Based on eslint-plugin-toplevel.
Lets you disallow top level side effects.
Examples of incorrect code for this rule:
console.log('hello world');
for (let i = 0; i < 10; i++) {
s += i;
}
console.log(s);
fetch('/api')
.then((res) => res.text())
.then(console.log);
Examples of correct code for this rule:
export default function () {
console.log('hello world');
for (let i = 0; i < 10; i++) {
s += i;
}
console.log(s);
fetch('/api')
.then((res) => res.text())
.then(console.log);
}
(function () {
console.log('hello world');
for (let i = 0; i < 10; i++) {
s += i;
}
console.log(s);
fetch('/api')
.then((res) => res.text())
.then(console.log);
})();
module.exports = () => {
console.log('hello world');
for (let i = 0; i < 10; i++) {
s += i;
}
console.log(s);
fetch('/api')
.then((res) => res.text())
.then(console.log);
};
(() => {
console.log('hello world');
for (let i = 0; i < 10; i++) {
s += i;
}
console.log(s);
fetch('/api')
.then((res) => res.text())
.then(console.log);
})();
If you want to allow top level side effects