-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config styling separates code from comments #187
Comments
alas, sorry this got you. i have some loose heuristics that try to do the least damage possible, but don't currently have a good solution here. likely sourceror's comment algorithm would do a better job, but last i checked it's not fast enough to be run as part of mix format 🤔 on the upside, once you fix the comments up once styler won't keep throwing things around. it's just that first sort where things can 💥 thanks for the issue ❤️ this is at least more data to try to tune things to behave better |
Thanks for the response! I've manually fixed the comments for this styler upgrade. Sadly it's something that can sneakily resurface when new config with comments is added in the future. Devs have to be attentive in PRs to make sure the comments go with the code. |
I'd be really interested in a repro for this, haven't experienced it myself. Likely because I'm only working in enormous config files... |
A fresh |
Right, i mean specifically for "can sneakily resurface when new config with comments is added". I'd love one where adding one or two new config messes up an already-sorted config |
came up with my own repro yesterday, sad bug indeed. no easy fix currently, so this may unfortunately sit a while longer |
Good I didn't have to submit this :) Happened to me, too: # Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime
config :pairs_one, :telegram_bot,
token: "9999999999:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ===> config :pairs_one, :telegram_bot,
# Initialize plugs at runtime for faster test compilation
token: "9999999999:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
config :phoenix, :plug_init_mode, :runtime FWIW: if I put this part onto a single line, it works correctly: config :pairs_one, :telegram_bot,
token: "9999999999:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
Actually this is possible without any changes to this library, it can be done with standard Update your root # .formatter.exs
[
subdirectories: ["config", ...],
# make sure to remove config from :inputs as well (it is added by default).
# See the docs for the :subdirectories option
inputs: [...]
...
] And add # config/.formatter.exs
[
inputs: ["*.exs"]
] https://hexdocs.pm/mix/Mix.Tasks.Format.html#module-formatting-options |
yeah that's definitely something i'd consider to work-around comments going willy-nilly |
before making configs enable/disable-able, i'm releasing 1.1.2 which removes a poor heuristic that was causing lots of comments moving. it still won't be perfect but i expect will be much better vis-a-vis small additions to config files. (this change fixed the issue for us where a single line being added to a large config caused all comments to be moved to the end of the file. instead, the new line was sorted and no other changes were made) |
oops, the above comment was a bit opaque. what i meant was |
Just for clarity, the config above still has the Elixir formatter running on Appreciate you looking into this and the heuristic update! |
Whoaaa totally was not aware you could set different configurations within a project like that, so it did indeed go over my head what you were saying. Very cool, thanks for the tip!
For sure. It was making us sad internally too, just had to have the time to get to it :) |
@jakeprem Any other guidance you can give to format the config directory separately? I think I followed your instructions and those in the docs, but now the formatter completely ignores my I followed your suggestions and:
[
inputs: ["*.exs"]
] |
Here are my # app/.formatter.exs
[
import_deps: [:ecto, :ecto_sql, :phoenix, :ecto_press],
subdirectories: ["priv/*/migrations", "config"],
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["*.{heex,ex,exs}", "{lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
] config: # app/config/.formatter.exs
[
inputs: ["*.exs"]
] Can't say for sure without seeing your actual configs, but hopefully this helps. I guess I should've included the full thing from the start 😁 |
Weird, mine's pretty close: # .formatter.exs
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations", "config"],
plugins: [TailwindFormatter, Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["*.{heex,ex,exs}", "{lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
] # config/.formatter.exs
[
inputs: ["*.exs"]
] |
Hi, first off thanks for this great lib! I've been using it for quite a while now and really love the improvements over the stock formatter.
Issue
Styler 1.0.0's extensive reformatting of config files separates many code comments from the lines they're annotating.
Versions
locked at 1.0.0 (styler) 4ba5bc40
Example Input
Stacktrace / Current Behaviour
Notice several blocks of code have been separated from their respective comments:
# Env variables
# We don't run a server during test. If one is required,
In my more complex config files (prod, runtime, dev), it's even messier.
Is there a different style of code commenting I should be using to prevent this? The majority of my config comments are scaffolded from the generators, so I won't be alone in hitting this.
The text was updated successfully, but these errors were encountered: