From 29ad261d78ad6e0354c36be7a49fb3cd04aae614 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 30 Oct 2024 10:39:58 +0000 Subject: [PATCH] fix(linter): ensure .cjs config file is handled correctly for generators #28214 (#28672) ## Current Behavior When the workspace has `eslint.config.cjs` at the root, generation of new lint projects currently does not check for it correctly ## Expected Behavior Ensure utils continue to work as expected when `eslint.config.cjs` is detected at the workspaceRoot ## Related Issue(s) Fixes #28214 --- packages/eslint/src/generators/lint-project/lint-project.ts | 3 ++- packages/eslint/src/generators/utils/eslint-file.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/eslint/src/generators/lint-project/lint-project.ts b/packages/eslint/src/generators/lint-project/lint-project.ts index 6ff40663bb8d8..545b0dcbcc47a 100644 --- a/packages/eslint/src/generators/lint-project/lint-project.ts +++ b/packages/eslint/src/generators/lint-project/lint-project.ts @@ -273,7 +273,8 @@ function createEsLintConfiguration( }); const nodeList = createNodeList(importMap, nodes); const content = stringifyNodeList(nodeList); - tree.write(join(projectConfig.root, 'eslint.config.js'), content); + const ext = extendedRootConfig?.endsWith('.cjs') ? '.cjs' : '.js'; + tree.write(join(projectConfig.root, `eslint.config${ext}`), content); } else { writeJson(tree, join(projectConfig.root, `.eslintrc.json`), { extends: extendedRootConfig ? [pathToRootConfig] : undefined, diff --git a/packages/eslint/src/generators/utils/eslint-file.ts b/packages/eslint/src/generators/utils/eslint-file.ts index 2db5e49f3f469..ee7e052ed253f 100644 --- a/packages/eslint/src/generators/utils/eslint-file.ts +++ b/packages/eslint/src/generators/utils/eslint-file.ts @@ -64,7 +64,11 @@ export function isEslintConfigSupported(tree: Tree, projectRoot = ''): boolean { if (!eslintFile) { return false; } - return eslintFile.endsWith('.json') || eslintFile.endsWith('.config.js'); + return ( + eslintFile.endsWith('.json') || + eslintFile.endsWith('.config.js') || + eslintFile.endsWith('.config.cjs') + ); } export function updateRelativePathsInConfig(