Skip to content

Commit b00eea2

Browse files
chore: update basic example to ESLint v9 and Flat Configurations. (#9501)
### Description This PR converts our `basic` example to ESLint v9 with Flat Configurations. I may have a few gray hairs now, but I'm very excited for the community to have this. ### Testing Instructions Use `npx create-turbo@canary -e https://github.com/vercel/turborepo/tree/shew-409f3/examples/basic basic-eslint-9` to try it out. - Pull it down, make sure you see diagnostics where you'd expect in your editor. Including for `eslint-config-turbo`, most importantly! - I know the diff is big, but there may be vestigials from my experimenting lying around. Please use a finely toothed comb! (I've looked myself but the more eyes, the better.) --------- Co-authored-by: vincenthsh <[email protected]>
1 parent cbb85b3 commit b00eea2

21 files changed

+2435
-4319
lines changed

examples/basic/apps/docs/.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { nextJsConfig } from "@repo/eslint-config/next-js";
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default nextJsConfig;

examples/basic/apps/docs/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "docs",
33
"version": "0.1.0",
4+
"type": "module",
45
"private": true,
56
"scripts": {
67
"dev": "next dev --turbopack",
78
"build": "next build",
89
"start": "next start",
9-
"lint": "next lint",
10+
"lint": "next lint --max-warnings 0",
1011
"check-types": "tsc --noEmit"
1112
},
1213
"dependencies": {
@@ -21,7 +22,7 @@
2122
"@types/node": "^20",
2223
"@types/react": "18.3.1",
2324
"@types/react-dom": "18.3.0",
24-
"eslint": "^8",
25+
"eslint": "^9.15.0",
2526
"eslint-config-next": "15.0.3",
2627
"typescript": "5.5.4"
2728
}

examples/basic/apps/docs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"include": [
1111
"next-env.d.ts",
12-
"next.config.mjs",
12+
"next.config.js",
1313
"**/*.ts",
1414
"**/*.tsx",
1515
".next/types/**/*.ts"

examples/basic/apps/web/.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { nextJsConfig } from "@repo/eslint-config/next-js";
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default nextJsConfig;

examples/basic/apps/web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "web",
33
"version": "0.1.0",
4+
"type": "module",
45
"private": true,
56
"scripts": {
67
"dev": "next dev --turbopack",
78
"build": "next build",
89
"start": "next start",
9-
"lint": "next lint",
10+
"lint": "next lint --max-warnings 0",
1011
"check-types": "tsc --noEmit"
1112
},
1213
"dependencies": {
@@ -21,7 +22,7 @@
2122
"@types/node": "^20",
2223
"@types/react": "18.3.1",
2324
"@types/react-dom": "18.3.0",
24-
"eslint": "^8",
25+
"eslint": "^9.15.0",
2526
"eslint-config-next": "15.0.3",
2627
"typescript": "5.5.4"
2728
}

examples/basic/apps/web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"include": [
1111
"next-env.d.ts",
12-
"next.config.mjs",
12+
"next.config.js",
1313
"**/*.ts",
1414
"**/*.tsx",
1515
".next/types/**/*.ts"

examples/basic/meta.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import turboPlugin from "eslint-plugin-turbo";
4+
import tseslint from "typescript-eslint";
5+
import onlyWarn from "eslint-plugin-only-warn";
6+
7+
/**
8+
* A shared ESLint configuration for the repository.
9+
*
10+
* @type {import("eslint").Linter.Config}
11+
* */
12+
export const config = [
13+
js.configs.recommended,
14+
eslintConfigPrettier,
15+
...tseslint.configs.recommended,
16+
{
17+
plugins: {
18+
turbo: turboPlugin,
19+
},
20+
rules: {
21+
"turbo/no-undeclared-env-vars": "warn",
22+
},
23+
},
24+
{
25+
plugins: {
26+
onlyWarn,
27+
},
28+
},
29+
{
30+
ignores: ["dist/**"],
31+
},
32+
];

examples/basic/packages/eslint-config/library.js

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
1-
const { resolve } = require("node:path");
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import tseslint from "typescript-eslint";
4+
import pluginReactHooks from "eslint-plugin-react-hooks";
5+
import pluginReact from "eslint-plugin-react";
6+
import globals from "globals";
7+
import pluginNext from "@next/eslint-plugin-next";
8+
import { config as baseConfig } from "./base.js";
29

3-
const project = resolve(process.cwd(), "tsconfig.json");
4-
5-
/** @type {import("eslint").Linter.Config} */
6-
module.exports = {
7-
extends: [
8-
"eslint:recommended",
9-
"prettier",
10-
require.resolve("@vercel/style-guide/eslint/next"),
11-
"turbo",
12-
],
13-
globals: {
14-
React: true,
15-
JSX: true,
10+
/**
11+
* A custom ESLint configuration for libraries that use React.
12+
*
13+
* @type {import("eslint").Linter.Config}
14+
* */
15+
export const nextJsConfig = [
16+
...baseConfig,
17+
js.configs.recommended,
18+
eslintConfigPrettier,
19+
...tseslint.configs.recommended,
20+
{
21+
...pluginReact.configs.flat.recommended,
22+
languageOptions: {
23+
...pluginReact.configs.flat.recommended.languageOptions,
24+
globals: {
25+
...globals.serviceworker,
26+
},
27+
},
1628
},
17-
env: {
18-
node: true,
19-
browser: true,
29+
{
30+
plugins: {
31+
"@next/next": pluginNext,
32+
},
33+
rules: {
34+
...pluginNext.configs.recommended.rules,
35+
...pluginNext.configs["core-web-vitals"].rules,
36+
},
2037
},
21-
plugins: ["only-warn"],
22-
settings: {
23-
"import/resolver": {
24-
typescript: {
25-
project,
26-
},
38+
{
39+
plugins: {
40+
"react-hooks": pluginReactHooks,
41+
},
42+
settings: { react: { version: "detect" } },
43+
rules: {
44+
...pluginReactHooks.configs.recommended.rules,
45+
// React scope no longer necessary with new JSX transform.
46+
"react/react-in-jsx-scope": "off",
2747
},
2848
},
29-
ignorePatterns: [
30-
// Ignore dotfiles
31-
".*.js",
32-
"node_modules/",
33-
],
34-
overrides: [{ files: ["*.js?(x)", "*.ts?(x)"] }],
35-
};
49+
];
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
22
"name": "@repo/eslint-config",
33
"version": "0.0.0",
4+
"type": "module",
45
"private": true,
5-
"files": [
6-
"library.js",
7-
"next.js",
8-
"react-internal.js"
9-
],
6+
"exports": {
7+
"./base": "./base.js",
8+
"./next-js": "./next.js",
9+
"./react-internal": "./react-internal.js"
10+
},
1011
"devDependencies": {
11-
"@vercel/style-guide": "^5.2.0",
12-
"eslint-config-turbo": "^2.0.0",
12+
"@next/eslint-plugin-next": "^15",
13+
"@typescript-eslint/eslint-plugin": "^8.15.0",
14+
"@typescript-eslint/parser": "^8.15.0",
15+
"eslint": "^9.15.0",
1316
"eslint-config-prettier": "^9.1.0",
1417
"eslint-plugin-only-warn": "^1.1.0",
15-
"@typescript-eslint/parser": "^7.1.0",
16-
"@typescript-eslint/eslint-plugin": "^7.1.0",
17-
"typescript": "5.5.4"
18+
"eslint-plugin-react": "^7.37.2",
19+
"eslint-plugin-react-hooks": "^5.0.0",
20+
"eslint-plugin-turbo": "^2.3.0",
21+
"globals": "^15.12.0",
22+
"typescript": "^5.3.3",
23+
"typescript-eslint": "^8.15.0"
1824
}
1925
}
Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
const { resolve } = require("node:path");
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import tseslint from "typescript-eslint";
4+
import pluginReactHooks from "eslint-plugin-react-hooks";
5+
import pluginReact from "eslint-plugin-react";
6+
import globals from "globals";
7+
import { config as baseConfig } from "./base.js";
28

3-
const project = resolve(process.cwd(), "tsconfig.json");
4-
5-
/*
6-
* This is a custom ESLint configuration for use with
7-
* internal (bundled by their consumer) libraries
8-
* that utilize React.
9-
*/
10-
11-
/** @type {import("eslint").Linter.Config} */
12-
module.exports = {
13-
extends: ["eslint:recommended", "prettier", "turbo"],
14-
plugins: ["only-warn"],
15-
globals: {
16-
React: true,
17-
},
18-
env: {
19-
browser: true,
20-
},
21-
settings: {
22-
"import/resolver": {
23-
typescript: {
24-
project,
9+
/**
10+
* A custom ESLint configuration for libraries that use React.
11+
*
12+
* @type {import("eslint").Linter.Config} */
13+
export const config = [
14+
...baseConfig,
15+
js.configs.recommended,
16+
eslintConfigPrettier,
17+
...tseslint.configs.recommended,
18+
pluginReact.configs.flat.recommended,
19+
{
20+
languageOptions: {
21+
...pluginReact.configs.flat.recommended.languageOptions,
22+
globals: {
23+
...globals.serviceworker,
24+
...globals.browser,
2525
},
2626
},
2727
},
28-
ignorePatterns: [
29-
// Ignore dotfiles
30-
".*.js",
31-
"node_modules/",
32-
"dist/",
33-
],
34-
overrides: [
35-
// Force ESLint to detect .tsx files
36-
{ files: ["*.js?(x)", "*.ts?(x)"] },
37-
],
38-
};
28+
{
29+
plugins: {
30+
"react-hooks": pluginReactHooks,
31+
},
32+
settings: { react: { version: "detect" } },
33+
rules: {
34+
...pluginReactHooks.configs.recommended.rules,
35+
// React scope no longer necessary with new JSX transform.
36+
"react/react-in-jsx-scope": "off",
37+
},
38+
},
39+
];

examples/basic/packages/ui/.eslintrc.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { config } from "@repo/eslint-config/react-internal";
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default config;

examples/basic/packages/ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@repo/ui",
33
"version": "0.0.0",
4+
"type": "module",
45
"private": true,
56
"exports": {
67
"./button": "./src/button.tsx",
@@ -16,11 +17,11 @@
1617
"@repo/eslint-config": "workspace:*",
1718
"@repo/typescript-config": "workspace:*",
1819
"@turbo/gen": "^1.12.4",
19-
"@types/node": "^20.11.24",
2020
"@types/eslint": "^8.56.5",
21+
"@types/node": "^20.11.24",
2122
"@types/react": "18.3.0",
2223
"@types/react-dom": "18.3.1",
23-
"eslint": "^8.57.0",
24+
"eslint": "^9.15.0",
2425
"typescript": "5.5.4"
2526
},
2627
"dependencies": {

0 commit comments

Comments
 (0)