Skip to content

Commit

Permalink
chore: update basic example to ESLint v9 and Flat Configurations. (#…
Browse files Browse the repository at this point in the history
…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 <111712068+vincenthsh@users.noreply.github.com>
  • Loading branch information
anthonyshew and vincenthsh authored Nov 25, 2024
1 parent cbb85b3 commit b00eea2
Show file tree
Hide file tree
Showing 21 changed files with 2,435 additions and 4,319 deletions.
9 changes: 0 additions & 9 deletions examples/basic/apps/docs/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions examples/basic/apps/docs/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { nextJsConfig } from "@repo/eslint-config/next-js";

/** @type {import("eslint").Linter.Config} */
export default nextJsConfig;
File renamed without changes.
5 changes: 3 additions & 2 deletions examples/basic/apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "docs",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint": "next lint --max-warnings 0",
"check-types": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -21,7 +22,7 @@
"@types/node": "^20",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.0",
"eslint": "^8",
"eslint": "^9.15.0",
"eslint-config-next": "15.0.3",
"typescript": "5.5.4"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"include": [
"next-env.d.ts",
"next.config.mjs",
"next.config.js",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
Expand Down
9 changes: 0 additions & 9 deletions examples/basic/apps/web/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions examples/basic/apps/web/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { nextJsConfig } from "@repo/eslint-config/next-js";

/** @type {import("eslint").Linter.Config} */
export default nextJsConfig;
File renamed without changes.
5 changes: 3 additions & 2 deletions examples/basic/apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "web",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint": "next lint --max-warnings 0",
"check-types": "tsc --noEmit"
},
"dependencies": {
Expand All @@ -21,7 +22,7 @@
"@types/node": "^20",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.0",
"eslint": "^8",
"eslint": "^9.15.0",
"eslint-config-next": "15.0.3",
"typescript": "5.5.4"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"include": [
"next-env.d.ts",
"next.config.mjs",
"next.config.js",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
Expand Down
7 changes: 0 additions & 7 deletions examples/basic/meta.json

This file was deleted.

32 changes: 32 additions & 0 deletions examples/basic/packages/eslint-config/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import turboPlugin from "eslint-plugin-turbo";
import tseslint from "typescript-eslint";
import onlyWarn from "eslint-plugin-only-warn";

/**
* A shared ESLint configuration for the repository.
*
* @type {import("eslint").Linter.Config}
* */
export const config = [
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
{
plugins: {
turbo: turboPlugin,
},
rules: {
"turbo/no-undeclared-env-vars": "warn",
},
},
{
plugins: {
onlyWarn,
},
},
{
ignores: ["dist/**"],
},
];
34 changes: 0 additions & 34 deletions examples/basic/packages/eslint-config/library.js

This file was deleted.

74 changes: 44 additions & 30 deletions examples/basic/packages/eslint-config/next.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
const { resolve } = require("node:path");
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import tseslint from "typescript-eslint";
import pluginReactHooks from "eslint-plugin-react-hooks";
import pluginReact from "eslint-plugin-react";
import globals from "globals";
import pluginNext from "@next/eslint-plugin-next";
import { config as baseConfig } from "./base.js";

const project = resolve(process.cwd(), "tsconfig.json");

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
"eslint:recommended",
"prettier",
require.resolve("@vercel/style-guide/eslint/next"),
"turbo",
],
globals: {
React: true,
JSX: true,
/**
* A custom ESLint configuration for libraries that use React.
*
* @type {import("eslint").Linter.Config}
* */
export const nextJsConfig = [
...baseConfig,
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
{
...pluginReact.configs.flat.recommended,
languageOptions: {
...pluginReact.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
},
},
},
env: {
node: true,
browser: true,
{
plugins: {
"@next/next": pluginNext,
},
rules: {
...pluginNext.configs.recommended.rules,
...pluginNext.configs["core-web-vitals"].rules,
},
},
plugins: ["only-warn"],
settings: {
"import/resolver": {
typescript: {
project,
},
{
plugins: {
"react-hooks": pluginReactHooks,
},
settings: { react: { version: "detect" } },
rules: {
...pluginReactHooks.configs.recommended.rules,
// React scope no longer necessary with new JSX transform.
"react/react-in-jsx-scope": "off",
},
},
ignorePatterns: [
// Ignore dotfiles
".*.js",
"node_modules/",
],
overrides: [{ files: ["*.js?(x)", "*.ts?(x)"] }],
};
];
26 changes: 16 additions & 10 deletions examples/basic/packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"name": "@repo/eslint-config",
"version": "0.0.0",
"type": "module",
"private": true,
"files": [
"library.js",
"next.js",
"react-internal.js"
],
"exports": {
"./base": "./base.js",
"./next-js": "./next.js",
"./react-internal": "./react-internal.js"
},
"devDependencies": {
"@vercel/style-guide": "^5.2.0",
"eslint-config-turbo": "^2.0.0",
"@next/eslint-plugin-next": "^15",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-only-warn": "^1.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"typescript": "5.5.4"
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-turbo": "^2.3.0",
"globals": "^15.12.0",
"typescript": "^5.3.3",
"typescript-eslint": "^8.15.0"
}
}
69 changes: 35 additions & 34 deletions examples/basic/packages/eslint-config/react-internal.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
const { resolve } = require("node:path");
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import tseslint from "typescript-eslint";
import pluginReactHooks from "eslint-plugin-react-hooks";
import pluginReact from "eslint-plugin-react";
import globals from "globals";
import { config as baseConfig } from "./base.js";

const project = resolve(process.cwd(), "tsconfig.json");

/*
* This is a custom ESLint configuration for use with
* internal (bundled by their consumer) libraries
* that utilize React.
*/

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint:recommended", "prettier", "turbo"],
plugins: ["only-warn"],
globals: {
React: true,
},
env: {
browser: true,
},
settings: {
"import/resolver": {
typescript: {
project,
/**
* A custom ESLint configuration for libraries that use React.
*
* @type {import("eslint").Linter.Config} */
export const config = [
...baseConfig,
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
{
languageOptions: {
...pluginReact.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
...globals.browser,
},
},
},
ignorePatterns: [
// Ignore dotfiles
".*.js",
"node_modules/",
"dist/",
],
overrides: [
// Force ESLint to detect .tsx files
{ files: ["*.js?(x)", "*.ts?(x)"] },
],
};
{
plugins: {
"react-hooks": pluginReactHooks,
},
settings: { react: { version: "detect" } },
rules: {
...pluginReactHooks.configs.recommended.rules,
// React scope no longer necessary with new JSX transform.
"react/react-in-jsx-scope": "off",
},
},
];
10 changes: 0 additions & 10 deletions examples/basic/packages/ui/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions examples/basic/packages/ui/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { config } from "@repo/eslint-config/react-internal";

/** @type {import("eslint").Linter.Config} */
export default config;
5 changes: 3 additions & 2 deletions examples/basic/packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@repo/ui",
"version": "0.0.0",
"type": "module",
"private": true,
"exports": {
"./button": "./src/button.tsx",
Expand All @@ -16,11 +17,11 @@
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@turbo/gen": "^1.12.4",
"@types/node": "^20.11.24",
"@types/eslint": "^8.56.5",
"@types/node": "^20.11.24",
"@types/react": "18.3.0",
"@types/react-dom": "18.3.1",
"eslint": "^8.57.0",
"eslint": "^9.15.0",
"typescript": "5.5.4"
},
"dependencies": {
Expand Down
Loading

0 comments on commit b00eea2

Please sign in to comment.