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 { Linter } from '../utils/linter';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
import { lintProjectGenerator } from './lint-project';
|
import { lintProjectGenerator } from './lint-project';
|
||||||
|
import { eslintVersion } from '../../utils/versions';
|
||||||
|
|
||||||
describe('@nx/eslint:lint-project', () => {
|
describe('@nx/eslint:lint-project', () => {
|
||||||
let tree: Tree;
|
let tree: Tree;
|
||||||
@ -221,4 +222,31 @@ describe('@nx/eslint:lint-project', () => {
|
|||||||
analyzeSourceFiles: true,
|
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(
|
createEsLintConfiguration(
|
||||||
tree,
|
tree,
|
||||||
projectConfig,
|
projectConfig,
|
||||||
options.setParserOptionsProject
|
options.setParserOptionsProject,
|
||||||
|
options.rootProject
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,11 +143,13 @@ export async function lintProjectGenerator(
|
|||||||
function createEsLintConfiguration(
|
function createEsLintConfiguration(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
projectConfig: ProjectConfiguration,
|
projectConfig: ProjectConfiguration,
|
||||||
setParserOptionsProject: boolean
|
setParserOptionsProject: boolean,
|
||||||
|
rootProject: boolean
|
||||||
) {
|
) {
|
||||||
const eslintConfig = findEslintFile(tree);
|
// we are only extending root for non-standalone projects or their complementary e2e apps
|
||||||
const pathToRootConfig = eslintConfig
|
const extendedRootConfig = rootProject ? undefined : findEslintFile(tree);
|
||||||
? `${offsetFromRoot(projectConfig.root)}${eslintConfig}`
|
const pathToRootConfig = extendedRootConfig
|
||||||
|
? `${offsetFromRoot(projectConfig.root)}${extendedRootConfig}`
|
||||||
: undefined;
|
: undefined;
|
||||||
const addDependencyChecks = isBuildableLibraryProject(projectConfig);
|
const addDependencyChecks = isBuildableLibraryProject(projectConfig);
|
||||||
|
|
||||||
@ -201,7 +204,7 @@ function createEsLintConfiguration(
|
|||||||
const isCompatNeeded = addDependencyChecks;
|
const isCompatNeeded = addDependencyChecks;
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
const importMap = new Map();
|
const importMap = new Map();
|
||||||
if (eslintConfig) {
|
if (extendedRootConfig) {
|
||||||
importMap.set(pathToRootConfig, 'baseConfig');
|
importMap.set(pathToRootConfig, 'baseConfig');
|
||||||
nodes.push(generateSpreadElement('baseConfig'));
|
nodes.push(generateSpreadElement('baseConfig'));
|
||||||
}
|
}
|
||||||
@ -213,7 +216,7 @@ function createEsLintConfiguration(
|
|||||||
tree.write(join(projectConfig.root, 'eslint.config.js'), content);
|
tree.write(join(projectConfig.root, 'eslint.config.js'), content);
|
||||||
} else {
|
} else {
|
||||||
writeJson(tree, join(projectConfig.root, `.eslintrc.json`), {
|
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.
|
// Include project files to be linted since the global one excludes all files.
|
||||||
ignorePatterns: ['!**/*'],
|
ignorePatterns: ['!**/*'],
|
||||||
overrides,
|
overrides,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user