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

Handle scripts with no file extension #33

Open
zimbatm opened this issue Feb 2, 2021 · 1 comment
Open

Handle scripts with no file extension #33

zimbatm opened this issue Feb 2, 2021 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@zimbatm
Copy link
Member

zimbatm commented Feb 2, 2021

Problem statement

Scripts often don't have a file extension. This means that the files = [] attribute won't be able to target them efficiently. The user would have to manually pass all of the filenames in there.

Proposed solution

If a file has the executable bit set, open the file and look at the shebang. This will make the detection more expensive but I don't really see a way around it.

In the formatter config, add a files_executable = [] section that lists all of the shebang executables the formatter should match on.

In cases where #!/usr/bin/env is being used, it should strip that and look at the next argument to find the executable name. Otherwise, it looks at the basename of the first argument.

@zimbatm zimbatm added the enhancement New feature or request label Feb 2, 2021
@zimbatm zimbatm added this to the Release 0.2 milestone Feb 27, 2021
@zimbatm zimbatm modified the milestones: Release 0.2, Release 0.3 Apr 10, 2021
@sellout
Copy link

sellout commented Aug 7, 2023

shfmt does this internally (I don’t know if that is visible via treefmt or if the interface always passes specific files or what).

An shfmt --find or something will return a list of the files it would have formatted, so it exposes the ability to find shebangs … but it doesn’t let you specify what you might want to find on the shebang, so you’re restricted to shell scripts.

brianmcgee pushed a commit that referenced this issue May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants