@petbee/eslint-config 3.0.6 → 3.0.7
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 +3 -2
- package/rules/nextjs.js +47 -12
- package/rules/react.js +11 -5
- package/rules/tests.js +103 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petbee/eslint-config",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Petbee's eslint config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"eslint-plugin-n": "^17.23.1",
|
|
52
52
|
"eslint-plugin-prettier": "^5.5.4",
|
|
53
53
|
"eslint-plugin-react": "7.37.5",
|
|
54
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
54
55
|
"typescript-eslint": "^8.47.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
@@ -81,5 +82,5 @@
|
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public"
|
|
83
84
|
},
|
|
84
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "d44351fa9e995cc0dc22f9b85f55d7305e6642ae"
|
|
85
86
|
}
|
package/rules/nextjs.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const { hasPackage } = require('../lib/utils')
|
|
2
|
+
|
|
3
|
+
const hasNextJs = hasPackage('next')
|
|
4
|
+
|
|
5
|
+
const nextjsRules = {
|
|
6
|
+
// Allow non-camelCase naming in Next.js projects (e.g., route segments, pages, metadata)
|
|
7
|
+
'@typescript-eslint/naming-convention': 'off',
|
|
8
|
+
// Next.js specific rules can be added here
|
|
9
|
+
// For example, enforce no HTML <img> element usage
|
|
10
|
+
'@next/next/no-img-element': 'error',
|
|
11
|
+
// Enforce usage of next/link for navigation
|
|
12
|
+
'@next/next/no-html-link-for-pages': 'warn',
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
// Legacy config for ESLint < 9 - only created if Next.js is available
|
|
16
|
+
let legacyConfig = {}
|
|
17
|
+
|
|
18
|
+
if (hasNextJs) {
|
|
19
|
+
legacyConfig = {
|
|
20
|
+
plugins: ['@next/eslint-plugin-next'],
|
|
21
|
+
extends: ['plugin:@next/next/recommended'],
|
|
22
|
+
rules: nextjsRules,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = legacyConfig
|
|
27
|
+
|
|
28
|
+
// Flat config for ESLint v9+ - only created if Next.js is available
|
|
29
|
+
let flatConfig = []
|
|
30
|
+
|
|
31
|
+
if (hasNextJs) {
|
|
32
|
+
const nextjsPlugin = require('@next/eslint-plugin-next')
|
|
33
|
+
|
|
34
|
+
flatConfig = [
|
|
35
|
+
{
|
|
36
|
+
files: ['**/*.{jsx,tsx}'],
|
|
37
|
+
plugins: {
|
|
38
|
+
'@next/next': nextjsPlugin,
|
|
39
|
+
},
|
|
40
|
+
rules: {
|
|
41
|
+
...nextjsPlugin.configs.recommended.rules,
|
|
42
|
+
...nextjsRules,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports.flat = flatConfig
|
package/rules/react.js
CHANGED
|
@@ -22,13 +22,19 @@ const reactRules = {
|
|
|
22
22
|
'react-hooks/exhaustive-deps': 'warn',
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// Legacy config for ESLint < 9
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
// Legacy config for ESLint < 9 - only created if React is available
|
|
26
|
+
let legacyConfig = {}
|
|
27
|
+
|
|
28
|
+
if (hasReact) {
|
|
29
|
+
legacyConfig = {
|
|
30
|
+
plugins: ['react'],
|
|
31
|
+
extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'],
|
|
32
|
+
rules: reactRules,
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
module.exports = legacyConfig
|
|
37
|
+
|
|
32
38
|
// Flat config for ESLint v9+ - only created if React is available
|
|
33
39
|
let flatConfig = []
|
|
34
40
|
|
package/rules/tests.js
CHANGED
|
@@ -2,83 +2,117 @@
|
|
|
2
2
|
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules
|
|
3
3
|
// Cypress: https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const { hasPackage } = require('../lib/utils')
|
|
6
|
+
|
|
7
|
+
const hasCypress = hasPackage('cypress')
|
|
8
|
+
const hasJest = hasPackage('jest')
|
|
9
|
+
|
|
10
|
+
const overrides = []
|
|
11
|
+
|
|
12
|
+
if (hasCypress) {
|
|
13
|
+
overrides.push({
|
|
14
|
+
files: ['**/cypress/**/*.{ts,tsx,js,jsx}'],
|
|
15
|
+
extends: ['plugin:cypress/recommended'],
|
|
16
|
+
rules: {
|
|
17
|
+
// Enforce assertions before taking a screenshot
|
|
18
|
+
// https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md
|
|
19
|
+
'cypress/assertion-before-screenshot': 'warn',
|
|
16
20
|
},
|
|
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
|
-
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (hasJest) {
|
|
25
|
+
overrides.push({
|
|
26
|
+
// Run through every test file found
|
|
27
|
+
files: ['*.{test,spec}.{ts,tsx,js,jsx}'],
|
|
28
|
+
// Unless it's inside a cypress directory
|
|
29
|
+
excludedFiles: ['**/cypress/**'],
|
|
30
|
+
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
|
|
31
|
+
rules: {
|
|
32
|
+
// Enforce consistent a test method name
|
|
33
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/consistent-test-it.md
|
|
34
|
+
'jest/consistent-test-it': [
|
|
35
|
+
'warn',
|
|
36
|
+
{
|
|
37
|
+
fn: 'test',
|
|
38
|
+
withinDescribe: 'it',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
// Disallow alias methods
|
|
43
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-alias-methods.md
|
|
44
|
+
'jest/no-alias-methods': 'error',
|
|
45
|
+
|
|
46
|
+
// Disallow duplicate setup/teardown hooks
|
|
47
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-duplicate-hooks.md
|
|
48
|
+
'jest/no-duplicate-hooks': 'error',
|
|
49
|
+
|
|
50
|
+
// Suggest to have all hooks at top-level before tests
|
|
51
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-hooks-on-top.md
|
|
52
|
+
'jest/prefer-hooks-on-top': 'error',
|
|
53
|
+
|
|
54
|
+
// Suggest jest.spyOn() instead of jest.fn()
|
|
55
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-spy-on.md
|
|
56
|
+
'jest/prefer-spy-on': 'warn',
|
|
57
|
+
|
|
58
|
+
// Suggest using test.todo()
|
|
59
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-todo.md
|
|
60
|
+
'jest/prefer-todo': 'warn',
|
|
61
|
+
|
|
62
|
+
// Disallow return statements from tests
|
|
63
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-test-return-statement.md
|
|
64
|
+
'jest/no-test-return-statement': 'warn',
|
|
65
|
+
|
|
66
|
+
// Disallow deprecated jest functions
|
|
67
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-deprecated-functions.md
|
|
68
|
+
'jest/no-deprecated-functions': 'error',
|
|
63
69
|
},
|
|
64
|
-
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
overrides,
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
// Flat config for ESLint v9 (no extends, plugins as object)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
const flatConfig = []
|
|
79
|
+
|
|
80
|
+
if (hasCypress) {
|
|
81
|
+
flatConfig.push({
|
|
82
|
+
files: ['**/cypress/**/*.{ts,tsx,js,jsx}'],
|
|
71
83
|
plugins: {
|
|
72
84
|
cypress: require('eslint-plugin-cypress'),
|
|
73
85
|
},
|
|
74
|
-
rules:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
rules: {
|
|
87
|
+
'cypress/assertion-before-screenshot': 'warn',
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (hasJest) {
|
|
93
|
+
flatConfig.push({
|
|
94
|
+
files: ['*.{test,spec}.{ts,tsx,js,jsx}'],
|
|
95
|
+
excludedFiles: ['**/cypress/**'],
|
|
79
96
|
plugins: {
|
|
80
97
|
jest: require('eslint-plugin-jest'),
|
|
81
98
|
},
|
|
82
|
-
rules:
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
rules: {
|
|
100
|
+
'jest/consistent-test-it': [
|
|
101
|
+
'warn',
|
|
102
|
+
{
|
|
103
|
+
fn: 'test',
|
|
104
|
+
withinDescribe: 'it',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
'jest/no-alias-methods': 'error',
|
|
108
|
+
'jest/no-duplicate-hooks': 'error',
|
|
109
|
+
'jest/prefer-hooks-on-top': 'error',
|
|
110
|
+
'jest/prefer-spy-on': 'warn',
|
|
111
|
+
'jest/prefer-todo': 'warn',
|
|
112
|
+
'jest/no-test-return-statement': 'warn',
|
|
113
|
+
'jest/no-deprecated-functions': 'error',
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports.flat = flatConfig
|