Refactor ESLint config (#13482)
We would like to insert TypeScript into the ESLint configuration, and because of the way that the current config is organized, that is not easy to do. Most files are assumed to be files that are suited for running in a browser context. This isn't correct, as we should expect most files to work in a Node context instead. This is because all browser-based files will be run through a transpiler that is able to make use of Node-specific variables anyway. There are a couple of important ways we can categories files which our ESLint config should be capable of handling well: * Is the file a script or a module? In other words, does the file run procedurally or is the file intended to be brought into an existing file? * If the file is a module, does it use the CommonJS syntax (`require()`) or does it use the ES syntax (`import`/`export`)? When we introduce TypeScript, this set of questions will become: * Is the file a script or a module? * If the file is a module, is it a JavaScript module or a TypeScript module? * If the file is a JavaScript module, does it use the CommonJS syntax (`require()`) or does it use the ES syntax (`import`/`export`)? To represent these divisions, this commit removes global rules — so now all of the rules are kept in `overrides` for explicitness — and sets up rules for CommonJS- and ES-module-compatible files that intentionally do not overlap with each other. This way TypeScript (which has its own set of rules independent from JavaScript and therefore shouldn't overlap with the other rules either) can be easily added later. Finally, this commit splits up the ESLint config into separate files and adds documentation to each section. This way sets of rules which are connected to a particular plugin (`jsdoc`, `@babel`, etc.) can be easily understood instead of being obscured.feature/default_network_editable
parent
96ab979e7c
commit
1e494f3004
@ -0,0 +1,9 @@ |
||||
module.exports = { |
||||
parser: '@babel/eslint-parser', |
||||
plugins: ['@babel'], |
||||
rules: { |
||||
'@babel/no-invalid-this': 'error', |
||||
// Prettier handles this
|
||||
'@babel/semi': 'off', |
||||
}, |
||||
}; |
@ -0,0 +1,67 @@ |
||||
const path = require('path'); |
||||
|
||||
module.exports = { |
||||
extends: [ |
||||
'@metamask/eslint-config', |
||||
path.resolve(__dirname, '.eslintrc.jsdoc.js'), |
||||
], |
||||
|
||||
globals: { |
||||
document: 'readonly', |
||||
window: 'readonly', |
||||
}, |
||||
|
||||
rules: { |
||||
'default-param-last': 'off', |
||||
'prefer-object-spread': 'error', |
||||
'require-atomic-updates': 'off', |
||||
|
||||
// This is the same as our default config, but for the noted exceptions
|
||||
'spaced-comment': [ |
||||
'error', |
||||
'always', |
||||
{ |
||||
markers: [ |
||||
'global', |
||||
'globals', |
||||
'eslint', |
||||
'eslint-disable', |
||||
'*package', |
||||
'!', |
||||
',', |
||||
// Local additions
|
||||
'/:', // This is for our code fences
|
||||
], |
||||
exceptions: ['=', '-'], |
||||
}, |
||||
], |
||||
|
||||
'no-invalid-this': 'off', |
||||
|
||||
// TODO: remove this override
|
||||
'padding-line-between-statements': [ |
||||
'error', |
||||
{ |
||||
blankLine: 'always', |
||||
prev: 'directive', |
||||
next: '*', |
||||
}, |
||||
{ |
||||
blankLine: 'any', |
||||
prev: 'directive', |
||||
next: 'directive', |
||||
}, |
||||
// Disabled temporarily to reduce conflicts while PR queue is large
|
||||
// {
|
||||
// blankLine: 'always',
|
||||
// prev: ['multiline-block-like', 'multiline-expression'],
|
||||
// next: ['multiline-block-like', 'multiline-expression'],
|
||||
// },
|
||||
], |
||||
|
||||
// It is common to import modules without assigning them to variables in
|
||||
// a browser context. For instance, we may import polyfills which change
|
||||
// global variables, or we may import stylesheets.
|
||||
'import/no-unassigned-import': 'off', |
||||
}, |
||||
}; |
@ -0,0 +1,23 @@ |
||||
module.exports = { |
||||
// Note that jsdoc is already in the `plugins` array thanks to
|
||||
// @metamask/eslint-config — this just extends the config there
|
||||
rules: { |
||||
// Allow tag `jest-environment` to work around Jest bug
|
||||
// See: https://github.com/facebook/jest/issues/7780
|
||||
'jsdoc/check-tag-names': ['error', { definedTags: ['jest-environment'] }], |
||||
'jsdoc/match-description': 'off', |
||||
'jsdoc/require-description': 'off', |
||||
'jsdoc/require-jsdoc': 'off', |
||||
'jsdoc/require-param-description': 'off', |
||||
'jsdoc/require-param-type': 'off', |
||||
'jsdoc/require-returns-description': 'off', |
||||
'jsdoc/require-returns-type': 'off', |
||||
'jsdoc/require-returns': 'off', |
||||
'jsdoc/valid-types': 'off', |
||||
}, |
||||
settings: { |
||||
jsdoc: { |
||||
mode: 'typescript', |
||||
}, |
||||
}, |
||||
}; |
@ -0,0 +1,10 @@ |
||||
module.exports = { |
||||
extends: ['@metamask/eslint-config-nodejs'], |
||||
rules: { |
||||
'node/no-process-env': 'off', |
||||
// TODO: re-enable these rules
|
||||
'node/no-sync': 'off', |
||||
'node/no-unpublished-import': 'off', |
||||
'node/no-unpublished-require': 'off', |
||||
}, |
||||
}; |
Loading…
Reference in new issue