Skip to content
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

[Bug]: shfmt doesn't respect editorconfig-defined ignored files #80

Closed
ciarand opened this issue Dec 13, 2023 · 2 comments · Fixed by #146
Closed

[Bug]: shfmt doesn't respect editorconfig-defined ignored files #80

ciarand opened this issue Dec 13, 2023 · 2 comments · Fixed by #146
Labels
bug Something isn't working

Comments

@ciarand
Copy link

ciarand commented Dec 13, 2023

What happened?

I have a file in my vendor'd third_party directory. There's a shell script in that directory that's not correctly formatted. Normally, I'd be able to instruct the shfmt tool to ignore that directory by setting up an .editorconfig file that looks like this:

# Ignore the entire "third_party" directory.
[third_party/**]
ignore = true

This is described in the shfmt documentation.

Unfortunately, the shfmt tool only applies this ignore setting when it's being passed a directory to walk. When passed a list of filenames directly, shfmt formats the files with no regard to the ignore setting. This is an open issue on the shfmt's bug tracker, but the author feels that the tool's behavior is correct.

Version

Development (host) and target OS/architectures:

Linux / amd64

Output of bazel --version:

6.2.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

v0.7.0

Language(s) and/or frameworks involved:

shfmt

How to reproduce

  1. Create a misformatted shell file in third_party/bad.sh:
#!/usr/bin/env bash

      function     badly_formatted()    {
  true
}
  1. Ask shfmt to ignore it by adding an .editorconfig file:
# .editorconfig
[third_party/**]
ignore = true
  1. Run the //:format target

Expected results: third_party/bad.sh isn't changed

Actual results: third_party/bad.sh is reformatted

Any other information?

No response

@ciarand ciarand added the bug Something isn't working label Dec 13, 2023
@ciarand
Copy link
Author

ciarand commented Dec 13, 2023

Ah, sorry, I forgot to finish my thought. This might just be a feature request for a rules_lint ignore list / function to prevent these files from being passed to (at least) the shfmt binary, but I marked it as a bug because the behavior looks akin to a bug even if both systems are sort-of doing some definition of the right thing

@alexeagle
Copy link
Member

Thanks for pointing to the black --force-exclude as a precedent on that issue. I agree that's the desirable fix here.

I think you could also make the case that pre-commit hooks will fall into the same trap - pre-commit.com is pretty popular FWICT, does it have this bug too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants