import-js / import-js/eslint-plugin-import
Help/Suggestion: No Export in a Shebang file
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
I feel like this rule would help a lot of new node users that love making CLI & bin application with it (like me😊).
I found out that exporting a function from a file that has a shebang declaration the top of it (like #! /usr/bin/env node) gives a lot of trouble in execution.
The rule to catch export statement would probably look like that:
create(context) {
if (context.parserOptions.sourceType !== 'module') { // ignore non-modules
return {};
}
return {
ExportDefaultDeclaration(node) {
context.report({
node,
message:
'Export declaration is not allowed in a shebang file. Try exporting from another file and then import it here.'
})
},
}
}
But how can I add a condition to test if a shebang line is present in the file?
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed create(context) entry point and ExportDefaultDeclaration visitor, then inspect existing rule and test conventions in the repository. Verify how a shebang is represented and how the visitor can distinguish module files; done means the rule reports the proposed export case only for shebang files and has coverage for it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100