Disallow side effects at the top level of files.
First, If you haven't already, install ESLint:
npm install eslint --save-dev
Then, install eslint-plugin-top
:
npm install @ericcornelissen/eslint-plugin-top --save-dev
Import from @ericcornelissen/eslint-plugin-top
and use one of the preset
configurations, e.g.:
import top from '@ericcornelissen/eslint-plugin-top';
export default [
top.configs.recommended,
// or
top.configs.strict
// ...
];
Or configure the rules you want to use in the rules section, e.g.:
import top from '@ericcornelissen/eslint-plugin-top';
export default [
{
plugins: {top},
rules: {
'top/no-top-level-side-effects': 'error',
'top/no-top-level-variables': 'error'
}
}
];
Note that the rule prefix (top
in the example) must match the name of the key
used in the plugins object.
First, add @ericcornelissen/top
to the plugins section of your .eslintrc
configuration file. You must omit the eslint-plugin-
infix:
plugins:
- '@ericcornelissen/top'
Then, configure the rules you want to use in the rules section:
rules:
'@ericcornelissen/top/no-top-level-side-effects': error
'@ericcornelissen/top/no-top-level-variables': error
recommended
: disallow top level variables while allowing mutable values and disallows top level side effects except for creating things likeSymbol
s.strict
: disallow all top level variables and side effects except for importing other files.
Please open an issue if you found a mistake or if you have a suggestion for how to improve the documentation.