eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Rule proposal: `no-exports-in-scripts`
Description
Currently, a js file starts with hashbang #! is script file. In script file, using exports is useless and confused.
Fail
#!/usr/bin/env node
export const foo = {};
Pass
export {}
#!/usr/bin/env node
console.log('foo');
Proposed rule name
no-exports-in-scripts
Additional Info
No response
Somewhat related:
- https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1661
This rule:
- report exports if it has side effects (detected via hashbang)
That rule:
- report side effects if it has exports
However this rule as defined is much easier to implement:
- find export statement
- report if line 1 is hashbang
Accepted
Changed my mind since Node supports import.meta.main. Allowing exports in scripts could be useful for testing.
#!/usr/bin/env node
export function main() {
// some codes need to be tested
}
if(import.meta.main) {
main()
}