Unverified Commit 3b4e4478 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Use ESLint Flat Config (#84800)

parent 0720d7c0
import { globalIgnores } from 'eslint/config'
export default globalIgnores([
'**/.*/**/*', // Default of ESLint legacy config
'**/node_modules',
'**/.next/**/*',
'**/_next/**/*',
'**/.vscode/**/*',
'**/dist/**/*',
'e2e-tests/**/*',
'examples/cms-sanity/sanity.types.ts',
'examples/with-eslint/**/*',
'examples/with-typescript-eslint-jest/**/*',
'examples/with-kea/**/*',
'examples/with-custom-babel-config/**/*',
'examples/with-flow/**/*',
'examples/with-jest/**/*',
'examples/with-mobx-state-tree/**/*',
'examples/with-mobx/**/*',
'examples/with-tigris/db/models/todoItems.ts',
'packages/next/src/bundles/webpack/packages/*.runtime.js',
'packages/next/src/bundles/webpack/packages/lazy-compilation-*.js',
'packages/next/src/compiled/**/*',
'packages/next/wasm/@next',
'packages/react-refresh-utils/**/*.js',
'packages/react-dev-overlay/lib/**/*',
'**/__tmp__/**/*',
'.github/actions/next-stats-action/.work',
'packages/next-codemod/transforms/__testfixtures__/**/*',
'packages/next-codemod/transforms/__tests__/**/*',
'packages/next-codemod/bin/__testfixtures__/**/*',
'packages/next-codemod/**/*.js',
'packages/next-codemod/**/*.d.ts',
'packages/next-env/**/*.d.ts',
'packages/create-next-app/templates/**/*',
'test/integration/eslint/**/*.js',
'test/integration/script-loader/**/*.js',
'test/development/basic/legacy-decorators/**/*.js',
'test/production/emit-decorator-metadata/**/*.js',
'!test/**/*.test.*',
'test/e2e/app-dir/rsc-errors/app/swc/use-client/page.js',
'**/test-timings.json',
'crates/**/*',
'bench/nested-deps/**/*',
'bench/nested-deps-app-router/**/*',
'bench/heavy-npm-deps/**/*',
'packages/next-bundle-analyzer/index.d.ts',
'examples/with-typescript-graphql/lib/gql/',
'test/development/basic/hmr/components/parse-error.js',
'test/development/mcp-server/fixtures/default-template/app/build-error/page.tsx',
'packages/next-swc/docs/assets/**/*',
'test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/sourcemapped.js',
'test/e2e/app-dir/server-source-maps/fixtures/default/external-pkg/sourcemapped.js',
'test/development/next-lint-eslint-formatter-compact/**/*.js',
'test/e2e/app-dir/app-external/app/mixed/import/mixed-mod.mjs',
'turbopack/crates/*/tests/**/*',
'turbopack/crates/*/js/src/compiled',
])
node_modules
**/.next/**
**/_next/**
**/.vscode/**
**/dist/**
e2e-tests/**
examples/cms-sanity/sanity.types.ts
examples/with-eslint/**
examples/with-typescript-eslint-jest/**
examples/with-kea/**
examples/with-custom-babel-config/**
examples/with-flow/**
examples/with-jest/**
examples/with-mobx-state-tree/**
examples/with-mobx/**
examples/with-tigris/db/models/todoItems.ts
packages/next/src/bundles/webpack/packages/*.runtime.js
packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
packages/next/src/compiled/**/*
packages/next/wasm/@next
packages/react-refresh-utils/**/*.js
packages/react-dev-overlay/lib/**
**/__tmp__/**
.github/actions/next-stats-action/.work
packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/bin/__testfixtures__/**/*
packages/next-codemod/**/*.js
packages/next-codemod/**/*.d.ts
packages/next-env/**/*.d.ts
packages/create-next-app/templates/**
test/integration/eslint/**/*.js
test/integration/script-loader/**/*.js
test/development/basic/legacy-decorators/**/*.js
test/production/emit-decorator-metadata/**/*.js
!test/**/*.test.*
test/e2e/app-dir/rsc-errors/app/swc/use-client/page.js
test-timings.json
crates/**
bench/nested-deps/**
bench/nested-deps-app-router/**
bench/heavy-npm-deps/**
packages/next-bundle-analyzer/index.d.ts
examples/with-typescript-graphql/lib/gql/
test/development/basic/hmr/components/parse-error.js
test/development/mcp-server/fixtures/default-template/app/build-error/page.tsx
packages/next-swc/docs/assets/**/*
test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/sourcemapped.js
test/e2e/app-dir/server-source-maps/fixtures/default/external-pkg/sourcemapped.js
test/development/next-lint-eslint-formatter-compact/**/*.js
test/e2e/app-dir/app-external/app/mixed/import/mixed-mod.mjs
# turbopack crates
turbopack/crates/*/tests/**
turbopack/crates/*/js/src/compiled
\ No newline at end of file
{
"$schema": "https://json.schemastore.org/eslintrc",
"extends": [".eslintrc.json"],
"overrides": [
{
// This override adds type-checked rules.
"files": ["**/*.ts", "**/*.tsx"],
// Linting with type-checked rules is very slow and needs a lot of memory,
// so we exclude non-essential files.
"excludedFiles": [
"examples/**/*",
"test/**/*",
"**/*.d.ts",
"turbopack/**/*"
],
"parserOptions": {
"project": true
},
// These rules are added on top of the rules that are declared in
// .eslintrc.json for the matching files.
"rules": {
// TODO: enable in follow-up PR
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/switch-exhaustiveness-check": "error"
}
}
]
}
This diff is collapsed.
......@@ -16,7 +16,7 @@
"typescript",
"typescriptreact"
],
"eslint.useFlatConfig": false,
"eslint.useFlatConfig": true,
// Set Jest runMode to on-demand as otherwise it will start running all tests the first time.
// Equivalent to deprecated option "jest.autoRun": "off"
"jest.runMode": "on-demand",
......
......@@ -23,7 +23,7 @@
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint": "9.37.0",
"eslint-config-next": "canary",
"tailwindcss": "4.1.13",
"typescript": "^5"
......
......@@ -22,7 +22,7 @@ If you get a warning by alex, follow the instructions to correct the language.
We recommend installing the [ESLint plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
You can find the enabled rules in the [ESLint config](../../.eslintrc.json).
You can find the enabled rules in the [ESLint config](../../eslint.config.mjs).
## Prettier
......
import { defineConfig } from 'eslint/config'
import baseConfig from './eslint.config.mjs'
export default defineConfig([
{
extends: [baseConfig],
},
{
files: ['**/*.ts', '**/*.tsx'],
// This override adds type-checked rules.
// Linting with type-checked rules is very slow and needs a lot of memory,
// so we exclude non-essential files.
ignores: ['examples/**/*', 'test/**/*', '**/*.d.ts', 'turbopack/**/*'],
languageOptions: {
parserOptions: {
project: true,
},
},
// These rules are added on top of the rules that are declared in
// the base config for the matching files.
rules: {
// TODO: enable in follow-up PR
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
},
},
])
This diff is collapsed.
module.exports = {
'*.{js,jsx,mjs,ts,tsx,mts,mdx}': [
'prettier --with-node-modules --ignore-path .prettierignore --write',
'cross-env ESLINT_USE_FLAT_CONFIG=false eslint --config .eslintrc.json --no-eslintrc --fix',
'eslint --config eslint.config.mjs --fix',
],
'*.{json,md,css,html,yml,yaml,scss}': [
'prettier --with-node-modules --ignore-path .prettierignore --write',
......
......@@ -67,7 +67,7 @@
"git-clean": "git clean -d -x -e node_modules -e packages -f",
"typescript": "tsc --noEmit",
"lint-typescript": "turbo run typescript",
"lint-eslint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --ext js,jsx,mjs,ts,tsx,mts,mdx --config .eslintrc.cli.json --no-eslintrc",
"lint-eslint": "eslint --config eslint.cli.config.mjs",
"lint-ast-grep": "ast-grep scan",
"lint-no-typescript": "run-p prettier-check \"lint-eslint .\" lint-language",
"types-and-precompiled": "run-p \"lint-typescript --log-order=stream\" check-compiler-fixtures types:test-lib && pnpm check-precompiled",
......@@ -127,6 +127,9 @@
"@edge-runtime/jest-environment": "4.0.0",
"@emotion/cache": "11.11.0",
"@emotion/react": "11.11.1",
"@eslint/compat": "1.4.0",
"@eslint/eslintrc": "^3",
"@eslint/js": "9.37.0",
"@fullhuman/postcss-purgecss": "1.3.0",
"@jest/expect-utils": "29.7.0",
"@mdx-js/loader": "2.2.1",
......@@ -168,8 +171,6 @@
"@types/relay-runtime": "14.1.13",
"@types/string-hash": "1.1.1",
"@types/trusted-types": "2.0.3",
"@typescript-eslint/eslint-plugin": "^8.36.0",
"@typescript-eslint/parser": "^8.36.0",
"@vercel/devlow-bench": "workspace:*",
"@vercel/kv": "3.0.0",
"@vercel/og": "0.7.2",
......@@ -190,7 +191,7 @@
"dd-trace": "4.12.0",
"es5-ext": "0.10.53",
"escape-string-regexp": "2.0.0",
"eslint": "9.12.0",
"eslint": "9.37.0",
"eslint-config-next": "workspace:*",
"eslint-formatter-codeframe": "7.32.1",
"eslint-plugin-eslint-plugin": "5.2.1",
......@@ -214,6 +215,7 @@
"get-port": "5.1.1",
"get-port-please": "3.1.1",
"glob": "7.1.6",
"globals": "16.4.0",
"gzip-size": "5.1.1",
"html-validator": "5.1.18",
"http-proxy": "1.18.1",
......@@ -294,6 +296,7 @@
"tsx": "4.19.2",
"turbo": "2.5.5",
"typescript": "5.9.2",
"typescript-eslint": "8.46.0",
"unfetch": "4.2.0",
"wait-port": "0.2.2",
"webpack": "5.98.0",
......
......@@ -12,9 +12,9 @@
"directory": "packages/eslint-plugin-internal"
},
"peerDependencies": {
"eslint": "9.12.0"
"eslint": "9.37.0"
},
"devDependencies": {
"eslint": "9.12.0"
"eslint": "9.37.0"
}
}
......@@ -17,7 +17,7 @@
},
"devDependencies": {
"@types/eslint": "9.6.1",
"eslint": "9.12.0"
"eslint": "9.37.0"
},
"scripts": {
"dev": "pnpm build",
......
......@@ -37,9 +37,9 @@ const config: StorybookConfig = {
},
},
}),
webpackFinal: async (config) => {
webpackFinal: async (webpackConfig) => {
// Find and override CSS rule to use the devtool style injection
const cssRule = config.module?.rules?.find((rule) => {
const cssRule = webpackConfig.module?.rules?.find((rule) => {
if (typeof rule !== 'object' || !rule) return false
if ('test' in rule && rule.test instanceof RegExp) {
return rule.test.test('.css')
......@@ -77,7 +77,7 @@ const config: StorybookConfig = {
}
}
return config
return webpackConfig
},
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment