-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
[FR]: Allow passing arguments to formatters in format_multirun #377
Comments
@momilo could you point to some specific motivating examples of cases where a linter takes a CLI flag that you can't put in a config file?
rules_lint doesn't require this. We only recommend this layout in the example because some tools expect that configurations are in a parent folder of the files being formatted. You're free to put the file wherever you like if the formatter permits.
Again, I'd like to see a motivating example of a case where a file should be excluded for one formatter but not another. Wouldn't it be a bad experience if two different formatters are trying to operate on the same file? Thanks @ewhauser for pointing out an existing workaround: put these in your own wrapper around the binary, then register that one:
|
Hey Alex, I think my argument is more focused around "if I don't absolutely need to use many additional files for trivial things, I would rather not". This wouldn't be an issue in a small repo. But running a monorepo with many "languages", creating a number of files e.g. just to specify the number of space indentations ( But, to be more specific, answers below.
That is not what I meant. I think it might be an incorrect assumption that each and every formatter necessarily must support a config file. From the top of my head, for instance, formatters which don't support config files:
I wouldn't be surprised if many other formatters (perhaps contrary to linters, which usually are usually much more complex) do not support config files.
Ish. Usually the formatters, if they accept a config file, take the approach of "the config file auto-discovered will be used for directories underneath". In monorepos this forces you to put them in the root (or copy-paste/symlink across a number or dirs). If you have access to CLI... you can often just hide the mess, like many usually do e.g. with golangci-lint or yamlfmt (chuck the configs into
That's a fair point. I was probably thinking more about including only a language-specific codepath (e.g. Overall - it's not a big thing (I would rather cheer for superfast golangci-lint support :-D), especially since now I have learnt of the helpful workaround. Just something to potentially consider. |
Not completely sure if my question is related (but it feels like): |
@TimotheusBachinger I think that's a different issue. If you run in check mode I expect ruff and terraform-fmt to behave similarly: print the difference of what should be changed. No need for the user to pass arguments to the formatters. If that's not the case, could you file a separate issue please? |
@momilo would this be sufficient?
That's semantically equivalent to the workaround above, but nicer syntax sugar and doesn't need a bash wrapper. It still defines a formatter that uses fixed arguments regardless of what directories contain the files it formats. |
@alexeagle I have simply created a PR to achieve what I want: |
Totally. I ended up doing |
+1, we currently patch - "yamlfmt": "-lint",
+ "yamlfmt": "-conf tools/yamlfmt.yaml -lint", just to set where the config file is stored. Creating a wrapper for this is feasible enough but it adds a few dozen lines of code (which feels more cumbersome than a one line .patch file, to be honest). |
@mattnworb why do you need to do that though? According to https://github.com/google/yamlfmt/blob/main/docs/config-file.md#config-file-discovery it should locate the config file automatically. Is it finding the wrong file? |
sorry for not being clear - we had a (very subjective) desire to put the config file in some place other than the root of the repo / Bazel workspace, in which case |
Okay, I think "we want to do something the tool doesn't support" is fine but means the complexity of supporting that should fall on you. I'm trying to be very parsimonious in what we add to rules_lint so that the required maintenance budget stays feasible. So my assessment is that yamlfmt example isn't enough motivation to add this feature. Maybe there are still other good ones. |
Just throwing into the mix: I believe |
I'm very new to Bazel, but trying to use this to run Am I right to think that this is required for that use case, or (more likely) am I missing something simple? |
@Undo1 no that ought to just work. You should not need to pass any flags to it. |
What is the current behavior?
At the moment it is not possible to provide arguments into the formatters specified in
format_multirun
. Instead, in order to configure their behaviour, one needs to rely on each formatter's internal (default) auto-discovery of configuration files (e.g. .editorconfig for shfmt, .yamlfmt for yamlfmt etc.) or rules_lint's supported.gitattributes
annotations (to exclude certain paths - although, in this case, this applies to all formatters, not a specific one).Describe the feature
It would be great to able to pass arguments to each individual formatter, to make full use of its features.
This would have a number of benefits:
.gitattributes
(applied indiscriminately to all formatters)The text was updated successfully, but these errors were encountered: