@petbee/eslint-config 3.0.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@petbee/eslint-config",
3
- "version": "3.0.5",
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": "033cab1e3f57a1b92490ef1326415d33a21b0ec9"
85
+ "gitHead": "d44351fa9e995cc0dc22f9b85f55d7305e6642ae"
85
86
  }
package/rules/nextjs.js CHANGED
@@ -1,13 +1,48 @@
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
- },
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
@@ -1,5 +1,6 @@
1
- const reactPlugin = require('eslint-plugin-react')
2
- const reactHooksPlugin = require('eslint-plugin-react-hooks')
1
+ const { hasPackage } = require('../lib/utils')
2
+
3
+ const hasReact = hasPackage('react')
3
4
 
4
5
  const reactRules = {
5
6
  // Allow non-camelCase naming in React projects (e.g., components, hooks, CSS modules)
@@ -21,32 +22,48 @@ const reactRules = {
21
22
  'react-hooks/exhaustive-deps': 'warn',
22
23
  }
23
24
 
24
- // Legacy config for ESLint < 9
25
- module.exports = {
26
- plugins: ['react'],
27
- extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'],
28
- rules: reactRules,
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
+ }
29
34
  }
30
35
 
31
- // Flat config for ESLint v9+
32
- module.exports.flat = [
33
- {
34
- files: ['**/*.{jsx,tsx}'],
35
- plugins: {
36
- react: reactPlugin,
37
- 'react-hooks': reactHooksPlugin,
38
- },
39
- languageOptions: {
40
- parserOptions: {
41
- ecmaFeatures: {
42
- jsx: true,
36
+ module.exports = legacyConfig
37
+
38
+ // Flat config for ESLint v9+ - only created if React is available
39
+ let flatConfig = []
40
+
41
+ if (hasReact) {
42
+ // If React is available, require React plugins. If they're missing, this will fail (expected behavior)
43
+ const reactPlugin = require('eslint-plugin-react')
44
+ const reactHooksPlugin = require('eslint-plugin-react-hooks')
45
+
46
+ flatConfig = [
47
+ {
48
+ files: ['**/*.{jsx,tsx}'],
49
+ plugins: {
50
+ react: reactPlugin,
51
+ 'react-hooks': reactHooksPlugin,
52
+ },
53
+ languageOptions: {
54
+ parserOptions: {
55
+ ecmaFeatures: {
56
+ jsx: true,
57
+ },
43
58
  },
44
59
  },
60
+ rules: {
61
+ ...reactPlugin.configs.recommended.rules,
62
+ ...reactHooksPlugin.configs.recommended.rules,
63
+ ...reactRules,
64
+ },
45
65
  },
46
- rules: {
47
- ...reactPlugin.configs.recommended.rules,
48
- ...reactHooksPlugin.configs.recommended.rules,
49
- ...reactRules,
50
- },
51
- },
52
- ]
66
+ ]
67
+ }
68
+
69
+ module.exports.flat = flatConfig
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
- module.exports = {
6
- overrides: [
7
- // ! CYPRESS
8
- {
9
- files: ['**/cypress/**/*.{ts,tsx,js,jsx}'],
10
- extends: ['plugin:cypress/recommended'],
11
- rules: {
12
- // Enforce assertions before taking a screenshot
13
- // https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md
14
- 'cypress/assertion-before-screenshot': 'warn',
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
- // ! JEST
18
- {
19
- // Run through every test file found
20
- files: ['*.{test,spec}.{ts,tsx,js,jsx}'],
21
- // Unless it's inside a cypress directory
22
- excludedFiles: ['**/cypress/**'],
23
- extends: ['plugin:jest/recommended', 'plugin:jest/style'],
24
- rules: {
25
- // Enforce consistent a test method name
26
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/consistent-test-it.md
27
- 'jest/consistent-test-it': [
28
- 'warn',
29
- {
30
- fn: 'test',
31
- withinDescribe: 'it',
32
- },
33
- ],
34
-
35
- // Disallow alias methods
36
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-alias-methods.md
37
- 'jest/no-alias-methods': 'error',
38
-
39
- // Disallow duplicate setup/teardown hooks
40
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-duplicate-hooks.md
41
- 'jest/no-duplicate-hooks': 'error',
42
-
43
- // Suggest to have all hooks at top-level before tests
44
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-hooks-on-top.md
45
- 'jest/prefer-hooks-on-top': 'error',
46
-
47
- // Suggest jest.spyOn() instead of jest.fn()
48
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-spy-on.md
49
- 'jest/prefer-spy-on': 'warn',
50
-
51
- // Suggest using test.todo()
52
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-todo.md
53
- 'jest/prefer-todo': 'warn',
54
-
55
- // Disallow return statements from tests
56
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-test-return-statement.md
57
- 'jest/no-test-return-statement': 'warn',
58
-
59
- // Disallow deprecated jest functions
60
- // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-deprecated-functions.md
61
- 'jest/no-deprecated-functions': 'error',
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
- module.exports.flat = [
69
- {
70
- files: module.exports.overrides[0].files,
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: module.exports.overrides[0].rules,
75
- },
76
- {
77
- files: module.exports.overrides[1].files,
78
- excludedFiles: module.exports.overrides[1].excludedFiles,
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: module.exports.overrides[1].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