Skip to content

Commit

Permalink
feat(linter): create new workspaces with ESLint v9 and typescript-esl…
Browse files Browse the repository at this point in the history
…int v8 (#27404)

Closes #27451

---------

Co-authored-by: Leosvel Pérez Espinosa <[email protected]>
Co-authored-by: Jack Hsu <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent 2e0f374 commit 68eeb2e
Show file tree
Hide file tree
Showing 112 changed files with 3,912 additions and 1,524 deletions.
2 changes: 1 addition & 1 deletion e2e/angular/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Move Angular Project', () => {
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.app.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/tsconfig.spec.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/.eslintrc.json`);
expect(moveOutput).toContain(`CREATE ${newPath}/eslint.config.js`);
expect(moveOutput).toContain(`CREATE ${newPath}/public/favicon.ico`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/index.html`);
expect(moveOutput).toContain(`CREATE ${newPath}/src/main.ts`);
Expand Down
37 changes: 9 additions & 28 deletions e2e/angular/src/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ describe('Angular Projects', () => {

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

Expand Down Expand Up @@ -160,10 +159,7 @@ describe('Angular Projects', () => {
);

if (runE2ETests('playwright')) {
const e2eResults = runCLI(`e2e ${app}-e2e`);
expect(e2eResults).toContain(
`Successfully ran target e2e for project ${app}-e2e`
);
expect(() => runCLI(`e2e ${app}-e2e`)).not.toThrow();
expect(await killPort(4200)).toBeTruthy();
}
}, 1000000);
Expand Down Expand Up @@ -495,7 +491,7 @@ describe('Angular Projects', () => {
updateFile(`${lib}/src/lib/${lib}.module.ts`, moduleContent);

// ACT
const buildOutput = runCLI(`build ${lib}`);
const buildOutput = runCLI(`build ${lib}`, { env: { CI: 'false' } });

// ASSERT
expect(buildOutput).toContain(`Building entry point '@${proj}/${lib}'`);
Expand All @@ -516,14 +512,9 @@ describe('Angular Projects', () => {
// check files are generated with the layout directory ("apps/")
checkFilesExist(`apps/${appName}/src/app/app.module.ts`);
// check build works
expect(runCLI(`build ${appName}`)).toContain(
`Successfully ran target build for project ${appName}`
);
expect(() => runCLI(`build ${appName}`)).not.toThrow();
// check tests pass
const appTestResult = runCLI(`test ${appName}`);
expect(appTestResult).toContain(
`Successfully ran target test for project ${appName}`
);
expect(() => runCLI(`test ${appName}`)).not.toThrow();

runCLI(
`generate @nx/angular:lib ${libName} --standalone --buildable --project-name-and-root-format=derived`
Expand All @@ -535,14 +526,9 @@ describe('Angular Projects', () => {
`libs/${libName}/src/lib/${libName}/${libName}.component.ts`
);
// check build works
expect(runCLI(`build ${libName}`)).toContain(
`Successfully ran target build for project ${libName}`
);
expect(() => runCLI(`build ${libName}`)).not.toThrow();
// check tests pass
const libTestResult = runCLI(`test ${libName}`);
expect(libTestResult).toContain(
`Successfully ran target test for project ${libName}`
);
expect(() => runCLI(`test ${libName}`)).not.toThrow();
}, 500_000);

it('should support generating libraries with a scoped name when --project-name-and-root-format=as-provided', () => {
Expand All @@ -568,14 +554,9 @@ describe('Angular Projects', () => {
}.component.ts`
);
// check build works
expect(runCLI(`build ${libName}`)).toContain(
`Successfully ran target build for project ${libName}`
);
expect(() => runCLI(`build ${libName}`)).not.toThrow();
// check tests pass
const libTestResult = runCLI(`test ${libName}`);
expect(libTestResult).toContain(
`Successfully ran target test for project ${libName}`
);
expect(() => runCLI(`test ${libName}`)).not.toThrow();
}, 500_000);

it('should support generating applications with SSR and converting targets with webpack-based executors to use the application executor', async () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/esbuild/src/esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe('EsBuild Plugin', () => {
expect(
readJson(`dist/libs/${parentLib}/package.json`).dependencies
).toEqual({
'jsonc-eslint-parser': expect.any(String),
// Don't care about the versions, just that they exist
rambda: expect.any(String),
lodash: expect.any(String),
Expand Down
44 changes: 32 additions & 12 deletions e2e/eslint/src/linter-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import {
} from '@nx/e2e/utils';

describe('Linter (legacy)', () => {
describe('Integrated', () => {
describe('Integrated (eslintrc config)', () => {
let originalEslintUseFlatConfigVal: string | undefined;
const myapp = uniq('myapp');
const mylib = uniq('mylib');

let projScope;

beforeAll(() => {
projScope = newProject({
// Opt into legacy .eslintrc config format for these tests
originalEslintUseFlatConfigVal = process.env.ESLINT_USE_FLAT_CONFIG;
process.env.ESLINT_USE_FLAT_CONFIG = 'false';

newProject({
packages: ['@nx/react', '@nx/js', '@nx/eslint'],
});
runCLI(`generate @nx/react:app ${myapp} --tags=validtag`, {
Expand All @@ -31,7 +34,10 @@ describe('Linter (legacy)', () => {
env: { NX_ADD_PLUGINS: 'false' },
});
});
afterAll(() => cleanupProject());
afterAll(() => {
process.env.ESLINT_USE_FLAT_CONFIG = originalEslintUseFlatConfigVal;
cleanupProject();
});

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

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

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

// 3. linting should not error when all rules are followed
out = runCLI(`lint ${myapp}`, { silenceError: true });
expect(out).toContain('All files pass linting');
expect(() =>
runCLI(`lint ${myapp}`, { silenceError: true })
).not.toThrow();
}, 1000000);

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

describe('Flat config', () => {
describe('eslintrc convert to flat config', () => {
let originalEslintUseFlatConfigVal: string | undefined;
const packageManager = getSelectedPackageManager() || 'pnpm';

beforeAll(() => {
// Opt into legacy .eslintrc config format for these tests
originalEslintUseFlatConfigVal = process.env.ESLINT_USE_FLAT_CONFIG;
process.env.ESLINT_USE_FLAT_CONFIG = 'false';
});
afterAll(() => {
process.env.ESLINT_USE_FLAT_CONFIG = originalEslintUseFlatConfigVal;
});

beforeEach(() => {
process.env.NX_ADD_PLUGINS = 'false';
});
Expand Down Expand Up @@ -162,7 +179,9 @@ describe('Linter (legacy)', () => {
const outFlat = runCLI(`affected -t lint`, {
silenceError: true,
});
expect(outFlat).toContain('ran target lint');
expect(outFlat).toContain(`${myapp}:lint`);
expect(outFlat).toContain(`${mylib}:lint`);
expect(outFlat).toContain(`${mylib2}:lint`);
}, 1000000);

it('should convert standalone to flat config', () => {
Expand Down Expand Up @@ -199,7 +218,8 @@ describe('Linter (legacy)', () => {
const outFlat = runCLI(`affected -t lint`, {
silenceError: true,
});
expect(outFlat).toContain('ran target lint');
expect(outFlat).toContain(`${myapp}:lint`);
expect(outFlat).toContain(`${mylib}:lint`);
}, 1000000);
});
});
Loading

0 comments on commit 68eeb2e

Please sign in to comment.