An eslint plugin for disallow side effect at module toplevel
npm install eslint-plugin-toplevelJS
console.log('hello world');
let s=0;
for (let i=0;i<10;i++) {
s += i;
}
console.log(s);
fetch('/api').then(res=>res.text()).then(console.log);
`$3
`JS
export async function main() {
console.log('hello world');
let s=0;
for (let i=0;i<10;i++) {
s += i;
}
console.log(s);
const res = await fetch('/api');
console.log(await res.text());
}
`And then in html:
`HTML
`Or in nodejs make a runner.mjs file:
`JS
import { main } from "./main.mjs";
main();
`Rules
There are three rules in this plugin:
$3
Disallow var usage at toplevel module.
Goal of this rule is to prevent modules to have internal state.
$3
similiar to no-toplevel-var
$3
Disallow any side effect at top levelContributing
I'd love to accept your patches and contributions to this project.
There are many ways you can contribute. For example:
* Add tests
* Fix bugs
* Add option to ignore module.exports assigns in no-toplevel-side-effect` rule