diff --git a/packages/eslint/src/generators/convert-to-flat-config/__snapshots__/generator.spec.ts.snap b/packages/eslint/src/generators/convert-to-flat-config/__snapshots__/generator.spec.ts.snap index 307e894f960c1..491e51e051057 100644 --- a/packages/eslint/src/generators/convert-to-flat-config/__snapshots__/generator.spec.ts.snap +++ b/packages/eslint/src/generators/convert-to-flat-config/__snapshots__/generator.spec.ts.snap @@ -35,12 +35,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -85,12 +89,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -130,12 +138,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -174,12 +186,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), { ignores: ['ignore/me'] }, ]; @@ -221,12 +237,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -275,12 +295,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -320,12 +344,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -364,12 +392,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -429,12 +461,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -494,12 +530,16 @@ module.exports = [ ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " diff --git a/packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.spec.ts b/packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.spec.ts index e1e09c1c79c03..a6ba8c6fa8b58 100644 --- a/packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.spec.ts +++ b/packages/eslint/src/generators/convert-to-flat-config/converters/json-converter.spec.ts @@ -102,7 +102,9 @@ describe('convertEslintJsonToFlatConfig', () => { "**/*.ts", "**/*.tsx" ], - rules: {} + rules: { + ...config.rules + } })), ...compat.config({ env: { jest: true } }).map(config => ({ ...config, @@ -112,7 +114,9 @@ describe('convertEslintJsonToFlatConfig', () => { "**/*.spec.js", "**/*.spec.jsx" ], - rules: {} + rules: { + ...config.rules + } })), { ignores: ["src/ignore/to/keep.ts"] }, { ignores: ["something/else"] } @@ -221,7 +225,10 @@ describe('convertEslintJsonToFlatConfig', () => { ...compat.config({ parser: "jsonc-eslint-parser" }).map(config => ({ ...config, files: ["**/*.json"], - rules: { "@nx/dependency-checks": "error" } + rules: { + ...config.rules, + "@nx/dependency-checks": "error" + } })), { ignores: [".next/**/*"] }, { ignores: ["something/else"] } diff --git a/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts b/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts index 17d3fa59747d5..9278592ef3e8c 100644 --- a/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts +++ b/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts @@ -179,12 +179,16 @@ describe('convert-to-flat-config generator', () => { ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " @@ -424,12 +428,16 @@ describe('convert-to-flat-config generator', () => { ...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({ ...config, files: ['**/*.ts', '**/*.tsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({ ...config, files: ['**/*.js', '**/*.jsx'], - rules: {}, + rules: { + ...config.rules, + }, })), ]; " diff --git a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts index 4e779e29a140e..4a78b6cebe9b2 100644 --- a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts +++ b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts @@ -773,7 +773,26 @@ export function generateFlatOverride( ]; addTSObjectProperty(objectLiteralElements, 'files', files); addTSObjectProperty(objectLiteralElements, 'excludedFiles', excludedFiles); - addTSObjectProperty(objectLiteralElements, 'rules', rules); + + // Apply rules (and spread ...config.rules into it as the first assignment) + addTSObjectProperty(objectLiteralElements, 'rules', rules || {}); + const rulesObjectAST = objectLiteralElements.pop() as ts.PropertyAssignment; + const rulesObjectInitializer = + rulesObjectAST.initializer as ts.ObjectLiteralExpression; + const spreadAssignment = ts.factory.createSpreadAssignment( + ts.factory.createIdentifier('config.rules') + ); + const updatedRulesProperties = [ + spreadAssignment, + ...rulesObjectInitializer.properties, + ]; + objectLiteralElements.push( + ts.factory.createPropertyAssignment( + 'rules', + ts.factory.createObjectLiteralExpression(updatedRulesProperties, true) + ) + ); + if (parserOptions) { addTSObjectProperty(objectLiteralElements, 'languageSettings', { parserOptions, diff --git a/packages/next/src/generators/application/lib/add-linting.spec.ts b/packages/next/src/generators/application/lib/add-linting.spec.ts index bbea7dd92c49b..ea210a80cbfc5 100644 --- a/packages/next/src/generators/application/lib/add-linting.spec.ts +++ b/packages/next/src/generators/application/lib/add-linting.spec.ts @@ -164,7 +164,10 @@ describe('updateEslint', () => { "**/*.spec.tsx", "**/*.spec.js", "**/*.spec.jsx" - ] + ], + rules: { + ...config.rules + } })), { ignores: [".next/**/*"] } ];