@petbee/eslint-config 2.0.12 → 2.0.13

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 CHANGED
@@ -3,6 +3,8 @@ module.exports = {
3
3
  parserOptions: {
4
4
  project: 'tsconfig.json',
5
5
  sourceType: 'module',
6
+ // ensure tsconfigRootDir is the project root for v8:
7
+ tsconfigRootDir: process.cwd(),
6
8
  },
7
9
  plugins: ['@typescript-eslint/eslint-plugin'],
8
10
  extends: [
@@ -14,8 +16,9 @@ module.exports = {
14
16
  './rules/variables.js',
15
17
  './rules/best-practices.js',
16
18
  './rules/imports.js',
17
- './rules/typescript.js',
18
19
  './rules/tests.js',
20
+ './rules/typescript.js',
21
+ './rules/nestjs.js',
19
22
  ],
20
23
  root: true,
21
24
  env: {
package/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  import jsLint from '@eslint/js'
2
2
  import tsLint from 'typescript-eslint'
3
3
 
4
+ // Utils
5
+ import { hasPackage, getFlat } from './lib/utils.js'
6
+
4
7
  // Importing all the rules from the rules directory
5
8
  import prettierConfig from './rules/prettier.js'
6
9
  import errorsConfig from './rules/errors.js'
@@ -13,19 +16,25 @@ import typescriptConfig from './rules/typescript.js'
13
16
  import testsConfig from './rules/tests.js'
14
17
  import nestjsConfig from './rules/nestjs.js'
15
18
 
19
+ const hasTypescript = hasPackage('typescript')
20
+ const hasNestJs = hasPackage('@nestjs/core')
21
+
22
+ const baseRecommended = [...tsLint.configs.recommended]
23
+ const recommendedTypeChecked = [
24
+ ...tsLint.configs.recommendedTypeChecked,
25
+ ...tsLint.configs.strictTypeChecked,
26
+ ...tsLint.configs.stylisticTypeChecked,
27
+ ]
28
+
16
29
  const ignoreConfig = {
17
30
  ignores: ['coverage', 'dist', '**/dist/', 'node_modules', '**/node_modules'],
18
31
  }
19
32
 
20
- // Helper to get the flat config if available, otherwise fallback
21
- const getFlat = (config) => {
22
- return config && config.flat ? (Array.isArray(config.flat) ? config.flat : [config.flat]) : []
23
- }
24
-
25
- export default [
33
+ export default tsLint.config(
26
34
  ignoreConfig,
27
- jsLint.configs.recommended,
28
- ...tsLint.configs.recommended,
35
+ ...(hasTypescript ? [] : [jsLint.configs.recommended]),
36
+ ...getFlat(typescriptConfig),
37
+ ...(hasTypescript ? (hasNestJs ? recommendedTypeChecked : baseRecommended) : []),
29
38
  ...getFlat(prettierConfig),
30
39
  ...getFlat(errorsConfig),
31
40
  ...getFlat(nodeConfig),
@@ -33,7 +42,6 @@ export default [
33
42
  ...getFlat(variablesConfig),
34
43
  ...getFlat(bestPracticesConfig),
35
44
  ...getFlat(importsConfig),
36
- ...getFlat(typescriptConfig),
37
45
  ...getFlat(testsConfig),
38
- ...getFlat(nestjsConfig),
39
- ]
46
+ ...getFlat(nestjsConfig)
47
+ )
package/lib/utils.js CHANGED
@@ -9,3 +9,6 @@ exports.hasPackage = (pkg) => {
9
9
  return false
10
10
  }
11
11
  }
12
+ exports.getFlat = (config) => {
13
+ return config && config.flat ? (Array.isArray(config.flat) ? config.flat : [config.flat]) : []
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@petbee/eslint-config",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
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": "a169e9be79636fe7e156170bce458162ac413405"
84
+ "gitHead": "7bd18dff6b637dc709f25a85e449dda98a4f91a9"
85
85
  }
package/rules/nestjs.js CHANGED
@@ -1,13 +1,57 @@
1
- const { hasPackage } = require('../lib/utils')
1
+ const { hasPackage, getFlat } = require('../lib/utils')
2
2
  const nestjsLint = require('@darraghor/eslint-plugin-nestjs-typed')
3
+ const tsConfig = require('./typescript.js') // <-- our patched TS config
3
4
 
4
5
  const hasNestJs = hasPackage('@nestjs/core')
5
6
 
7
+ // Grab TS-ESLint flat override
8
+ const tsFlat = getFlat(tsConfig)
9
+
10
+ const nestjsRules = {
11
+ '@typescript-eslint/interface-name-prefix': 'off',
12
+ '@typescript-eslint/explicit-function-return-type': 'off',
13
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
14
+ '@typescript-eslint/no-explicit-any': 'off',
15
+ '@typescript-eslint/no-extraneous-class': [
16
+ 'error',
17
+ {
18
+ allowWithDecorator: true,
19
+ allowStaticOnly: true,
20
+ allowEmpty: true,
21
+ allowConstructorOnly: false,
22
+ },
23
+ ],
24
+ 'no-redeclare': 'off',
25
+ }
26
+
27
+ // If NestJS is present, take its flatRecommended array and
28
+ // graft in parserOptions from tsFlat[0]:
29
+ const nestFlat = hasNestJs
30
+ ? [
31
+ ...nestjsLint.default.configs.flatRecommended.map((cfg) => ({
32
+ ...cfg,
33
+ languageOptions: {
34
+ ...tsFlat[0].languageOptions,
35
+ ...cfg.languageOptions,
36
+ // merge parserOptions so `project` stays intact
37
+ parserOptions: {
38
+ ...tsFlat[0].languageOptions.parserOptions,
39
+ ...cfg.languageOptions?.parserOptions,
40
+ },
41
+ },
42
+ })),
43
+ {
44
+ rules: nestjsRules,
45
+ },
46
+ ]
47
+ : []
48
+
6
49
  module.exports = hasNestJs
7
50
  ? {
51
+ extends: ['plugin:@darraghor/nestjs-typed/recommended'],
8
52
  plugins: [nestjsLint.classicPlugin],
53
+ rules: nestjsRules,
9
54
  }
10
55
  : {}
11
56
 
12
- // Flat config for ESLint v9 (no extends, plugins as object)
13
- module.exports.flat = hasNestJs ? nestjsLint.default.configs.flatRecommended : []
57
+ module.exports.flat = nestFlat
@@ -1,11 +1,15 @@
1
1
  const { hasPackage } = require('../lib/utils')
2
2
 
3
3
  const hasTypescript = hasPackage('typescript')
4
+ const hasNestJs = hasPackage('@nestjs/core')
4
5
 
5
- const tsConfig = [
6
+ const tsConfigOptions = [
6
7
  {
7
8
  files: ['*.ts', '*.tsx'],
8
- extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
9
+ extends: [
10
+ 'plugin:@typescript-eslint/eslint-recommended',
11
+ hasNestJs ? 'plugin:@typescript-eslint/recommended' : 'plugin:@typescript-eslint/recommended-type-checked',
12
+ ],
9
13
  plugins: ['@typescript-eslint'],
10
14
  parser: '@typescript-eslint/parser',
11
15
  parserOptions: {
@@ -19,6 +23,8 @@ const tsConfig = [
19
23
  // look in dirs like packages/package/*
20
24
  '*/*/tsconfig{.eslint.json,.json}',
21
25
  ],
26
+ projectService: true,
27
+ tsconfigRootDir: process.cwd(),
22
28
  projectFolderIgnoreList: [/node_modules/i],
23
29
  // We need this configuration to avoid performance issues in monorepos
24
30
  // https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-862414778
@@ -28,9 +34,6 @@ const tsConfig = [
28
34
  //! extensions of native eslint rules
29
35
  //! when modifying a rule here, make sure to modify the native one and vice-versa
30
36
 
31
- // Don't require a weird naming convention for interfaces
32
- '@typescript-eslint/interface-name-prefix': 'off',
33
-
34
37
  // Disallow declaration of variables already declared in the outer scope
35
38
  // https://eslint.org/docs/rules/no-shadow
36
39
  'no-shadow': 'off',
@@ -277,29 +280,31 @@ const tsConfig = [
277
280
  },
278
281
  ]
279
282
 
280
- module.exports = hasTypescript
281
- ? {
282
- overrides: tsConfig,
283
- }
284
- : {}
285
-
286
283
  // Flat config for ESLint v9 (no extends, plugins as object)
287
- module.exports.flat = hasTypescript
284
+ const flatConfig = hasTypescript
288
285
  ? [
289
286
  {
290
- files: tsConfig[0].files,
287
+ files: tsConfigOptions[0].files,
291
288
  languageOptions: {
292
289
  parser: require('@typescript-eslint/parser'),
293
- parserOptions: tsConfig[0].parserOptions,
290
+ parserOptions: {
291
+ ...tsConfigOptions[0].parserOptions,
292
+ tsconfigRootDir: process.cwd(),
293
+ },
294
294
  },
295
295
  plugins: {
296
296
  '@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
297
297
  },
298
- rules: tsConfig[0].rules,
298
+ rules: tsConfigOptions[0].rules,
299
299
  },
300
300
  {
301
- files: tsConfig[1].files,
302
- rules: tsConfig[1].rules,
301
+ files: tsConfigOptions[1].files,
302
+ rules: tsConfigOptions[1].rules,
303
303
  },
304
304
  ]
305
305
  : []
306
+
307
+ const config = hasTypescript ? { overrides: tsConfigOptions } : {}
308
+
309
+ module.exports = config
310
+ module.exports.flat = flatConfig