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
  • Loading branch information
JamesHenry committed Aug 15, 2024
1 parent 0d97039 commit 0122b2d
Show file tree
Hide file tree
Showing 67 changed files with 1,352 additions and 436 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
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
28 changes: 22 additions & 6 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 Down Expand Up @@ -93,9 +99,19 @@ describe('Linter (legacy)', () => {
});
});

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
17 changes: 17 additions & 0 deletions e2e/eslint/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ import {
import * as ts from 'typescript';

describe('Linter', () => {
let originalEslintUseFlatConfigVal: string | undefined;
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;
});

describe('Integrated', () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
Expand Down Expand Up @@ -524,8 +534,15 @@ describe('Linter', () => {
});

describe('flat config', () => {
let envVar: string | undefined;
beforeAll(() => {
runCLI(`generate @nx/eslint:convert-to-flat-config`);
envVar = process.env.ESLINT_USE_FLAT_CONFIG;
// Now that we have converted the existing configs to flat config we need to clear the explicitly set env var to allow it to infer things from the root config file type
delete process.env.ESLINT_USE_FLAT_CONFIG;
});
afterAll(() => {
process.env.ESLINT_USE_FLAT_CONFIG = envVar;
});

it('should generate new projects using flat config', () => {
Expand Down
11 changes: 11 additions & 0 deletions e2e/js/src/js-packaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getPackageManagerCommand,
readJson,
updateFile,
renameFile,
} from '@nx/e2e/utils';
import { join } from 'path';

Expand Down Expand Up @@ -169,6 +170,16 @@ describe('packaging libs', () => {
`libs/${swcEsmLib}/src/index.ts`,
`export * from './lib/${swcEsmLib}.js';`
);
// We also need to update the eslint config file extensions to be explicitly commonjs
// TODO: re-evaluate this once we support ESM eslint configs
renameFile(
`libs/${tscEsmLib}/eslint.config.js`,
`libs/${tscEsmLib}/eslint.config.cjs`
);
renameFile(
`libs/${swcEsmLib}/eslint.config.js`,
`libs/${swcEsmLib}/eslint.config.cjs`
);

// Add additional entry points for `exports` field
updateJson(join('libs', tscLib, 'project.json'), (json) => {
Expand Down
3 changes: 2 additions & 1 deletion e2e/next/src/next-appdir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('Next.js App Router', () => {

afterAll(() => cleanupProject());

it('should be able to generate and build app with default App Router', async () => {
// TODO: this currently fails on eslint v9 because the stable eslint-plugin-next does not support it, despite the PR being merged many months ago
xit('should be able to generate and build app with default App Router', async () => {
const appName = uniq('app');
const jsLib = uniq('tslib');

Expand Down
3 changes: 2 additions & 1 deletion e2e/next/src/next-playwright-standalone-eslint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe('nextjs standalone playwright linting', () => {

afterEach(() => cleanupProject());

it('should work', async () => {
// TODO: this currently fails on eslint v9 because the stable eslint-plugin-next does not support it, despite the PR being merged many months ago
xit('should work', async () => {
const wsName = uniq('next');
const appName = uniq('app');
runCreateWorkspace(wsName, {
Expand Down
3 changes: 2 additions & 1 deletion e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe('Next.js Applications', () => {
}).not.toThrow();
}, 300_000);

it('should support --js flag', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should support --js flag', async () => {
const appName = uniq('app');

runCLI(
Expand Down
9 changes: 8 additions & 1 deletion e2e/nx-init/src/nx-init-react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ describe('nx init (for React - legacy)', () => {
const craToNxOutput = runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --no-interactive --vite=false`
} nx@${getPublishedVersion()} init --no-interactive --vite=false`,
{
env: {
...process.env,
// TODO: craco does not support ESLint v9 https://github.com/dilanx/craco/issues/543
ESLINT_USE_FLAT_CONFIG: 'false',
},
}
);

expect(craToNxOutput).toContain('🎉 Done!');
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx/src/__snapshots__/extras.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ exports[`Extra Nx Misc Tests task graph inputs should correctly expand dependent
"nx.json",
],
"lib-base-123": [
"libs/lib-base-123/.eslintrc.json",
"libs/lib-base-123/README.md",
"libs/lib-base-123/eslint.config.js",
"libs/lib-base-123/jest.config.ts",
"libs/lib-base-123/package.json",
"libs/lib-base-123/project.json",
Expand All @@ -38,8 +38,8 @@ exports[`Extra Nx Misc Tests task graph inputs should correctly expand dependent
"libs/lib-base-123/tsconfig.spec.json",
],
"lib-dependent-123": [
"libs/lib-dependent-123/.eslintrc.json",
"libs/lib-dependent-123/README.md",
"libs/lib-dependent-123/eslint.config.js",
"libs/lib-dependent-123/jest.config.ts",
"libs/lib-dependent-123/package.json",
"libs/lib-dependent-123/project.json",
Expand Down
11 changes: 8 additions & 3 deletions e2e/nx/src/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ describe('Nx Import', () => {
execSync(`git commit -am "initial commit"`, {
cwd: tempViteProjectPath,
});
execSync(`git checkout -b main`, {
cwd: tempViteProjectPath,
});

try {
execSync(`git checkout -b main`, {
cwd: tempViteProjectPath,
});
} catch {
// This fails if git is already configured to have `main` branch, but that's OK
}

const remote = tempViteProjectPath;
const ref = 'main';
Expand Down
3 changes: 2 additions & 1 deletion e2e/nx/src/workspace-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {

let proj: string;

describe('@nx/workspace:convert-to-monorepo', () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xdescribe('@nx/workspace:convert-to-monorepo', () => {
beforeEach(() => {
proj = newProject({ packages: ['@nx/react', '@nx/js'] });
});
Expand Down
3 changes: 2 additions & 1 deletion e2e/nx/src/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { join } from 'path';

let proj: string;

describe('@nx/workspace:convert-to-monorepo', () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xdescribe('@nx/workspace:convert-to-monorepo', () => {
beforeEach(() => {
proj = newProject({ packages: ['@nx/react', '@nx/js'] });
});
Expand Down
9 changes: 6 additions & 3 deletions e2e/react/src/react-vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('Build React applications and libraries with Vite', () => {
cleanupProject();
});

it('should test and lint app with bundler=vite and compiler=babel', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should test and lint app with bundler=vite and compiler=babel', async () => {
const viteApp = uniq('viteapp');

runCLI(
Expand All @@ -39,7 +40,8 @@ describe('Build React applications and libraries with Vite', () => {
checkFilesExist(`dist/apps/${viteApp}/index.html`);
}, 300_000);

it('should test and lint app with bundler=vite and compiler=swc', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should test and lint app with bundler=vite and compiler=swc', async () => {
const viteApp = uniq('viteapp');

runCLI(
Expand All @@ -60,7 +62,8 @@ describe('Build React applications and libraries with Vite', () => {
checkFilesExist(`dist/apps/${viteApp}/index.html`);
}, 300_000);

it('should test and lint app with bundler=vite and inSourceTests', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should test and lint app with bundler=vite and inSourceTests', async () => {
const viteApp = uniq('viteapp');
const viteLib = uniq('vitelib');

Expand Down
6 changes: 4 additions & 2 deletions e2e/react/src/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ describe('React Applications', () => {
}
}, 250_000);

it('should be able to generate a react app + lib (with CSR and SSR)', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should be able to generate a react app + lib (with CSR and SSR)', async () => {
const appName = uniq('app');
const libName = uniq('lib');
const libWithNoComponents = uniq('lib');
Expand Down Expand Up @@ -176,7 +177,8 @@ describe('React Applications', () => {
]);
}, 250_000);

it('should be able to add a redux slice', async () => {
// TODO: failing because of eslint-plugin-import with eslint v9 - https://github.com/import-js/eslint-plugin-import/issues/2948
xit('should be able to add a redux slice', async () => {
const appName = uniq('app');
const libName = uniq('lib');

Expand Down
9 changes: 5 additions & 4 deletions nx-dev/nx-dev-e2e/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page, test, expect } from '@playwright/test';
import { expect, test } from '@playwright/test';
/**
* Assert a text is present on the visited page.
* @param page
Expand All @@ -11,11 +11,12 @@ export function assertTextOnPage(
title: string,
selector: string = 'h1'
): void {
test.describe(path, () =>
// eslint-disable-next-line playwright/valid-title
test.describe(path, () => {
test(`should display "${title}"`, async ({ page }) => {
await page.goto(path);
const locator = page.locator(selector);
await expect(locator).toContainText(title);
})
);
});
});
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@
"@types/tmp": "^0.2.0",
"@types/yargs": "^17.0.10",
"@types/yarnpkg__lockfile": "^1.1.5",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"@typescript-eslint/type-utils": "^7.16.0",
"@typescript-eslint/utils": "7.16.0",
"@typescript-eslint/rule-tester": "^8.0.0",
"@typescript-eslint/type-utils": "^8.0.0",
"@typescript-eslint/utils": "^8.0.0",
"@xstate/immer": "0.3.1",
"@xstate/inspect": "0.7.0",
"@xstate/react": "3.0.1",
Expand Down Expand Up @@ -177,8 +176,8 @@
"eslint-plugin-cypress": "2.14.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-playwright": "^0.15.3",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-react": "7.35.0",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-storybook": "^0.8.0",
"express": "^4.19.2",
Expand Down Expand Up @@ -287,6 +286,7 @@
"typedoc": "0.25.12",
"typedoc-plugin-markdown": "3.17.1",
"typescript": "~5.5.2",
"typescript-eslint": "^8.0.0",
"unist-builder": "^4.0.0",
"unzipper": "^0.10.11",
"url-loader": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@phenomnomnominal/tsquery": "~5.0.1",
"@typescript-eslint/type-utils": "^7.16.0",
"@typescript-eslint/type-utils": "^8.0.0",
"chalk": "^4.1.0",
"find-cache-dir": "^3.3.2",
"magic-string": "~0.30.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cypress/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nxVersion = require('../../package.json').version;
export const eslintPluginCypressVersion = '^2.13.4';
export const eslintPluginCypressVersion = '^3.5.0';
export const typesNodeVersion = '18.16.9';
export const cypressViteDevServerVersion = '^2.2.1';
export const cypressVersion = '^13.13.0';
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"homepage": "https://nx.dev",
"peerDependencies": {
"@typescript-eslint/parser": "^6.13.2 || ^7.0.0",
"@typescript-eslint/parser": "^6.13.2 || ^7.0.0 || ^8.0.0",
"eslint-config-prettier": "^9.0.0"
},
"peerDependenciesMeta": {
Expand All @@ -36,8 +36,8 @@
"dependencies": {
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@typescript-eslint/type-utils": "^7.16.0",
"@typescript-eslint/utils": "^7.16.0",
"@typescript-eslint/type-utils": "^8.0.0",
"@typescript-eslint/utils": "^8.0.0",
"chalk": "^4.1.0",
"confusing-browser-globals": "^1.0.9",
"jsonc-eslint-parser": "^2.1.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin/src/configs/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,12 @@ export default {
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
/**
* During the migration to use ESLint v9 and typescript-eslint v8 for new workspaces,
* this rule would have created a lot of noise, so we are disabling it by default for now.
*
* TODO(v20): we should make this part of what we re-evaluate in v20
*/
'@typescript-eslint/no-require-imports': 'off',
},
};
Loading

0 comments on commit 0122b2d

Please sign in to comment.