@petbee/eslint-config 3.0.3 → 3.0.5
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.mjs +3 -0
- package/package.json +2 -2
- package/rules/nestjs.js +7 -10
- package/rules/react.js +47 -18
- package/rules/shared-config.js +36 -0
- package/rules/typescript.js +10 -28
package/index.mjs
CHANGED
|
@@ -10,12 +10,14 @@ import importsConfig from './rules/imports.js'
|
|
|
10
10
|
import nestjsConfig from './rules/nestjs.js'
|
|
11
11
|
import nodeConfig from './rules/node.js'
|
|
12
12
|
import prettierConfig from './rules/prettier.js'
|
|
13
|
+
import reactConfig from './rules/react.js'
|
|
13
14
|
import styleConfig from './rules/style.js'
|
|
14
15
|
import testsConfig from './rules/tests.js'
|
|
15
16
|
import typescriptConfig from './rules/typescript.js'
|
|
16
17
|
import variablesConfig from './rules/variables.js'
|
|
17
18
|
|
|
18
19
|
const hasTypescript = hasPackage('typescript')
|
|
20
|
+
const hasReact = hasPackage('react')
|
|
19
21
|
|
|
20
22
|
const ignoreConfig = {
|
|
21
23
|
ignores: ['coverage', 'dist', '**/dist/', 'node_modules', '**/node_modules'],
|
|
@@ -33,6 +35,7 @@ const eslintFlatConfig = [
|
|
|
33
35
|
...getFlat(bestPracticesConfig),
|
|
34
36
|
...getFlat(importsConfig),
|
|
35
37
|
...getFlat(testsConfig),
|
|
38
|
+
...(hasReact ? getFlat(reactConfig) : []),
|
|
36
39
|
]
|
|
37
40
|
|
|
38
41
|
const nestjsEslintFlatConfig = nestjsConfig.flat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petbee/eslint-config",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
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": "033cab1e3f57a1b92490ef1326415d33a21b0ec9"
|
|
85
85
|
}
|
package/rules/nestjs.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
const { hasPackage
|
|
1
|
+
const { hasPackage } = require('../lib/utils')
|
|
2
2
|
const nestjsLint = require('@darraghor/eslint-plugin-nestjs-typed')
|
|
3
|
-
const
|
|
3
|
+
const { tsParserOptions } = require('./shared-config.js')
|
|
4
4
|
|
|
5
5
|
const hasNestJs = hasPackage('@nestjs/core')
|
|
6
6
|
|
|
7
|
-
// Grab TS-ESLint flat override
|
|
8
|
-
const tsFlat = getFlat(tsConfig)
|
|
9
|
-
|
|
10
7
|
const nestjsRules = {
|
|
11
8
|
'@typescript-eslint/interface-name-prefix': 'off',
|
|
12
9
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
@@ -25,19 +22,19 @@ const nestjsRules = {
|
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
// If NestJS is present, take its flatRecommended array and
|
|
28
|
-
// graft in parserOptions from
|
|
25
|
+
// graft in parserOptions from shared config:
|
|
29
26
|
const nestFlat = hasNestJs
|
|
30
27
|
? [
|
|
31
28
|
...nestjsLint.default.configs.flatRecommended.map((cfg) => ({
|
|
32
29
|
...cfg,
|
|
33
30
|
languageOptions: {
|
|
34
|
-
|
|
35
|
-
...cfg.languageOptions,
|
|
36
|
-
// merge parserOptions so `project` stays intact
|
|
31
|
+
parser: require('@typescript-eslint/parser'),
|
|
37
32
|
parserOptions: {
|
|
38
|
-
...
|
|
33
|
+
...tsParserOptions,
|
|
34
|
+
// merge with any NestJS-specific parserOptions
|
|
39
35
|
...cfg.languageOptions?.parserOptions,
|
|
40
36
|
},
|
|
37
|
+
...cfg.languageOptions,
|
|
41
38
|
},
|
|
42
39
|
})),
|
|
43
40
|
{
|
package/rules/react.js
CHANGED
|
@@ -1,23 +1,52 @@
|
|
|
1
|
+
const reactPlugin = require('eslint-plugin-react')
|
|
2
|
+
const reactHooksPlugin = require('eslint-plugin-react-hooks')
|
|
3
|
+
|
|
4
|
+
const reactRules = {
|
|
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
|
+
|
|
24
|
+
// Legacy config for ESLint < 9
|
|
1
25
|
module.exports = {
|
|
2
26
|
plugins: ['react'],
|
|
3
27
|
extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'],
|
|
4
|
-
rules:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
rules: reactRules,
|
|
29
|
+
}
|
|
30
|
+
|
|
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,
|
|
43
|
+
},
|
|
14
44
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'react-hooks/exhaustive-deps': 'warn',
|
|
45
|
+
},
|
|
46
|
+
rules: {
|
|
47
|
+
...reactPlugin.configs.recommended.rules,
|
|
48
|
+
...reactHooksPlugin.configs.recommended.rules,
|
|
49
|
+
...reactRules,
|
|
50
|
+
},
|
|
22
51
|
},
|
|
23
|
-
|
|
52
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Shared configuration to avoid circular dependencies
|
|
2
|
+
const { hasPackage } = require('../lib/utils')
|
|
3
|
+
|
|
4
|
+
const hasTypescript = hasPackage('typescript')
|
|
5
|
+
|
|
6
|
+
// Common TypeScript parser configuration
|
|
7
|
+
const tsParserOptions = {
|
|
8
|
+
ecmaVersion: 2022,
|
|
9
|
+
sourceType: 'module',
|
|
10
|
+
projectService: true,
|
|
11
|
+
tsconfigRootDir: process.cwd(),
|
|
12
|
+
projectFolderIgnoreList: [/node_modules/i],
|
|
13
|
+
allowAutomaticSingleRunInference: true,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Common TypeScript rules
|
|
17
|
+
const tsCommonRules = {
|
|
18
|
+
'no-useless-catch': 'warn',
|
|
19
|
+
'no-magic-numbers': ['warn', { ignore: [0, 1], ignoreArrayIndexes: true }],
|
|
20
|
+
'max-classes-per-file': ['warn', 1],
|
|
21
|
+
'prefer-arrow-callback': ['warn', { allowNamedFunctions: false, allowUnboundThis: true }],
|
|
22
|
+
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
|
|
23
|
+
'import/no-relative-parent-imports': 'warn',
|
|
24
|
+
'no-restricted-imports': [
|
|
25
|
+
'error',
|
|
26
|
+
{
|
|
27
|
+
patterns: ['../../*'],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
hasTypescript,
|
|
34
|
+
tsParserOptions,
|
|
35
|
+
tsCommonRules,
|
|
36
|
+
}
|
package/rules/typescript.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
const { hasPackage } = require('../lib/utils')
|
|
2
|
-
const hasTypescript =
|
|
2
|
+
const { hasTypescript, tsParserOptions, tsCommonRules } = require('./shared-config.js')
|
|
3
|
+
|
|
3
4
|
const hasNestJs = hasPackage('@nestjs/core')
|
|
4
|
-
const hasReact = hasPackage('react')
|
|
5
5
|
const hasNext = hasPackage('next') || hasPackage('nextjs')
|
|
6
6
|
|
|
7
7
|
// Load framework-specific rules
|
|
8
|
-
const reactRules = hasReact ? require('./react.js').rules : {}
|
|
9
8
|
const nextjsRules = hasNext ? require('./nextjs.js').rules : {}
|
|
10
|
-
|
|
9
|
+
// Note: Don't require nestjs.js here to avoid circular dependency.
|
|
10
|
+
// NestJS handles its own flat config completely.
|
|
11
|
+
// React rules are now handled separately in index.mjs
|
|
12
|
+
const nestjsRules = {}
|
|
13
|
+
const reactRules = {}
|
|
11
14
|
|
|
12
15
|
const tsConfigOptions = [
|
|
13
16
|
{
|
|
@@ -15,30 +18,9 @@ const tsConfigOptions = [
|
|
|
15
18
|
extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
|
|
16
19
|
plugins: ['@typescript-eslint'],
|
|
17
20
|
parser: '@typescript-eslint/parser',
|
|
18
|
-
parserOptions:
|
|
19
|
-
ecmaVersion: 2022,
|
|
20
|
-
sourceType: 'module',
|
|
21
|
-
projectService: true,
|
|
22
|
-
tsconfigRootDir: process.cwd(),
|
|
23
|
-
projectFolderIgnoreList: [/node_modules/i],
|
|
24
|
-
// We need this configuration to avoid performance issues in monorepos
|
|
25
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-862414778
|
|
26
|
-
allowAutomaticSingleRunInference: true,
|
|
27
|
-
},
|
|
21
|
+
parserOptions: tsParserOptions,
|
|
28
22
|
rules: {
|
|
29
|
-
|
|
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': [
|
|
37
|
-
'error',
|
|
38
|
-
{
|
|
39
|
-
patterns: ['../../*'],
|
|
40
|
-
},
|
|
41
|
-
],
|
|
23
|
+
...tsCommonRules,
|
|
42
24
|
...reactRules,
|
|
43
25
|
...nextjsRules,
|
|
44
26
|
...nestjsRules,
|
|
@@ -62,7 +44,7 @@ const flatConfig = hasTypescript
|
|
|
62
44
|
languageOptions: {
|
|
63
45
|
parser: require('@typescript-eslint/parser'),
|
|
64
46
|
parserOptions: {
|
|
65
|
-
...
|
|
47
|
+
...tsParserOptions,
|
|
66
48
|
tsconfigRootDir: process.cwd(),
|
|
67
49
|
},
|
|
68
50
|
},
|