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

Allow shebang in any file #336

Open
1 task
mk-pmb opened this issue Sep 10, 2024 · 4 comments
Open
1 task

Allow shebang in any file #336

mk-pmb opened this issue Sep 10, 2024 · 4 comments

Comments

@mk-pmb
Copy link

mk-pmb commented Sep 10, 2024

Rule details

I'd like to configure the shebang rule to do all of its regular checks, but not complain "This file needs no hashbang."

What type of rule is this?

Suggests an alternate way of doing something

Example code

#!/usr/bin/env -S nodemjs
import main from 'main.mjs';

main(process.argv.slice(2));

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

Also the message "This file needs no hashbang." should be a bit more helpful, rather than just patronizing. When I first got the error, my first thought was, "Of course it needs one, how else would my shell know how to run it?" So maybe let's change it to something like "This file contains a hashbang but is not listed as a bin entry in package.json."

@scagood
Copy link

scagood commented Sep 10, 2024

There is an option in the rule for exactly this, it's called additionalExecutables

@mk-pmb
Copy link
Author

mk-pmb commented Sep 10, 2024

Thanks! I assumed that empty array in the example is an array of glob patterns, so I expressed my intention "any" as '**' and that worked. Now instead I need a way to restrict the enforcement of executableMap to the files mentioned in the "bin" entry.
Edit: Or, even better, can I give a regexp of acceptable hashbang lines? (Edit 2: Nope. "Value {} should be string.")
Edit 3: Also This file needs shebang "#!/usr/bin/env node". should probably say "hashbang" instead of "shebang".
Edit 4: Turns out this is not a solution either. With '**', now all files are expected to have a shebang. I want to just allow it, not enforce needless shebangs.

@aladdin-add
Copy link

there are 2 options:

  1. additionalExecutables: Mark files as executable that are not referenced by the package.json#bin property, default is [].
  2. ignoreUnpublished : Allow for files that are not published to npm to be ignored by this rule, default is false.

@mk-pmb
Copy link
Author

mk-pmb commented Sep 18, 2024

Neither of those work for me. I have scripts that are meant to be invoked by my node scripts, but would not usually be desirable to invoke from an interactive shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants