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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect .styluaignore
when explicitly passing in file names
#751
Comments
Hey, |
Thanks for the info. Sounds reasonable. I'll see if I can fix this in the pre-commit hook. |
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
@JohnnyMorganz is this the intended behavior? If so, could I try to persuade you to to rethink this behavior? I'll spare you the boring details but long story short: our build system caches required work at a file level, meaning that we have to run stylua on each file individually if we want to avoid linting and formatting unmodified files. This procedure helps us save immense amounts of time by only doing work that is necessary. I suspect our build system isn't the only one with this behavior and that our situation isn't unique. My proposal is instead that If you'd still like a way for stylua to be able to bypass Thank you for hearing me out and thank you for stylua :) |
I think it is reasonable to provide some way to continue respecting ignores when explicitly passing file names. For backwards compatibility reasons, it would probably have to be the inverse of your suggestion, instead providing a I was curious what the default behaviour of other tools are for this:
Each tool varies in its support |
.styluaignore
when explicitly passing in file names
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
I think As a user, if I'm running stylua on a file from the command line, I probably want to format that file, so On the other hand, |
Turns out a while ago this was actually partially implemented by a user specifically for Ideally this should also be behind the |
add_glob_target is our custom method to figure out whether a work needs to be done or not. This works as expected most of the time, but causes a problem with stylua. Stylua makes the decision that if a file is explicitly passed to be formatted, then it will format the file even if the file is set to be ignored in .styluaignore. This behavior breaks add_glob_target with seemingly no easy workaround. More information: JohnnyMorganz/StyLua#751 Instead, what we can do is call stylua as you would in the command line. This will make stylua work as expected. The downside is that we no longer get a free "is this work necessary" detection, meaning that stylua will be run each time `make lint` is called, regardless if it's necessary or not. For longer lint tasks such as uncrustify and clang-tidy this would be disastrous, but this is an acceptable tradeoff since stylua is very quick.
Hi 馃槃
I have a git pre-commit hook that calls
stylua
with file names (the staged files),and I noticed that when passing in a file (rather than a directory), it is formatted, even if the file matches
.styluaignore
.Is this intended behaviour? If so, I'm wondering if there's a way to modify this behaviour so that it works with pre-commit hooks, or if it would make sense to add a CLI flag?
(asking before I go ahead and open a PR)
The text was updated successfully, but these errors were encountered: