@petbee/eslint-config 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/rules/nextjs.js +11 -0
- package/rules/react.js +21 -0
- package/rules/typescript.js +20 -244
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petbee/eslint-config",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Petbee's eslint config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "691cd678231d15a665a7bb1751cac4c2fa3789b1"
|
|
85
85
|
}
|
package/rules/nextjs.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: ['@next/eslint-plugin-next'],
|
|
3
|
+
extends: ['plugin:@next/next/recommended'],
|
|
4
|
+
rules: {
|
|
5
|
+
// Next.js specific rules can be added here
|
|
6
|
+
// For example, enforce no HTML <img> element usage
|
|
7
|
+
'@next/next/no-img-element': 'error',
|
|
8
|
+
// Enforce usage of next/link for navigation
|
|
9
|
+
'@next/next/no-html-link-for-pages': 'warn',
|
|
10
|
+
},
|
|
11
|
+
}
|
package/rules/react.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: ['react'],
|
|
3
|
+
extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'],
|
|
4
|
+
rules: {
|
|
5
|
+
// Enforce consistent usage of function component definition
|
|
6
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
|
|
7
|
+
'react/function-component-definition': [
|
|
8
|
+
'error',
|
|
9
|
+
{
|
|
10
|
+
namedComponents: 'arrow-function',
|
|
11
|
+
unnamedComponents: 'arrow-function',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
// Prevent missing React when using JSX (React 17+ JSX transform)
|
|
15
|
+
'react/react-in-jsx-scope': 'off',
|
|
16
|
+
// Enforce rules of hooks
|
|
17
|
+
'react-hooks/rules-of-hooks': 'error',
|
|
18
|
+
// Verify the list of the dependencies for Hooks like useEffect and similar
|
|
19
|
+
'react-hooks/exhaustive-deps': 'warn',
|
|
20
|
+
},
|
|
21
|
+
}
|
package/rules/typescript.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
const { hasPackage } = require('../lib/utils')
|
|
2
|
-
|
|
3
2
|
const hasTypescript = hasPackage('typescript')
|
|
4
3
|
const hasNestJs = hasPackage('@nestjs/core')
|
|
4
|
+
const hasReact = hasPackage('react')
|
|
5
|
+
const hasNext = hasPackage('next') || hasPackage('nextjs')
|
|
6
|
+
|
|
7
|
+
// Load framework-specific rules
|
|
8
|
+
const reactRules = hasReact ? require('./react.js').rules : {}
|
|
9
|
+
const nextjsRules = hasNext ? require('./nextjs.js').rules : {}
|
|
10
|
+
const nestjsRules = hasNestJs ? require('./nestjs.js').rules : {}
|
|
5
11
|
|
|
6
12
|
const tsConfigOptions = [
|
|
7
13
|
{
|
|
@@ -12,15 +18,8 @@ const tsConfigOptions = [
|
|
|
12
18
|
parserOptions: {
|
|
13
19
|
ecmaVersion: 2022,
|
|
14
20
|
sourceType: 'module',
|
|
15
|
-
project: [
|
|
16
|
-
// look in the root
|
|
17
|
-
'tsconfig{.eslint.json,.json}',
|
|
18
|
-
// look in dirs like node/react
|
|
19
|
-
'*/tsconfig{.eslint.json,.json}',
|
|
20
|
-
// look in dirs like packages/package/*
|
|
21
|
-
'*/*/tsconfig{.eslint.json,.json}',
|
|
22
|
-
],
|
|
23
21
|
projectService: true,
|
|
22
|
+
defaultProject: 'tsconfig.json',
|
|
24
23
|
tsconfigRootDir: process.cwd(),
|
|
25
24
|
projectFolderIgnoreList: [/node_modules/i],
|
|
26
25
|
// We need this configuration to avoid performance issues in monorepos
|
|
@@ -28,245 +27,22 @@ const tsConfigOptions = [
|
|
|
28
27
|
allowAutomaticSingleRunInference: true,
|
|
29
28
|
},
|
|
30
29
|
rules: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'no-
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
allow: ['done', 'next', 'resolve', 'reject', 'cb'],
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
|
|
44
|
-
// Prevent unused declared variables
|
|
45
|
-
// https://typescript-eslint.io/rules/no-unused-vars/
|
|
46
|
-
'no-unused-vars': 'off',
|
|
47
|
-
'@typescript-eslint/no-unused-vars': [
|
|
48
|
-
'warn',
|
|
49
|
-
{
|
|
50
|
-
ignoreRestSiblings: true,
|
|
51
|
-
argsIgnorePattern: '^_+',
|
|
52
|
-
varsIgnorePattern: '^_',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
|
|
56
|
-
// Disallows the use of eval()-like methods
|
|
57
|
-
// https://typescript-eslint.io/rules/no-magic-numbers/
|
|
58
|
-
'no-magic-numbers': 'off',
|
|
59
|
-
'@typescript-eslint/no-magic-numbers': [
|
|
60
|
-
'off',
|
|
61
|
-
{
|
|
62
|
-
ignore: [0, 1, 2, 3],
|
|
63
|
-
ignoreArrayIndexes: true,
|
|
64
|
-
enforceConst: true,
|
|
65
|
-
detectObjects: false,
|
|
66
|
-
ignoreNumericLiteralTypes: true,
|
|
67
|
-
ignoreEnums: true,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
// Enforce parameters with default values to be last
|
|
72
|
-
// https://typescript-eslint.io/rules/default-param-last/
|
|
73
|
-
'default-param-last': 'off',
|
|
74
|
-
'@typescript-eslint/default-param-last': 'error',
|
|
75
|
-
|
|
76
|
-
// Disallow useless constructors
|
|
77
|
-
// https://typescript-eslint.io/rules/no-useless-constructor/
|
|
78
|
-
'no-useless-constructor': 'off',
|
|
79
|
-
'@typescript-eslint/no-useless-constructor': 'error',
|
|
80
|
-
|
|
81
|
-
// Disallow empty functions, except for standalone funcs/arrows
|
|
82
|
-
// https://eslint.org/docs/rules/no-empty-function
|
|
83
|
-
'no-empty-function': 'off',
|
|
84
|
-
'@typescript-eslint/no-empty-function': [
|
|
30
|
+
// General improvements
|
|
31
|
+
'no-useless-catch': 'warn',
|
|
32
|
+
'no-magic-numbers': ['warn', { ignore: [0, 1], ignoreArrayIndexes: true }],
|
|
33
|
+
'max-classes-per-file': ['warn', 1],
|
|
34
|
+
'prefer-arrow-callback': ['warn', { allowNamedFunctions: false, allowUnboundThis: true }],
|
|
35
|
+
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
|
|
36
|
+
'import/no-relative-parent-imports': 'warn',
|
|
37
|
+
'no-restricted-imports': [
|
|
85
38
|
'error',
|
|
86
39
|
{
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
|
|
91
|
-
// Require a consistent naming convention
|
|
92
|
-
// https://typescript-eslint.io/rules/naming-convention/
|
|
93
|
-
camelcase: 'off',
|
|
94
|
-
'@typescript-eslint/naming-convention': [
|
|
95
|
-
'error',
|
|
96
|
-
{
|
|
97
|
-
selector: 'default',
|
|
98
|
-
format: ['camelCase'],
|
|
99
|
-
leadingUnderscore: 'allow',
|
|
100
|
-
trailingUnderscore: 'allow',
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
selector: 'variable',
|
|
104
|
-
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
|
|
105
|
-
leadingUnderscore: 'allow',
|
|
106
|
-
trailingUnderscore: 'allow',
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
selector: 'function',
|
|
110
|
-
format: ['camelCase', 'PascalCase'],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
selector: 'typeLike',
|
|
114
|
-
format: ['PascalCase'],
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
selector: 'memberLike',
|
|
118
|
-
format: null,
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
// have to leave this for now as this rule
|
|
122
|
-
// doesn't separate regular parameters from
|
|
123
|
-
// destructured parameters
|
|
124
|
-
selector: 'parameter',
|
|
125
|
-
format: null,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
|
|
129
|
-
// Disallow use of variables before they are defined
|
|
130
|
-
// https://typescript-eslint.io/rules/no-use-before-define/
|
|
131
|
-
'no-use-before-define': 'off',
|
|
132
|
-
'@typescript-eslint/no-use-before-define': [
|
|
133
|
-
'error',
|
|
134
|
-
{
|
|
135
|
-
functions: false,
|
|
136
|
-
classes: false,
|
|
137
|
-
variables: true,
|
|
138
|
-
enums: false,
|
|
139
|
-
typedefs: false,
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
// ! ts only rules
|
|
143
|
-
// Enforce explicit accessibility modifiers on class properties and methods
|
|
144
|
-
// https://typescript-eslint.io/rules/explicit-member-accessibility/
|
|
145
|
-
'@typescript-eslint/explicit-member-accessibility': hasNestJs
|
|
146
|
-
? 'off'
|
|
147
|
-
: [
|
|
148
|
-
'error',
|
|
149
|
-
{
|
|
150
|
-
accessibility: 'explicit',
|
|
151
|
-
overrides: {
|
|
152
|
-
accessors: 'explicit',
|
|
153
|
-
constructors: 'no-public',
|
|
154
|
-
methods: 'explicit',
|
|
155
|
-
parameterProperties: 'explicit',
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
|
|
160
|
-
// Don't allow "any" at all
|
|
161
|
-
// https://typescript-eslint.io/rules/no-explicit-any
|
|
162
|
-
'@typescript-eslint/no-explicit-any': hasNestJs ? 'warn' : 'error',
|
|
163
|
-
|
|
164
|
-
// Enforce explicit function return type
|
|
165
|
-
// https://typescript-eslint.io/rules/explicit-function-return-type/
|
|
166
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
167
|
-
|
|
168
|
-
// Enforce a consistent way of typing arrays
|
|
169
|
-
// https://typescript-eslint.io/rules/array-type/v
|
|
170
|
-
'@typescript-eslint/array-type': [
|
|
171
|
-
'warn',
|
|
172
|
-
{
|
|
173
|
-
default: 'array-simple',
|
|
174
|
-
readonly: 'array-simple',
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
|
|
178
|
-
// Enforce a consitent way to type objects
|
|
179
|
-
// https://typescript-eslint.io/rules/consistent-type-definitions/
|
|
180
|
-
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
181
|
-
|
|
182
|
-
// Disallow non null assertions (!), comes from the recommended config
|
|
183
|
-
// https://typescript-eslint.io/rules/no-non-null-assertion/
|
|
184
|
-
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
185
|
-
|
|
186
|
-
// Enforce that when adding two variables, operands must both be of type number or of type string
|
|
187
|
-
// https://typescript-eslint.io/rules/restrict-plus-operands/
|
|
188
|
-
'@typescript-eslint/restrict-plus-operands': ['error'],
|
|
189
|
-
|
|
190
|
-
// Enforce optional chaining over chaining AND (&&) operators
|
|
191
|
-
// https://typescript-eslint.io/rules/prefer-optional-chain/
|
|
192
|
-
'@typescript-eslint/prefer-optional-chain': 'warn',
|
|
193
|
-
|
|
194
|
-
// Enforce optional chaining over chaining AND (&&) operators
|
|
195
|
-
// https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain/
|
|
196
|
-
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
|
197
|
-
|
|
198
|
-
// Enforce nullish coalescing over short-circuiting
|
|
199
|
-
// https://typescript-eslint.io/rules/prefer-nullish-coalescing/
|
|
200
|
-
'@typescript-eslint/prefer-nullish-coalescing': [
|
|
201
|
-
'warn',
|
|
202
|
-
{
|
|
203
|
-
ignoreConditionalTests: true,
|
|
204
|
-
ignoreMixedLogicalExpressions: true,
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
|
|
208
|
-
// Prefer usage of as const over literal type
|
|
209
|
-
// https://typescript-eslint.io/rules/prefer-as-const/
|
|
210
|
-
'@typescript-eslint/prefer-as-const': 'error',
|
|
211
|
-
|
|
212
|
-
// Prevent unnecessary type arguments
|
|
213
|
-
// https://typescript-eslint.io/rules/no-unnecessary-type-arguments/
|
|
214
|
-
'@typescript-eslint/no-unnecessary-type-arguments': 'warn',
|
|
215
|
-
|
|
216
|
-
// Warns when a namespace qualifier is unnecessary
|
|
217
|
-
// https://typescript-eslint.io/rules/no-unnecessary-qualifier/
|
|
218
|
-
'@typescript-eslint/no-unnecessary-qualifier': 'warn',
|
|
219
|
-
|
|
220
|
-
// Disallow throwing literals as exceptions
|
|
221
|
-
// https://typescript-eslint.io/rules/no-throw-literal/
|
|
222
|
-
'no-throw-literal': 'warn',
|
|
223
|
-
|
|
224
|
-
// Disallows invocation of require() in favor of import statements
|
|
225
|
-
// https://typescript-eslint.io/rules/no-require-imports/
|
|
226
|
-
'@typescript-eslint/no-require-imports': 'warn',
|
|
227
|
-
|
|
228
|
-
// Disallows the use of eval()-like methods
|
|
229
|
-
// https://typescript-eslint.io/rules/no-implied-eval/
|
|
230
|
-
'@typescript-eslint/no-implied-eval': 'error',
|
|
231
|
-
|
|
232
|
-
// Requires Array#sort calls to always provide a compareFunction
|
|
233
|
-
// https://typescript-eslint.io/rules/require-array-sort-compare/
|
|
234
|
-
'@typescript-eslint/require-array-sort-compare': 'error',
|
|
235
|
-
|
|
236
|
-
// Enforce explicit enum item values
|
|
237
|
-
// https://typescript-eslint.io/rules/prefer-enum-initializers/
|
|
238
|
-
'@typescript-eslint/prefer-enum-initializers': 'warn',
|
|
239
|
-
|
|
240
|
-
// Explicitly defines what a module scoped method returns
|
|
241
|
-
// https://typescript-eslint.io/rules/explicit-module-boundary-types/
|
|
242
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
243
|
-
|
|
244
|
-
// Disallow // @ts comments
|
|
245
|
-
// https://typescript-eslint.io/rules/ban-ts-comment/
|
|
246
|
-
'@typescript-eslint/ban-ts-comment': [
|
|
247
|
-
'error',
|
|
248
|
-
{
|
|
249
|
-
'ts-expect-error': 'allow-with-description',
|
|
250
|
-
'ts-ignore': true,
|
|
251
|
-
'ts-nocheck': true,
|
|
252
|
-
'ts-check': false,
|
|
253
|
-
minimumDescriptionLength: 3,
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
|
|
257
|
-
// Disallows unnecessary constraints on generic types
|
|
258
|
-
// https://typescript-eslint.io/rules/no-unnecessary-type-constraint/
|
|
259
|
-
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
|
|
260
|
-
|
|
261
|
-
// Enforces consistent usage of type imports
|
|
262
|
-
// https://typescript-eslint.io/rules/consistent-type-imports/
|
|
263
|
-
'@typescript-eslint/consistent-type-imports': [
|
|
264
|
-
'warn',
|
|
265
|
-
{
|
|
266
|
-
prefer: 'type-imports',
|
|
267
|
-
disallowTypeAnnotations: false,
|
|
40
|
+
patterns: ['../../*'],
|
|
268
41
|
},
|
|
269
42
|
],
|
|
43
|
+
...reactRules,
|
|
44
|
+
...nextjsRules,
|
|
45
|
+
...nestjsRules,
|
|
270
46
|
},
|
|
271
47
|
},
|
|
272
48
|
{
|