fix(linter): standalone e2e should not extend root config (#20379)
This commit is contained in:
parent
c8e753ad8a
commit
0f6c1168db
@ -9,6 +9,7 @@ import {
|
||||
import { Linter } from '../utils/linter';
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import { lintProjectGenerator } from './lint-project';
|
||||
import { eslintVersion } from '../../utils/versions';
|
||||
|
||||
describe('@nx/eslint:lint-project', () => {
|
||||
let tree: Tree;
|
||||
@ -221,4 +222,31 @@ describe('@nx/eslint:lint-project', () => {
|
||||
analyzeSourceFiles: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should extend root config', async () => {
|
||||
await lintProjectGenerator(tree, {
|
||||
...defaultOptions,
|
||||
linter: Linter.EsLint,
|
||||
eslintFilePatterns: ['libs/test-lib/**/*.ts'],
|
||||
project: 'test-lib',
|
||||
setParserOptionsProject: false,
|
||||
});
|
||||
|
||||
const eslintConfig = readJson(tree, 'libs/test-lib/.eslintrc.json');
|
||||
expect(eslintConfig.extends).toBeDefined();
|
||||
});
|
||||
|
||||
it('should not extend root config if rootProject is set', async () => {
|
||||
await lintProjectGenerator(tree, {
|
||||
...defaultOptions,
|
||||
linter: Linter.EsLint,
|
||||
eslintFilePatterns: ['libs/test-lib/**/*.ts'],
|
||||
project: 'test-lib',
|
||||
setParserOptionsProject: false,
|
||||
rootProject: true,
|
||||
});
|
||||
|
||||
const eslintConfig = readJson(tree, 'libs/test-lib/.eslintrc.json');
|
||||
expect(eslintConfig.extends).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -113,7 +113,8 @@ export async function lintProjectGenerator(
|
||||
createEsLintConfiguration(
|
||||
tree,
|
||||
projectConfig,
|
||||
options.setParserOptionsProject
|
||||
options.setParserOptionsProject,
|
||||
options.rootProject
|
||||
);
|
||||
}
|
||||
|
||||
@ -142,11 +143,13 @@ export async function lintProjectGenerator(
|
||||
function createEsLintConfiguration(
|
||||
tree: Tree,
|
||||
projectConfig: ProjectConfiguration,
|
||||
setParserOptionsProject: boolean
|
||||
setParserOptionsProject: boolean,
|
||||
rootProject: boolean
|
||||
) {
|
||||
const eslintConfig = findEslintFile(tree);
|
||||
const pathToRootConfig = eslintConfig
|
||||
? `${offsetFromRoot(projectConfig.root)}${eslintConfig}`
|
||||
// we are only extending root for non-standalone projects or their complementary e2e apps
|
||||
const extendedRootConfig = rootProject ? undefined : findEslintFile(tree);
|
||||
const pathToRootConfig = extendedRootConfig
|
||||
? `${offsetFromRoot(projectConfig.root)}${extendedRootConfig}`
|
||||
: undefined;
|
||||
const addDependencyChecks = isBuildableLibraryProject(projectConfig);
|
||||
|
||||
@ -201,7 +204,7 @@ function createEsLintConfiguration(
|
||||
const isCompatNeeded = addDependencyChecks;
|
||||
const nodes = [];
|
||||
const importMap = new Map();
|
||||
if (eslintConfig) {
|
||||
if (extendedRootConfig) {
|
||||
importMap.set(pathToRootConfig, 'baseConfig');
|
||||
nodes.push(generateSpreadElement('baseConfig'));
|
||||
}
|
||||
@ -213,7 +216,7 @@ function createEsLintConfiguration(
|
||||
tree.write(join(projectConfig.root, 'eslint.config.js'), content);
|
||||
} else {
|
||||
writeJson(tree, join(projectConfig.root, `.eslintrc.json`), {
|
||||
extends: eslintConfig ? [pathToRootConfig] : undefined,
|
||||
extends: extendedRootConfig ? [pathToRootConfig] : undefined,
|
||||
// Include project files to be linted since the global one excludes all files.
|
||||
ignorePatterns: ['!**/*'],
|
||||
overrides,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user