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