-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Ignored files not ignored when passed by name #1037
Comments
That is indeed expected. The "ignore" logic only applies when walking directories, like In a way, why else would you be running that command? Or, put another way, what could the tool reasonably do? Failing, or printing no stdout rather than the formatted source, both seem counter-intuitive. That said, this is not well documented - I will update the man page. |
In particular, that it only applies when formatting directories. When directly formatting files, we don't ignore anything. For #1037.
Hi @mvdan, thank you for getting back to me that quickly.
You do mean
I get the rational behind it. However, this places the burden to determine which file to call
I completely agree, printing no stdout and failing are both counter intuitive, and not very useful for that matter. I would like to propose to print the file without alternation, like
That would be very appreciated. However, the current behavior is rather counter-intuitive. |
shfmt recursively walks directories when given a directory. This happens with
Unless I'm missing something, you could and probably should be running shfmt on each repository's directory. That's how the majority of people use the tool. If what you're using is an editor or IDE which works on a file-by-file basis rather than the entire repository, and wants to integrate with shfmt, the easiest solution is likely for the integration to check for the
Sorry, but I disagree. If you're running a formatter on a filename explicitly, the behavior should not be to silently print it out as it already was. |
I get it, I updated my suggestion to the PR, accordingly.
That is kind of my point. I am not calling
How do you know?
Well, then the editors behavior would differ form your tool. Not exactly intuitive either.
When I look for other formatters on github (there are only few with more stars than If you think your tool should be used differently, I completely respect that. However, I will have to come up with another solution for my use cases. Thank you anyway for a great tool and being so open for discussion. |
Hello! We ran into this problem using the rules_lint package (a set of Bazel-related linters and formatters), which calls Would you be open to a |
In particular, that it only applies when formatting directories. When directly formatting files, we don't ignore anything. For #1037.
In particular, that it only applies when formatting directories. When directly formatting files, we don't ignore anything. For #1037.
I didn't verify this, but I imagine users of pre-commit will have the same problem, since it runs tools on the changed files by passing their paths to the tool. |
Thanks all for your input. Trying to recap what is my understanding of the situation below. I think there are two use cases for
This seems to be mainly about use case 2, and I agree it's awkward. My earlier suggestion was that the tool should check editorconfig to see if a file should be ignored, but that's effectively reimplementing our logic, which isn't a good solution. I definitely want to make some change here, I'm just not sure which. I would like to retain the property that, regardless of "ignore" settings, Thanks for bringing up psf/black#438. That seems to be an almost exact replica of our situation and my thinking as a maintainer :) I think adding a flag like Assuming such an
What does |
Thank you for getting back to us.
Simply running
|
I also lean towards "print absolutely nothing". I initially had a minor worry that this could lead to IDE/editor integrations suddenly emptying people's shell scripts, but the integration would have to explicitly opt into this behavior via |
The EditorConfig ignore=true property is currently only obeyed when walking directories, which is fine for command line users running shfmt like shfmt -l -w . However, many tools and editor integrations use shfmt via stdin or by passing a single file argument, and in those cases, the ignore=true logic does not kick in at all. There should be a way for a user to force running shfmt on a file, and that has always been passing a file as a direct argument, like: shfmt -w file.sh We can't break that, but tools do need a way to obey ignore rules. For that reason, add an --apply-ignore flag which does just that. Fixes #1037.
Please take a look at this PR implementing the above: #1051 |
@mvdan Thank you. I would like to share two observations:
|
Sorry, can you clarify? I don't follow. |
Perhaps you're right. We made up this property name because upstream doesn't have a standard way to ignore/skip files. For better or worse, |
Sorry, my test case must have been flawed. I am not able to reproduce a setup in which the statement 1. is valid. It works perfectly as far as I am concerned. |
Thanks for the input :) Merging and gearing up for a release. |
The EditorConfig ignore=true property is currently only obeyed when walking directories, which is fine for command line users running shfmt like shfmt -l -w . However, many tools and editor integrations use shfmt via stdin or by passing a single file argument, and in those cases, the ignore=true logic does not kick in at all. There should be a way for a user to force running shfmt on a file, and that has always been passing a file as a direct argument, like: shfmt -w file.sh We can't break that, but tools do need a way to obey ignore rules. For that reason, add an --apply-ignore flag which does just that. Fixes #1037.
Release done; tools and editors should hopefully be able to start relying on this as users upgrade. They could either check if |
Thanks @mvdan! |
Hi @mvdan,
thank you for
shfmt
. I have read that a directive in the.editorconfig
like this:... should ignore the directory. However, this seems only true for the usage of
--find
. If I callshfmt third_party/script.sh
,shfmt
formats the file. I expectshfmt
to output the file without any alternation, since the file is exempt from formatting.Is this a bug or intended? I am asking because I am building a setup for CI and multiple editors and I would like to exclude some files from formatting.
Have a nice weekend,
dcd-arnold
The text was updated successfully, but these errors were encountered: