@petbee/eslint-config 3.0.3 → 3.0.4

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.3",
3
+ "version": "3.0.4",
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": "46ff4afe672b542fcbd6d2f0b6481f52f2379b24"
84
+ "gitHead": "13a8a59332c6aa1b447f5d830041e7ed00d3e7a2"
85
85
  }
package/rules/nestjs.js CHANGED
@@ -1,12 +1,9 @@
1
- const { hasPackage, getFlat } = require('../lib/utils')
1
+ const { hasPackage } = require('../lib/utils')
2
2
  const nestjsLint = require('@darraghor/eslint-plugin-nestjs-typed')
3
- const tsConfig = require('./typescript.js') // <-- our patched TS config
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 tsFlat[0]:
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
- ...tsFlat[0].languageOptions,
35
- ...cfg.languageOptions,
36
- // merge parserOptions so `project` stays intact
31
+ parser: require('@typescript-eslint/parser'),
37
32
  parserOptions: {
38
- ...tsFlat[0].languageOptions.parserOptions,
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
  {
@@ -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
+ }
@@ -1,5 +1,6 @@
1
1
  const { hasPackage } = require('../lib/utils')
2
- const hasTypescript = hasPackage('typescript')
2
+ const { hasTypescript, tsParserOptions, tsCommonRules } = require('./shared-config.js')
3
+
3
4
  const hasNestJs = hasPackage('@nestjs/core')
4
5
  const hasReact = hasPackage('react')
5
6
  const hasNext = hasPackage('next') || hasPackage('nextjs')
@@ -7,7 +8,9 @@ const hasNext = hasPackage('next') || hasPackage('nextjs')
7
8
  // Load framework-specific rules
8
9
  const reactRules = hasReact ? require('./react.js').rules : {}
9
10
  const nextjsRules = hasNext ? require('./nextjs.js').rules : {}
10
- const nestjsRules = hasNestJs ? require('./nestjs.js').rules : {}
11
+ // Note: Don't require nestjs.js here to avoid circular dependency.
12
+ // NestJS handles its own flat config completely.
13
+ const nestjsRules = {}
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
- // 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': [
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
- ...tsConfigOptions[0].parserOptions,
47
+ ...tsParserOptions,
66
48
  tsconfigRootDir: process.cwd(),
67
49
  },
68
50
  },