/
.eslintrc.js
145 lines (134 loc) · 4.81 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// @ts-check
/**
* - If a workspace emits declaration files, it should contain a `.eslintrc.js`
* which extends {@link file://./.config/eslintrc.typed-workspace.js}.
* - A workspace _only_ needs its own `.eslintrc.js` if it needs to override this
* configuration.
* - While you may be tempted, please do not use an `eslintConfig` prop in your
* `package.json`; use `.eslintrc.js` for consistency.
* - Note: glob patterns in this file should _not_ be relative.
*
* @summary The root ESLint configuration.
* @packageDocumentation
*/
/**
* The minimum EcmaScript runtime environment to support
*
* @see {@link https://eslint.org/docs/latest/use/configure/language-options#specifying-environments}
*/
const ECMASCRIPT_ENV = 'es2021'
/**
* The minimum EcmaScript language version to support
*
* @see {@link https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options}
*/
const ECMASCRIPT_VERSION = 2021
/**
* The minimum supported version of Node.js
*
* Instead of maintaining this value, we could use the `semver` package to read
* the root `engines` field and dynamically generate this value using
* `SemVer.minVersion()`.
*/
const MIN_NODE_VERSION = '16.20.0'
/**
* @type {import('eslint').Linter.Config}
*/
module.exports = {
root: true,
parserOptions: {
// this should be whatever the latest env version provides. some plugin is
// messing with this, so we need to set it manually.
// https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
ecmaVersion: ECMASCRIPT_VERSION,
},
// this should be synced with the version of V8 used by the min supported node version
env: { [ECMASCRIPT_ENV]: true, node: true },
// the prettier config disables all eslint rules known to conflict with prettier
extends: ['eslint:recommended', 'plugin:n/recommended', 'prettier'],
plugins: ['node-import'],
rules: {
// base rules; none of these are in eslint/recommended
'no-empty': ['error', { allowEmptyCatch: true }],
// additional errors not in n/recommended
'n/callback-return': 'error',
'n/handle-callback-err': 'error',
'n/no-callback-literal': 'error',
'n/no-mixed-requires': 'error',
'n/no-new-require': 'error',
'n/no-restricted-import': 'error',
'n/no-restricted-require': 'error',
'n/prefer-global/buffer': 'error',
'n/prefer-global/console': 'error',
'n/prefer-global/process': 'error',
'n/prefer-global/text-decoder': 'error',
'n/prefer-global/text-encoder': 'error',
'n/prefer-global/url-search-params': 'error',
'n/prefer-global/url': 'error',
'n/prefer-promises/dns': 'error',
'n/prefer-promises/fs': 'error',
// these rules seem broken in a monorepo
'n/no-unpublished-require': 'off',
// we should probably actually fix these three and turn these back on
'n/no-sync': 'off', // very few reasons to actually use this; "CLI tool" is not one of them
'n/no-process-exit': 'off', // should not be used with async code
// require node: prefix for builtin modules
'node-import/prefer-node-protocol': 'error',
},
settings: {
node: {
/**
* For `n/no-missing-import`
*
* @see {@link https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-missing-import.md}
*/
allowModules: ['deep-equal'], // something weird about this dependency
/**
* For `n/no-unsupported-features`.
*
* `eslint-plugin-n` looks in the `engines` field of the closest
* `package.json` to the file being linted to determine this value. For
* our workspaces, this field is present, but in some test fixtures it may
* not be. We _do_ try to ignore test fixtures, but that is easy to
* accidentally override via `eslint` on the command line. So, the safest
* thing is to just set it here.
*/
version: MIN_NODE_VERSION,
},
},
overrides: [
{
files: ['**/*/*/test/**/*.js'],
extends: ['plugin:ava/recommended'],
env: {
browser: true,
},
rules: {
// this should be removed and the issues fixed
'n/no-path-concat': 'warn',
// these two are broken in monorepos that resolve dev deps from the workspace root
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
},
},
{
files: ['**/*.ts'],
rules: {
// eslint-plugin-n does not understand typescript imports
'n/no-missing-import': 'off',
// eslint doesn't understand typescript
'no-unused-vars': 'off'
},
parser: '@typescript-eslint/parser',
},
{
files: ['**/tsconfig*.json', '**/*.json5', '**/*.jsonc'],
extends: ['plugin:jsonc/prettier'],
},
],
ignorePatterns: [
'**/types/**/*',
'**/test/**/fixtures/**/*',
'**/examples/**/*',
],
}