Skip to content

Commit d8d6d13

Browse files
authored
fix(linter): ensure .cjs config file is handled correctly for generators #28214 (#28672)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> When the workspace has `eslint.config.cjs` at the root, generation of new lint projects currently does not check for it correctly ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Ensure utils continue to work as expected when `eslint.config.cjs` is detected at the workspaceRoot ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #28214
1 parent 62f58eb commit d8d6d13

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/eslint/src/generators/lint-project/lint-project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ function createEsLintConfiguration(
273273
});
274274
const nodeList = createNodeList(importMap, nodes);
275275
const content = stringifyNodeList(nodeList);
276-
tree.write(join(projectConfig.root, 'eslint.config.js'), content);
276+
const ext = extendedRootConfig?.endsWith('.cjs') ? '.cjs' : '.js';
277+
tree.write(join(projectConfig.root, `eslint.config${ext}`), content);
277278
} else {
278279
writeJson(tree, join(projectConfig.root, `.eslintrc.json`), {
279280
extends: extendedRootConfig ? [pathToRootConfig] : undefined,

packages/eslint/src/generators/utils/eslint-file.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ export function isEslintConfigSupported(tree: Tree, projectRoot = ''): boolean {
6464
if (!eslintFile) {
6565
return false;
6666
}
67-
return eslintFile.endsWith('.json') || eslintFile.endsWith('.config.js');
67+
return (
68+
eslintFile.endsWith('.json') ||
69+
eslintFile.endsWith('.config.js') ||
70+
eslintFile.endsWith('.config.cjs')
71+
);
6872
}
6973

7074
export function updateRelativePathsInConfig(

0 commit comments

Comments
 (0)