-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy patheslint.config.js
More file actions
170 lines (159 loc) · 6.32 KB
/
eslint.config.js
File metadata and controls
170 lines (159 loc) · 6.32 KB
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
import { globalIgnores } from '@eslint/config-helpers'
import js from '@eslint/js'
import stylistic from '@stylistic/eslint-plugin'
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
// Using eslint-plugin-import-x rather than eslint-plugin-import
// to get rid of `Unable to resolve path to module '@typescript-eslint/parser' import/no-unresolved` errors
import importxPlugin from 'eslint-plugin-import-x'
import globals from 'globals'
import ts from 'typescript-eslint'
// Inspect the generated config:
// npx eslint --inspect-config
// Inspect the config applying to a specific file:
// eslint --print-config file_to_check.js
const tsParserOptions = {
tsconfigRootDir: import.meta.dirname,
// Would be required to enable ts.configs.recommendedTypeChecked and ts.configs.stylisticTypeChecked,
// but couldn't make it work
// See https://typescript-eslint.io/blog/project-service/
// projectService: true,
allowDefaultProject: [ '*.js' ],
}
export default ts.config([
js.configs.recommended,
...ts.configs.recommended,
...ts.configs.stylistic,
importxPlugin.flatConfigs.recommended,
importxPlugin.flatConfigs.typescript,
stylistic.configs.customize({
braceStyle: '1tbs',
jsx: false,
}),
{
files: [ 'src/**/*.ts', 'tests/**/*.ts', 'scripts/**/*.ts', '*.js', '*.cjs' ],
languageOptions: {
globals: globals.node,
parser: ts.parser,
parserOptions: tsParserOptions,
},
settings: {
'import-x/resolver-next': [
createTypeScriptImportResolver({
project: './tsconfig.json',
}),
],
},
rules: {
'array-callback-return': 'off',
eqeqeq: [ 'error', 'smart' ],
'implicit-arrow-linebreak': [ 'error', 'beside' ],
// See https://github.com/un-ts/eslint-plugin-import-x#rules
'import-x/newline-after-import': 'error',
'import-x/no-named-as-default': 'off',
'import-x/no-duplicates': 'error',
'import-x/no-named-as-default-member': 'off',
'import-x/order': [ 'error', {
pathGroups: [ {
pattern: '#*/**',
group: 'internal',
position: 'before',
} ],
groups: [ 'builtin', 'external', 'internal', 'parent', 'sibling', 'object', 'type' ],
'newlines-between': 'never',
alphabetize: {
order: 'asc',
},
} ],
indent: [ 'error', 2, {
MemberExpression: 'off',
} ],
'no-ex-assign': [ 'off' ],
'no-var': [ 'error' ],
// Disable until eslint-plugin-node-import adds support for ESLint 9
// or `eslint-plugin-import-x` implements `import/enforce-node-protocol-usage`
// 'node-import/prefer-node-protocol': 2,
'nonblock-statement-body-position': [ 'error', 'beside' ],
'object-shorthand': [ 'error', 'properties' ],
'one-var': [ 'off' ],
'prefer-arrow-callback': [ 'error' ],
'prefer-const': [ 'off' ],
// See https://eslint.style/rules
'@stylistic/array-bracket-spacing': [ 'error', 'always' ],
'@stylistic/arrow-parens': [ 'error', 'as-needed' ],
'@stylistic/brace-style': 'error',
'@stylistic/comma-dangle': [ 'error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
} ],
'@stylistic/indent': [ 'error', 2, { MemberExpression: 'off' } ],
'@stylistic/keyword-spacing': 'error',
'@stylistic/operator-linebreak': [ 'error', 'after', { overrides: { '?': 'before', ':': 'before' } } ],
'@stylistic/max-statements-per-line': 'off',
'@stylistic/member-delimiter-style': [ 'error', {
multiline: {
delimiter: 'none',
},
singleline: {
delimiter: 'comma',
requireLast: false,
},
} ],
'@stylistic/object-curly-spacing': [ 'error', 'always' ],
'@stylistic/quote-props': [ 'error', 'as-needed' ],
'@stylistic/quotes': [ 'error', 'single', { avoidEscape: true } ],
'@stylistic/space-before-function-paren': [ 'error', { anonymous: 'always', asyncArrow: 'always', named: 'always' } ],
'@stylistic/space-infix-ops': 'error',
'@stylistic/type-annotation-spacing': 'error',
// Doesn't allow have a space between the function name and the generic type parameters
'@stylistic/type-generic-spacing': 'off',
// See https://typescript-eslint.io/rules/
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' } ],
'@typescript-eslint/no-explicit-any': 'off',
// -- Type check rules overrides
// This rules require strict types
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
// Some equivalent types, in particular string types, are worth keeping for the sake of readability
// until we can introduce tagged types (1)
'@typescript-eslint/no-duplicate-type-constituents': 'off',
// Idem
'@typescript-eslint/no-redundant-type-constituents': 'off',
// Noisy when doing things such as passing an async function a `setTimeout`
'@typescript-eslint/no-misused-promises': 'off',
// We have rather been using String#match until now, which might be more readable
'@typescript-eslint/prefer-regexp-exec': 'off',
// Some functions might not call await but conditionally return a promise;
// making it async allows to normalize the response type to always be a promise
'@typescript-eslint/require-await': 'off',
// --
},
},
{
files: [ './tests/**/*.ts' ],
languageOptions: {
globals: {
it: 'readonly',
xit: 'readonly',
describe: 'readonly',
xdescribe: 'readonly',
beforeEach: 'readonly',
before: 'readonly',
},
parser: ts.parser,
parserOptions: tsParserOptions,
},
},
globalIgnores([
'**/node_modules',
'**/dist',
]),
])
// (1): on tagged types, see https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721)