Browse Source

chore: migrate ESLint configuration to flat config without FlatCompat

Resolves #7906
- Replace FlatCompat blocks with native flat configs from @nx/eslint-plugin and typescript-eslint
- Remove @eslint/eslintrc and @eslint/js dependencies
- Add typescript-eslint for native flat config exports
pull/7925/head
Suraj 1 week ago
parent
commit
975e24a86c
  1. 310
      eslint.config.cjs
  2. 3
      package.json

310
eslint.config.cjs

@ -1,19 +1,14 @@
const { FlatCompat } = require('@eslint/eslintrc'); const nx = require('@nx/eslint-plugin');
const js = require('@eslint/js');
const nxEslintPlugin = require('@nx/eslint-plugin');
const storybook = require('eslint-plugin-storybook'); const storybook = require('eslint-plugin-storybook');
const tseslint = require('typescript-eslint');
const importPlugin = require('eslint-plugin-import');
const compat = new FlatCompat({ module.exports = tseslint.config(
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended
});
module.exports = [
{ {
ignores: ['**/dist'] ignores: ['**/dist']
}, },
...storybook.configs['flat/recommended'], ...storybook.configs['flat/recommended'],
{ plugins: { '@nx': nxEslintPlugin } }, { plugins: { '@nx': nx } },
{ {
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: { rules: {
@ -35,160 +30,149 @@ module.exports = [
'no-extra-semi': 'off' 'no-extra-semi': 'off'
} }
}, },
...compat ...nx.configs['flat/typescript'].map((config) => ({
.config({ ...config,
extends: ['plugin:@nx/typescript'] files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
}) })),
.map((config) => ({ ...nx.configs['flat/javascript'].map((config) => ({
...config, ...config,
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'], files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'],
rules: { })),
...config.rules {
} files: ['**/*.ts'],
})), extends: [
...compat ...tseslint.configs.recommendedTypeChecked,
.config({ ...tseslint.configs.stylisticTypeChecked
extends: ['plugin:@nx/javascript'] ],
}) plugins: {
.map((config) => ({ import: importPlugin
...config, },
files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'], languageOptions: {
rules: { parserOptions: {
...config.rules projectService: true,
tsconfigRootDir: __dirname
} }
})), },
...compat rules: {
.config({ '@typescript-eslint/consistent-indexed-object-style': 'off',
plugins: ['eslint-plugin-import', '@typescript-eslint'], '@typescript-eslint/dot-notation': 'off',
extends: [ '@typescript-eslint/explicit-member-accessibility': [
'plugin:@typescript-eslint/recommended-type-checked', 'off',
'plugin:@typescript-eslint/stylistic-type-checked' {
] accessibility: 'explicit'
}) }
.map((config) => ({ ],
...config, '@typescript-eslint/member-ordering': 'warn',
files: ['**/*.ts'], '@typescript-eslint/naming-convention': [
rules: { 'off',
...config.rules, {
'@typescript-eslint/consistent-indexed-object-style': 'off', selector: 'default',
'@typescript-eslint/dot-notation': 'off', format: ['camelCase'],
'@typescript-eslint/explicit-member-accessibility': [ leadingUnderscore: 'allow',
'off', trailingUnderscore: 'allow'
{ },
accessibility: 'explicit' {
} selector: ['variable', 'classProperty', 'typeProperty'],
], format: ['camelCase', 'UPPER_CASE'],
'@typescript-eslint/member-ordering': 'warn', leadingUnderscore: 'allow',
'@typescript-eslint/naming-convention': [ trailingUnderscore: 'allow'
'off', },
{ {
selector: 'default', selector: 'objectLiteralProperty',
format: ['camelCase'], format: null
leadingUnderscore: 'allow', },
trailingUnderscore: 'allow' {
}, selector: 'enumMember',
{ format: ['camelCase', 'UPPER_CASE', 'PascalCase']
selector: ['variable', 'classProperty', 'typeProperty'], },
format: ['camelCase', 'UPPER_CASE'], {
leadingUnderscore: 'allow', selector: 'typeLike',
trailingUnderscore: 'allow' format: ['PascalCase']
}, }
{ ],
selector: 'objectLiteralProperty', '@typescript-eslint/no-empty-interface': 'warn',
format: null '@typescript-eslint/no-inferrable-types': [
}, 'warn',
{ {
selector: 'enumMember', ignoreParameters: true
format: ['camelCase', 'UPPER_CASE', 'PascalCase'] }
}, ],
{ '@typescript-eslint/no-non-null-assertion': 'warn',
selector: 'typeLike', '@typescript-eslint/no-shadow': [
format: ['PascalCase'] 'warn',
} {
], hoist: 'all'
'@typescript-eslint/no-empty-interface': 'warn', }
'@typescript-eslint/no-inferrable-types': [ ],
'warn', '@typescript-eslint/unified-signatures': 'error',
{ '@typescript-eslint/no-loss-of-precision': 'warn',
ignoreParameters: true '@typescript-eslint/no-var-requires': 'warn',
} 'arrow-body-style': 'off',
], 'constructor-super': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn', eqeqeq: ['error', 'smart'],
'@typescript-eslint/no-shadow': [ 'guard-for-in': 'warn',
'warn', 'id-blacklist': 'off',
{ 'id-match': 'off',
hoist: 'all' 'import/no-deprecated': 'warn',
} 'no-bitwise': 'error',
], 'no-caller': 'error',
'@typescript-eslint/unified-signatures': 'error', 'no-debugger': 'error',
'@typescript-eslint/no-loss-of-precision': 'warn', 'no-empty': 'off',
'@typescript-eslint/no-var-requires': 'warn', 'no-eval': 'error',
'arrow-body-style': 'off', 'no-fallthrough': 'error',
'constructor-super': 'error', 'no-new-wrappers': 'error',
eqeqeq: ['error', 'smart'], 'no-restricted-imports': ['error', 'rxjs/Rx'],
'guard-for-in': 'warn', 'no-undef-init': 'error',
'id-blacklist': 'off', 'no-underscore-dangle': 'off',
'id-match': 'off', 'no-var': 'error',
'import/no-deprecated': 'warn', radix: 'error',
'no-bitwise': 'error', 'no-unsafe-optional-chaining': 'warn',
'no-caller': 'error', 'no-extra-boolean-cast': 'warn',
'no-debugger': 'error', 'no-empty-pattern': 'warn',
'no-empty': 'off', 'no-useless-catch': 'warn',
'no-eval': 'error', 'no-unsafe-finally': 'warn',
'no-fallthrough': 'error', 'no-prototype-builtins': 'warn',
'no-new-wrappers': 'error', 'no-async-promise-executor': 'warn',
'no-restricted-imports': ['error', 'rxjs/Rx'], 'no-constant-condition': 'warn',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-var': 'error',
radix: 'error',
'no-unsafe-optional-chaining': 'warn',
'no-extra-boolean-cast': 'warn',
'no-empty-pattern': 'warn',
'no-useless-catch': 'warn',
'no-unsafe-finally': 'warn',
'no-prototype-builtins': 'warn',
'no-async-promise-executor': 'warn',
'no-constant-condition': 'warn',
// The following rules are part of eslint:recommended // The following rules are part of eslint:recommended
// and can be remove once solved // and can be remove once solved
'no-loss-of-precision': 'warn', 'no-loss-of-precision': 'warn',
// The following rules are part of @typescript-eslint/recommended-type-checked // The following rules are part of @typescript-eslint/recommended-type-checked
// and can be remove once solved // and can be remove once solved
'@typescript-eslint/await-thenable': 'warn', '@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn', '@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-base-to-string': 'warn', '@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn', '@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-floating-promises': 'warn', '@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-misused-promises': 'warn', '@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn', '@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-require-imports': 'warn', '@typescript-eslint/no-require-imports': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn', '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn', '@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn', '@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-enum-comparison': 'warn', '@typescript-eslint/no-unsafe-enum-comparison': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn', '@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn', '@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn', '@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unused-vars': [ '@typescript-eslint/no-unused-vars': [
'error', 'error',
{ {
caughtErrors: 'none' caughtErrors: 'none'
} }
], ],
'@typescript-eslint/no-wrapper-object-types': 'warn', '@typescript-eslint/no-wrapper-object-types': 'warn',
'@typescript-eslint/only-throw-error': 'warn', '@typescript-eslint/only-throw-error': 'warn',
'@typescript-eslint/prefer-promise-reject-errors': 'warn', '@typescript-eslint/prefer-promise-reject-errors': 'warn',
'@typescript-eslint/require-await': 'warn', '@typescript-eslint/require-await': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn', '@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/unbound-method': 'warn', '@typescript-eslint/unbound-method': 'warn',
// The following rules are part of @typescript-eslint/stylistic-type-checked // The following rules are part of @typescript-eslint/stylistic-type-checked
// and can be remove once solved // and can be remove once solved
'@typescript-eslint/prefer-nullish-coalescing': 'warn' // TODO: Requires strictNullChecks: true '@typescript-eslint/prefer-nullish-coalescing': 'warn' // TODO: Requires strictNullChecks: true
} }
})) }
]; );

3
package.json

@ -166,8 +166,6 @@
"@angular/language-service": "22.1.2", "@angular/language-service": "22.1.2",
"@angular/localize": "22.1.2", "@angular/localize": "22.1.2",
"@angular/pwa": "22.1.4", "@angular/pwa": "22.1.4",
"@eslint/eslintrc": "3.3.1",
"@eslint/js": "9.35.0",
"@nestjs/schematics": "11.1.0", "@nestjs/schematics": "11.1.0",
"@nestjs/testing": "11.2.3", "@nestjs/testing": "11.2.3",
"@nx/angular": "23.1.1", "@nx/angular": "23.1.1",
@ -221,6 +219,7 @@
"ts-node": "10.9.2", "ts-node": "10.9.2",
"tslib": "2.8.1", "tslib": "2.8.1",
"typescript": "6.0.3", "typescript": "6.0.3",
"typescript-eslint": "8.67.0",
"webpack-cli": "7.1.0" "webpack-cli": "7.1.0"
}, },
"engines": { "engines": {

Loading…
Cancel
Save