-
Notifications
You must be signed in to change notification settings - Fork 4
/
.eslintrc.js
190 lines (183 loc) · 5.79 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
'use strict';
const debug = require('debug')(`${require('./package.json').name}:eslint-config`);
const restrictedGlobals = require('confusing-browser-globals');
const plugins = ['unicorn', '@typescript-eslint', 'import'];
const xtends = [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:unicorn/recommended'
];
const environment = {
es2022: true,
node: true
// * Instead of including more options here, enable them on a per-file basis
};
const rules = {
'no-console': 'warn',
'no-return-await': 'warn',
'no-await-in-loop': 'warn',
'import/no-unresolved': ['error', { commonjs: true }],
'no-restricted-globals': ['warn', ...restrictedGlobals],
'no-extra-boolean-cast': 'off',
'no-empty': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'@typescript-eslint/ban-ts-comment': [
'warn',
{
'ts-expect-error': 'allow-with-description',
minimumDescriptionLength: 6
}
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_+',
varsIgnorePattern: '^_+',
caughtErrorsIgnorePattern: '^ignored?\\d*$',
caughtErrors: 'all'
}
],
// ? Ever since v4, we will rely on TypeScript to catch these
'no-undef': 'off',
'@typescript-eslint/no-var-requires': 'off',
// ? I'll be good, I promise
'@typescript-eslint/no-non-null-assertion': 'off',
'no-unused-vars': 'off',
'unicorn/no-keyword-prefix': 'warn',
'unicorn/prefer-string-replace-all': 'warn',
// ? Handled by integration tests
'unicorn/prefer-module': 'off',
// ? I am of the opinion that there is a difference between something being
// ? defined as nothing and something being undefined
'unicorn/no-null': 'off',
// ? If MongoDB can get away with "DB" in its name, so can we. Also,
// ? unnecessary underscores are a big no-no.
'unicorn/prevent-abbreviations': [
'warn',
{
checkFilenames: false,
replacements: {
args: false,
str: false,
fn: false,
db: false,
dir: false,
dist: false,
tmp: false,
pkg: false,
src: false,
dest: false,
obj: false,
val: false
},
ignore: [/stderr/i]
}
],
// ? Actually, I rather like this curt syntax
'unicorn/no-await-expression-member': 'off',
// ? Between disabling this and disabling no-empty-function, I choose this
'unicorn/no-useless-undefined': 'off',
// ? Not sure why this isn't the default
'unicorn/prefer-export-from': ['warn', { ignoreUsedVariables: true }],
// ? Yeah, I read The Good Parts too, I know what I'm doing
'unicorn/consistent-function-scoping': 'off',
// ? It's 2022. Use Prettier
'unicorn/no-nested-ternary': 'off',
// ? `Array.from` communicates intent much better than `[...]`
'unicorn/prefer-spread': 'off',
// ? Not realistic when using TypeScript
'unicorn/prefer-native-coercion-functions': 'off',
// ? Premature optimization is evil
'unicorn/no-array-for-each': 'off',
// ? Lol, no
'unicorn/explicit-length-check': 'off',
// ? I don't think so
'unicorn/no-negated-condition': 'off'
};
module.exports = {
parser: '@typescript-eslint/parser',
plugins,
extends: xtends,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true,
jsx: true
},
project: 'tsconfig.eslint.json'
},
env: environment,
rules,
overrides: [
{
files: ['*.test.*'],
plugins: [...plugins, 'jest'],
env: { ...environment, jest: true },
extends: [...xtends, 'plugin:jest/all', 'plugin:jest/style'],
rules: {
...rules,
'jest/lowercase': 'off',
'jest/consistent-test-it': 'off',
'jest/require-top-level-describe': 'off',
'jest/valid-describe': 'off',
'jest/no-hooks': 'off',
'jest/require-to-throw-message': 'off',
'jest/prefer-called-with': 'off',
'jest/prefer-spy-on': 'off',
'jest/no-if': 'off',
'jest/no-disabled-tests': 'warn',
'jest/no-commented-out-tests': 'warn',
'jest/no-alias-methods': 'off',
'jest/max-expects': 'off',
'jest/prefer-mock-promise-shorthand': 'off',
'jest/no-conditional-in-test': 'off',
'jest/no-conditional-expect': 'off',
'jest/prefer-each': 'off'
}
}
],
settings: {
react: {
version: 'detect'
},
'import/extensions': ['.ts', '.tsx', '.js', '.jsx'],
// ? Switch parsers depending on which type of file we're looking at
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.cts', '.mts'],
'@babel/eslint-parser': ['.js', '.jsx', '.cjs', '.mjs']
},
'import/resolver': {
alias: {
map: [
// ! If changed, also update these aliases in tsconfig.json,
// ! webpack.config.js, next.config.ts, babel.config.js, and
// ! jest.config.js
['universe', './src'],
['multiverse', './lib'],
['testverse', './test'],
['externals', './external-scripts'],
['types', './types'],
['package', './package.json']
],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
},
typescript: {}
},
'import/ignore': [
// ? Don't go complaining about anything that we don't own
'.*/node_modules/.*',
'.*/bin/.*'
]
},
ignorePatterns: ['coverage', 'dist', 'bin', 'build', '/next.config.js']
};
debug('exports: %O', module.exports);