-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy path.eslintrc.js
More file actions
151 lines (148 loc) · 5.38 KB
/
.eslintrc.js
File metadata and controls
151 lines (148 loc) · 5.38 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
// @ts-check
/** @type {import('@typescript-eslint/utils').TSESLint.Linter.Config} */
const config = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
project: ['tsconfig.json'],
},
plugins: ['@typescript-eslint', 'etc'],
reportUnusedDisableDirectives: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
rules: {
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variableLike',
format: ['PascalCase', 'camelCase'],
leadingUnderscore: 'allow',
},
],
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-shadow': ['error', { ignoreTypeValueShadow: true }],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
// Follow the typescript pattern of ignoring things starting with _
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/prefer-for-of': 'error',
'etc/no-deprecated': 'error',
// ESLint has a built-in version of this rule without the allowTypeImports functionality.
// Some overrides use the built-in ESLint rule to set additional restricted imports without
// overriding these defaults.
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
{
name: 'node:test',
message: 'You probably meant to import from "@jest/globals"',
},
],
},
],
'no-restricted-properties': [
'error',
{
object: 'fs',
property: 'promises',
message: 'Import "fs/promises" directly instead. This allows methods to be mocked with Jest.',
},
{
object: 'process',
property: 'cwd',
message: 'Pass the proper cwd through to avoid accidentally running operations in the wrong context.',
},
{
object: 'process',
property: 'chdir',
message:
'beachball should not be dependent on the actual process.cwd(). Ensure the proper cwd is passed through instead.',
},
{
object: 'process',
property: 'exit',
message: 'Errors should be propagated to the top level and handled there.',
},
],
// Downgrade these rules to warnings because they cause excessive/unhelpful noise when
// the actual problem is type errors due to a missing import...
// With the rules as warnings, there will only be "red squiggles" at the spot of the type error
// rather than sometimes covering the whole statement.
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
// Disabled rules from extended configs:
'no-undef': 'off',
'no-regex-spaces': 'off',
// This rule requires using Record instead of index signatures, and it's disabled because
// sometimes the key name can be useful for documentation.
'@typescript-eslint/consistent-indexed-object-style': 'off',
// Don't restrict types of `template expression ${operands}`.
'@typescript-eslint/restrict-template-expressions': 'off',
// Right now this rule gives unnecessary warnings about comparisons with string literals,
// which the compiler would flag anyway. It could be helpful if there was a future fix or
// option to ignore those types of safe comparisons.
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
},
overrides: [
{
files: ['*.js', '*.mjs'],
parserOptions: {
sourceType: 'module',
},
rules: {
// Rule doesn't handle JS files
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['**/__e2e__/**', '**/__fixtures__/**', '**/__functional__/**', '**/__tests__/**'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-restricted-properties': [
'error',
...['describe', 'it', 'test']
.map(func => [
{ object: func, property: 'only', message: 'Do not commit .only() tests' },
{ object: func, property: 'skip', message: 'Do not commit .skip() tests (disable this rule if needed)' },
])
.flat(),
],
// Use the ESLint version of the rule to avoid overriding the restricted imports from the base config
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@jest/globals',
importNames: ['xdescribe', 'xit', 'xtest'],
message: 'Do not commit disabled tests (disable this rule if needed)',
},
],
},
],
},
},
],
};
module.exports = config;