Skip to content

Commit 68eeb2e

Browse files
JamesHenryleosvelperezjaysoo
authored
feat(linter): create new workspaces with ESLint v9 and typescript-eslint v8 (#27404)
Closes #27451 --------- Co-authored-by: Leosvel Pérez Espinosa <[email protected]> Co-authored-by: Jack Hsu <[email protected]>
1 parent 2e0f374 commit 68eeb2e

File tree

112 files changed

+3912
-1524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3912
-1524
lines changed

e2e/angular/src/misc.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Move Angular Project', () => {
4141
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.app.json`);
4242
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.json`);
4343
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.spec.json`);
44-
expect(moveOutput).toContain(`CREATE ${newPath}/.eslintrc.json`);
44+
expect(moveOutput).toContain(`CREATE ${newPath}/eslint.config.js`);
4545
expect(moveOutput).toContain(`CREATE ${newPath}/public/favicon.ico`);
4646
expect(moveOutput).toContain(`CREATE ${newPath}/src/index.html`);
4747
expect(moveOutput).toContain(`CREATE ${newPath}/src/main.ts`);

e2e/angular/src/projects.test.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ describe('Angular Projects', () => {
127127

128128
// check e2e tests
129129
if (runE2ETests('playwright')) {
130-
const e2eResults = runCLI(`e2e ${app1}-e2e`);
131-
expect(e2eResults).toContain('Successfully ran target e2e for project');
130+
expect(() => runCLI(`e2e ${app1}-e2e`)).not.toThrow();
132131
expect(await killPort(4200)).toBeTruthy();
133132
}
134133

@@ -160,10 +159,7 @@ describe('Angular Projects', () => {
160159
);
161160

162161
if (runE2ETests('playwright')) {
163-
const e2eResults = runCLI(`e2e ${app}-e2e`);
164-
expect(e2eResults).toContain(
165-
`Successfully ran target e2e for project ${app}-e2e`
166-
);
162+
expect(() => runCLI(`e2e ${app}-e2e`)).not.toThrow();
167163
expect(await killPort(4200)).toBeTruthy();
168164
}
169165
}, 1000000);
@@ -495,7 +491,7 @@ describe('Angular Projects', () => {
495491
updateFile(`${lib}/src/lib/${lib}.module.ts`, moduleContent);
496492

497493
// ACT
498-
const buildOutput = runCLI(`build ${lib}`);
494+
const buildOutput = runCLI(`build ${lib}`, { env: { CI: 'false' } });
499495

500496
// ASSERT
501497
expect(buildOutput).toContain(`Building entry point '@${proj}/${lib}'`);
@@ -516,14 +512,9 @@ describe('Angular Projects', () => {
516512
// check files are generated with the layout directory ("apps/")
517513
checkFilesExist(`apps/${appName}/src/app/app.module.ts`);
518514
// check build works
519-
expect(runCLI(`build ${appName}`)).toContain(
520-
`Successfully ran target build for project ${appName}`
521-
);
515+
expect(() => runCLI(`build ${appName}`)).not.toThrow();
522516
// check tests pass
523-
const appTestResult = runCLI(`test ${appName}`);
524-
expect(appTestResult).toContain(
525-
`Successfully ran target test for project ${appName}`
526-
);
517+
expect(() => runCLI(`test ${appName}`)).not.toThrow();
527518

528519
runCLI(
529520
`generate @nx/angular:lib ${libName} --standalone --buildable --project-name-and-root-format=derived`
@@ -535,14 +526,9 @@ describe('Angular Projects', () => {
535526
`libs/${libName}/src/lib/${libName}/${libName}.component.ts`
536527
);
537528
// check build works
538-
expect(runCLI(`build ${libName}`)).toContain(
539-
`Successfully ran target build for project ${libName}`
540-
);
529+
expect(() => runCLI(`build ${libName}`)).not.toThrow();
541530
// check tests pass
542-
const libTestResult = runCLI(`test ${libName}`);
543-
expect(libTestResult).toContain(
544-
`Successfully ran target test for project ${libName}`
545-
);
531+
expect(() => runCLI(`test ${libName}`)).not.toThrow();
546532
}, 500_000);
547533

548534
it('should support generating libraries with a scoped name when --project-name-and-root-format=as-provided', () => {
@@ -568,14 +554,9 @@ describe('Angular Projects', () => {
568554
}.component.ts`
569555
);
570556
// check build works
571-
expect(runCLI(`build ${libName}`)).toContain(
572-
`Successfully ran target build for project ${libName}`
573-
);
557+
expect(() => runCLI(`build ${libName}`)).not.toThrow();
574558
// check tests pass
575-
const libTestResult = runCLI(`test ${libName}`);
576-
expect(libTestResult).toContain(
577-
`Successfully ran target test for project ${libName}`
578-
);
559+
expect(() => runCLI(`test ${libName}`)).not.toThrow();
579560
}, 500_000);
580561

581562
it('should support generating applications with SSR and converting targets with webpack-based executors to use the application executor', async () => {

e2e/esbuild/src/esbuild.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ describe('EsBuild Plugin', () => {
162162
expect(
163163
readJson(`dist/libs/${parentLib}/package.json`).dependencies
164164
).toEqual({
165+
'jsonc-eslint-parser': expect.any(String),
165166
// Don't care about the versions, just that they exist
166167
rambda: expect.any(String),
167168
lodash: expect.any(String),

e2e/eslint/src/linter-legacy.test.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ import {
1414
} from '@nx/e2e/utils';
1515

1616
describe('Linter (legacy)', () => {
17-
describe('Integrated', () => {
17+
describe('Integrated (eslintrc config)', () => {
18+
let originalEslintUseFlatConfigVal: string | undefined;
1819
const myapp = uniq('myapp');
1920
const mylib = uniq('mylib');
2021

21-
let projScope;
22-
2322
beforeAll(() => {
24-
projScope = newProject({
23+
// Opt into legacy .eslintrc config format for these tests
24+
originalEslintUseFlatConfigVal = process.env.ESLINT_USE_FLAT_CONFIG;
25+
process.env.ESLINT_USE_FLAT_CONFIG = 'false';
26+
27+
newProject({
2528
packages: ['@nx/react', '@nx/js', '@nx/eslint'],
2629
});
2730
runCLI(`generate @nx/react:app ${myapp} --tags=validtag`, {
@@ -31,7 +34,10 @@ describe('Linter (legacy)', () => {
3134
env: { NX_ADD_PLUGINS: 'false' },
3235
});
3336
});
34-
afterAll(() => cleanupProject());
37+
afterAll(() => {
38+
process.env.ESLINT_USE_FLAT_CONFIG = originalEslintUseFlatConfigVal;
39+
cleanupProject();
40+
});
3541

3642
describe('linting errors', () => {
3743
let defaultEslintrc;
@@ -58,8 +64,7 @@ describe('Linter (legacy)', () => {
5864
updateFile('.eslintrc.json', JSON.stringify(eslintrc, null, 2));
5965

6066
// 1. linting should error when rules are not followed
61-
let out = runCLI(`lint ${myapp}`, { silenceError: true });
62-
expect(out).toContain('Unexpected console statement');
67+
expect(() => runCLI(`lint ${myapp}`)).toThrow();
6368

6469
// 2. linting should not error when rules are not followed and the force flag is specified
6570
expect(() => runCLI(`lint ${myapp} --force`)).not.toThrow();
@@ -72,8 +77,9 @@ describe('Linter (legacy)', () => {
7277
updateFile('.eslintrc.json', JSON.stringify(eslintrc, null, 2));
7378

7479
// 3. linting should not error when all rules are followed
75-
out = runCLI(`lint ${myapp}`, { silenceError: true });
76-
expect(out).toContain('All files pass linting');
80+
expect(() =>
81+
runCLI(`lint ${myapp}`, { silenceError: true })
82+
).not.toThrow();
7783
}, 1000000);
7884

7985
it('should print the effective configuration for a file specified using --print-config', () => {
@@ -86,16 +92,27 @@ describe('Linter (legacy)', () => {
8692
});
8793
updateFile('.eslintrc.json', JSON.stringify(eslint, null, 2));
8894
const out = runCLI(`lint ${myapp} --print-config src/index.ts`, {
95+
env: { CI: 'false' }, // We don't want to show the summary table from cloud runner
8996
silenceError: true,
9097
});
9198
expect(out).toContain('"specific-rule": [');
9299
}, 1000000);
93100
});
94101
});
95102

96-
describe('Flat config', () => {
103+
describe('eslintrc convert to flat config', () => {
104+
let originalEslintUseFlatConfigVal: string | undefined;
97105
const packageManager = getSelectedPackageManager() || 'pnpm';
98106

107+
beforeAll(() => {
108+
// Opt into legacy .eslintrc config format for these tests
109+
originalEslintUseFlatConfigVal = process.env.ESLINT_USE_FLAT_CONFIG;
110+
process.env.ESLINT_USE_FLAT_CONFIG = 'false';
111+
});
112+
afterAll(() => {
113+
process.env.ESLINT_USE_FLAT_CONFIG = originalEslintUseFlatConfigVal;
114+
});
115+
99116
beforeEach(() => {
100117
process.env.NX_ADD_PLUGINS = 'false';
101118
});
@@ -162,7 +179,9 @@ describe('Linter (legacy)', () => {
162179
const outFlat = runCLI(`affected -t lint`, {
163180
silenceError: true,
164181
});
165-
expect(outFlat).toContain('ran target lint');
182+
expect(outFlat).toContain(`${myapp}:lint`);
183+
expect(outFlat).toContain(`${mylib}:lint`);
184+
expect(outFlat).toContain(`${mylib2}:lint`);
166185
}, 1000000);
167186

168187
it('should convert standalone to flat config', () => {
@@ -199,7 +218,8 @@ describe('Linter (legacy)', () => {
199218
const outFlat = runCLI(`affected -t lint`, {
200219
silenceError: true,
201220
});
202-
expect(outFlat).toContain('ran target lint');
221+
expect(outFlat).toContain(`${myapp}:lint`);
222+
expect(outFlat).toContain(`${mylib}:lint`);
203223
}, 1000000);
204224
});
205225
});

0 commit comments

Comments
 (0)