Skip to content

Commit

Permalink
fix(linter): do not expect project to have flat eslint config (#20018)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Nov 7, 2023
1 parent f42d47a commit d4f4d73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
22 changes: 20 additions & 2 deletions e2e/eslint/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
newProject,
readFile,
readJson,
renameFile,
runCLI,
runCreateWorkspace,
setMaxWorkers,
Expand Down Expand Up @@ -542,6 +543,7 @@ describe('Linter', () => {
it('should convert integrated to flat config', () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
const mylib2 = uniq('mylib2');

runCreateWorkspace(myapp, {
preset: 'react-monorepo',
Expand All @@ -554,18 +556,34 @@ describe('Linter', () => {
runCLI(
`generate @nx/js:lib ${mylib} --directory libs/${mylib} --projectNameAndRootFormat as-provided`
);
runCLI(
`generate @nx/js:lib ${mylib2} --directory libs/${mylib2} --projectNameAndRootFormat as-provided`
);

// migrate to flat structure
runCLI(`generate @nx/eslint:convert-to-flat-config`);
checkFilesExist(
'eslint.config.js',
`apps/${myapp}/eslint.config.js`,
`libs/${mylib}/eslint.config.js`
`libs/${mylib}/eslint.config.js`,
`libs/${mylib2}/eslint.config.js`
);
checkFilesDoNotExist(
'.eslintrc.json',
`apps/${myapp}/.eslintrc.json`,
`libs/${mylib}/.eslintrc.json`
`libs/${mylib}/.eslintrc.json`,
`libs/${mylib2}/.eslintrc.json`
);

// move eslint.config one step up
// to test the absence of the flat eslint config in the project root folder
renameFile(`libs/${mylib2}/eslint.config.js`, `libs/eslint.config.js`);
updateFile(
`libs/eslint.config.js`,
readFile(`libs/eslint.config.js`).replace(
`../../eslint.config.js`,
`../eslint.config.js`
)
);

const outFlat = runCLI(`affected -t lint`, {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint/src/executors/lint/lint.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
await lintExecutor(createValidRunBuilderOptions(), mockContext);
expect(mockResolveAndInstantiateESLint).toHaveBeenCalledWith(
'apps/proj/eslint.config.js',
undefined,
{
lintFilePatterns: [],
eslintConfig: null,
Expand Down
6 changes: 0 additions & 6 deletions packages/eslint/src/executors/lint/lint.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ export default async function run(
joinPathFragments(workspaceRoot, 'eslint.config.js')
);

if (!eslintConfigPath && hasFlatConfig) {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
eslintConfigPath = joinPathFragments(projectRoot, 'eslint.config.js');
}

const { eslint, ESLint } = await resolveAndInstantiateESLint(
eslintConfigPath,
normalizedOptions,
Expand Down

0 comments on commit d4f4d73

Please sign in to comment.