-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
cmd/shfmt: add a way to skip custom directories when walking directories #288
Comments
I'd imagine that Otherwise, adding a |
Here's another question, Paul - is this about performance, or about not formatting files that shouldn't be formatted? If it's the former, then we really do need a way to skip the massive directories. If it's the latter, perhaps there's other workarounds. For example:
|
It's about being able to use shfmt as a linting tool, while not having the CI build fail if there are node_modules (containing shell scripts) present. fwiw, I definitely agree about the For now I'm using:
But I didn't see the |
I added Right now this is what we skip:
So this would likely translate to a default of The other option is to not add the flag and instead tell people to use a combination of |
For now, I think users should stick to:
This can be extended however one likes, and should be fast enough. If a directory like
So I'm going to close this for now, as I don't see a big need to add another flag. If anyone thinks otherwise, please speak up or open another issue. |
Please reopen this issue as this solution doesn't work with pre-commit formatters like lintstaged. Also, |
That seems like a limitation of that piece of software. If a formatter tool is given a list of files, it should format those files. In other words, if what you're saying was true, lots of other formatters like Also, this issue is about walking directories (like
If every tool had config and ignore files on each repo using said tool, we'd end up with dozens of dot-files bothering developers. I'll only consider adding either if there really is a big need for it. Otherwise, just following what's standard for the sake of it is not a good idea. |
First thanks for this great software. This comment is not for requesting anything just for adding another point of view. I'm using the patterns that @paulbellamy and @mvdan showed in this issue to exclude or even something like Some tools like stylelint allow a In my case i like that this ignore file takes precedence even over files passed from command line (in git hooks) because sometimes is useful to copy&paste an external file or set of files from third party that i prefer to keep as is. |
We're going to do #393, so shfmt will now have a (shared) per-project config file. I think that's a fine place to be able to configure something like this. For example, there's editorconfig/editorconfig#228. It hasn't progressed as a new EditorConfig feature, but we can still grab ideas from there. |
The Managing a shfmt --ignore-path .gitignore By the way, providing a A lot of lint tools already provide this option like I already implemented it on a project thanks to this library: github.com/sabhiram/go-git-ignore You can see the implementation here: https://gitlab.com/nexylan/pretty/blob/acaa4fa25f5bddabb1b289c86dcad9f324c6193f/main.go#L114-133 As you can see, it is quite simple to implement ignore file and it will simplify a lot the usage of this tool. 👍 |
Please see my proposal: #422 |
I left a short review on the PR. I generally disagree with the design; it adds a custom I realise that editorconfigs don't directly support ignoring files, but that's worth a try over adding yet another config file and flag. |
I really don't see the issue to add a flag or a new config file (if you specify The added logic is not complex and fix this issue with ease and feels everyone needs. We are not discussing about adding or changing a rule nor adding an option about that, but adding a needed feature to globally improve the tool usage. Plus, the fact many lint tools already implement the option should encourage us to follow the way IMHO. 👍 Maybe I'm missing something about your concern, and I would be glad to better understand. |
For anybody, here is my workaround for FILES=$(comm -12 <(shfmt -f . | sort) <(git ls-files | sort))
if [ -z "${FILES}" ]; then
exit 0
fi
echo "${FILES}" | xargs shfmt ${OPTIONS} But it it not ideal as we have a strict dependency to |
Please just let me add editorconfig support first. One major new feature at a time :) The time I have to work on this project is limited, and new flags and features need to be carefully considered. |
Amount of dot-files in big projects is already alarming, we should try hard not to add another one. I do not have any opinion on editorconfig. |
This is not the same thing and, honestly, my MR is not so big. And it's ready to use! :-)
This is why I let the option to use
You meant, add a pre-commit? No, because it's for a CI tool. Here is my implement (with git workaround): https://gitlab.com/nexylan/pretty/blob/master/tools/shfmt/run But this is quite buggy: https://gitlab.com/nexylan/pretty/issues/44 BTW, if I do not find a more reliable workaround, I may have to remove shfmt support from the project. @mvdan Having this tiny option I proposed in #422 would make thing a lot easier and this approach is already adopted by many popular let tools. Could you please tell me why you are still uncomfortable to it? Regards |
Adding more flags is just as bad as adding more dotfiles.
It's not, when tool doesn't work well without that dotfile.
No. I meant make a tool which builds list of files and feeds it to shfmt (this is what referenced pre-commit hook does). |
@soullivaneuh other tools doing something, or a patch being ready for a feature, doesn't mean that we must add that feature. As I said above, I carefully consider new features, particularly those that add new flags or encourage the use of yet more dotfiles. I'm pretty happy with the EditorConfig support. I'd very much prefer to build on top of that instead of adding more config files. For example, to ignore all
The The only downside that I see is that, in practice, this could mean duplicating some lines between
It's unfortunate that this I'll ship v3 without this feature, but we can add it soon after in master for v3.1 if it sounds like a good plan to others. Particularly interested in @paulbellamy's input, though it's been over a year since he filed the issue :) |
I laid out my plan above two months ago, and I still think it's a good idea for the reasons stated in that last comment. The implementation is done; I'll push it to close this issue. 3.1.0 will come sometime in March, so there are a few weeks of time if anyone has feedback on the feature. I'm going to close #422 for now, because it accomplishes something pretty similar but at the cost of adding one more flag and tool-specific config file. |
It maybe be fill @paulbellamy issue, but not the Our tool pretty manage lint tool execution regardless of the submitted project to allow us configuration tool reducing. The So no, your changes does not bring anything on this side. Could you please reopen #422 for discussion? The option implement is very tiny and this is the may most of the lint tools manage the ignore files. It's really hard to me to understand your concerns. :-/ |
BTW, you also refused the With a ignore file option, we may not manage Even if I personally use it, I don't see so many project using the If your only concern is the option addition, could we at least detect and manage populare ignore files like you did for the Regards. |
It's not just for editors. Build systems like Gradle and Maven also support it, for example, and I think it fits
Sorry, but I disagree - if anyone badly needs to make
The code being tiny isn't really a factor, though. The fact that other tools do something can count, but it doesn't mean that it's automatically a good idea for us.
The flag was one concern, yes, but the other concern is config files. Most users needed a way to set flags via a file, and some needed to ignore directories via a file. A gitignore only fixes the second, smaller problem. An editorconfig fixes the bigger first problem, and with a bit of a stretch, it fixes the second too. It's of course not a perfect solution, but it seems to me like a far better solution than supporting two sets of config files, when in fact we don't really need two config files.
That's fine :) The joy of open source is that everyone gets to voice their opinion. But, as a maintainer, that also makes some decisions terribly difficult. How does one make a decision when it's impossible to make everyone in a thread happy? How does one reject a patch without discouraging the author from contributing again in the future? Honestly, maybe I'll make mistakes, but I'm only doing what I think is best for the project in the long run. I hope you can understand that. |
I also forgot to mention - thanks to @tbcs and issue #477, it should now be far easier to use It also allows simplifying examples earlier in this thread; for example:
can probably be just the line below, assuming that
|
For what it's worth, the examples in this thread are unsafe for filenames containing spaces (see here for more info). Technically they should be looped via something like: shfmt -f . | grep -v node_modules/ | while read -r fname; do
shfmt -d "$fname"
done Although this still doesn't handle other special characters like newlines correctly. Probably unlikely to come up with scripts in source repos but thought it was worth noting. It might make sense to add a |
shfmt -f output for filenames with newlines is completely broken, I suggest to file a new issue for that. As for the fix - \0 separator can only work with xargs and xargs is bizzare. Working with filenames in shell is annoying, but I found that using proper shell escaping works okayish:
Final
None of that will work on windows of course and I don't know what to do with it. |
Thanks @mvdan for the great work in this library. Just wanted to share how I configured My problem: My fix (as recommended in
|
I created #1095 because this issue has been addressed via the I do think that having |
When recursing it would be nice to be able to ignore certain directories or files (for example,
node_modules
).Either a
--exclude=node_modules
, or--ignore=node_modules
, or a.shfmtignore
-type functionality would be nice.The text was updated successfully, but these errors were encountered: