Skip to content

Commit

Permalink
feat!(eslint-config): migrate to Typescript-eslint v8 (#191)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Using the new Typescript-eslint version and bumped a few other majors. This includes a few rule changes, which may impact your project.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Dirk de Visser <github@dirkdevisser.nl>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dirk de Visser <github@dirkdevisser.nl>
  • Loading branch information
dependabot[bot] and dirkdev98 authored Aug 21, 2024
1 parent 60577f1 commit f0bbcd5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 73 deletions.
19 changes: 2 additions & 17 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,9 @@ Add the following scripts to your `package.json`:

> Make sure to add `.cache` to your .gitignore
### In a CommonJS project

> [!NOTE]
> > [!NOTE]
>
> These steps will be obsolete with ESLint v9, which at the time of writing is released
> but not yet supported by all our plugins.
- Use `eslint.config.mjs` instead of `eslint.config.js`
- Specify `--config eslint.config.mjs` in the `package.json` scripts. For example:

```json
{
"scripts": {
"lint": "eslint . --fix --cache --cache-location .cache/eslint/ --config eslint.config.mjs",
"lint:ci": "eslint . --config eslint.config.mjs"
}
}
```
> In a CommonJS project, make sure to name your file `eslint.config.mjs` instead.
## Default configuration and options

Expand Down
22 changes: 11 additions & 11 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@
},
"dependencies": {
"@eslint/js": "8.57.0",
"@typescript-eslint/utils": "7.18.0",
"@typescript-eslint/utils": "8.2.0",
"diff-match-patch": "1.0.5",
"eslint": "8.57.0",
"eslint-config-flat-gitignore": "0.1.5",
"eslint-config-flat-gitignore": "0.1.8",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-merge-processors": "0.1.0",
"eslint-plugin-comment-length": "1.7.3",
"eslint-plugin-file-progress": "1.4.0",
"eslint-plugin-file-progress": "1.5.0",
"eslint-plugin-import-x": "3.1.0",
"eslint-plugin-jsdoc": "48.10.2",
"eslint-plugin-jsdoc": "50.2.2",
"eslint-plugin-markdown": "5.1.0",
"eslint-plugin-unused-imports": "3.2.0",
"eslint-plugin-unused-imports": "4.1.3",
"globals": "15.9.0",
"prettier": "3.3.3",
"synckit": "0.9.1",
"typescript-eslint": "7.18.0"
"typescript-eslint": "8.2.0"
},
"peerDependencies": {
"@next/eslint-plugin-next": "^14.1.4",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-no-relative-import-paths": "^1.5.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0"
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-no-relative-import-paths": "^1.5.5",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2"
},
"peerDependenciesMeta": {
"@next/eslint-plugin-next": {
Expand All @@ -73,7 +73,7 @@
"devDependencies": {
"@next/eslint-plugin-next": "14.2.5",
"@types/diff-match-patch": "1.0.36",
"@types/eslint": "8.56.9",
"@types/eslint": "8.56.10",
"@types/eslint__js": "8.42.3",
"@types/eslint-plugin-markdown": "2.0.2",
"eslint-plugin-jsx-a11y": "6.9.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-config/src/imports.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import * as pluginImport from "eslint-plugin-import-x";
// @ts-expect-error No types available
import pluginUnusedImports from "eslint-plugin-unused-imports";
import { GLOBS, globUse } from "./globs.js";
import type { TypeScriptConfig } from "./typescript.js";

export function imports(typescript: TypeScriptConfig) {
export function imports(typescript: TypeScriptConfig): Array<FlatConfig.Config> {
return [
{
// Setup import plugins. Includes unused-imports, to automatically remove them.
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function javascript(): Array<FlatConfig.Config> {
parser: typescriptEslintParser,
parserOptions: {
project: false,
EXPERIMENTAL_useProjectService: false,
projectService: false,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function markdownSnippetOverrides(): Array<FlatConfig.Config> {
...typescriptEslint.configs.disableTypeChecked,
languageOptions: {
parserOptions: {
EXPERIMENTAL_useProjectService: false,
projectService: false,
warnOnUnsupportedTypeScriptVersion: false,
project: false,
program: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface PrettierConfig {
/**
* Override default Prettier options for specific files.
*/
languageOverrides?: { [K in SupportedLanguageOverrides]?: PrettierOptions };
languageOverrides?: Partial<Record<SupportedLanguageOverrides, PrettierOptions>>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function typescript(config: TypeScriptConfig): Array<FlatConfig.Config> {
languageOptions: {
parser: typescriptEslint.parser,
parserOptions: {
EXPERIMENTAL_useProjectService: config.projectService,
projectService: config.projectService,
warnOnUnsupportedTypeScriptVersion: false,
},
},
Expand Down
44 changes: 6 additions & 38 deletions packages/eslint-config/test/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as crypto from "node:crypto";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";
import { afterAll, beforeAll, expect, test } from "vitest";
import { beforeAll, beforeEach, expect, test } from "vitest";
import type { defineConfig } from "../src/index.js";

const execPromise = promisify(exec);
Expand All @@ -15,13 +15,15 @@ const tmpDir = path.join(import.meta.dirname, `../.cache/.tmp/${crypto.randomUUI
beforeAll(async () => {
// We are going to execute ESLint, so make sure that we have an up-to-date build
await execPromise("npm run build");
});

beforeEach(async () => {
// Create a temporary directory to run our tests in.
await fs.mkdir(tmpDir, { recursive: true });
});

afterAll(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
return async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
};
});

async function testOnStdout(
Expand Down Expand Up @@ -205,40 +207,6 @@ test("automatically enables typescript support on detection of tsconfig.json", a
expect(stdoutLinesForFile(stdout, "index.ts")).toMatch(/\(format\/prettier\)/);
});

test("automatically prefers tsconfig.eslint.json over tsconfig.json", async () => {
const { stdout } = await testOnStdout({}, [
{
path: "tsconfig.json",
contents: JSON.stringify({
extends: "@total-typescript/tsconfig/tsc/no-dom/library-monorepo",
compilerOptions: {
outDir: "dist",
},
files: ["./bar.ts"],
}),
},
{
path: "tsconfig.eslint.json",
contents: JSON.stringify({
extends: "@total-typescript/tsconfig/tsc/no-dom/library-monorepo",
compilerOptions: {
noEmit: true,
},
includes: ["**/*"],
}),
},
{
path: "index.ts",
contents: `let foo: 2= 2`,
},
]);

expect(stdoutLinesForFile(stdout, "index.ts")).toMatch(
/\(unused-imports\/no-unused-vars\)/,
);
expect(stdoutLinesForFile(stdout, "index.ts")).toMatch(/\(format\/prettier\)/);
});

test("enables js file linting without tsconfig.json", async () => {
const { stdout } = await testOnStdout({}, [
{
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"composite": false,
"declaration": false
},
"files": ["./eslint.config.js"],
"files": ["./eslint.config.js", "./vitest.workspace.ts"],
"references": [
{
"path": "./packages/eslint-config"
Expand Down

0 comments on commit f0bbcd5

Please sign in to comment.