diff --git a/README.md b/README.md index 8437f83..f9ae19f 100644 --- a/README.md +++ b/README.md @@ -23,27 +23,6 @@ ESLint configuration is provided in the `eslint.config.js`, aka. "Flat Config" f ``` This will set up the necessary dependencies and configurations for you. -## Migration von v2 to v3 - -When upgrading from `@atmina/linting@^2` to `@^3` in a Next project, a few changes are currently required: -1. Add `@eslint/compat` as a dev-dependency to the Next project -2. Update your `eslint.config.js` by wrapping the next plugin's config with `fixupConfigRules`: -```diff -// For CJS -+ const {fixupConfigRules} = require('@eslint/compat'); -// ... -- require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next')), -+ ...fixupConfigRules( -+ require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next')), -+ ), - -// For ESM -import {fixupConfigRules} from '@eslint/compat'; -// ... -- next(nextPlugin), -+ fixupConfigRules(next(nextPlugin)), -``` - ## IDE Integration In VS Code, use these workspace settings: diff --git a/apps/compatibility-check/eslint.config.js b/apps/compatibility-check/eslint.config.js index 97c6d81..0737386 100644 --- a/apps/compatibility-check/eslint.config.js +++ b/apps/compatibility-check/eslint.config.js @@ -1,12 +1,8 @@ -const {fixupConfigRules} = require('@eslint/compat'); - /** * @type {import('eslint').Linter.FlatConfig[]} */ module.exports = [ ...require('@atmina/linting/eslint/recommended'), require('@atmina/linting/eslint/tailwind'), - ...fixupConfigRules( - require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next')), - ), + require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next')), ]; diff --git a/apps/compatibility-check/package.json b/apps/compatibility-check/package.json index 460e10f..a3dd7b8 100644 --- a/apps/compatibility-check/package.json +++ b/apps/compatibility-check/package.json @@ -19,7 +19,6 @@ }, "devDependencies": { "@atmina/linting": "workspace:*", - "@eslint/compat": "^1.2.0", "@next/eslint-plugin-next": "^14.2.14", "@types/eslint": "9.6.1", "@types/node": "^20", diff --git a/packages/linting/bin/linting.mjs b/packages/linting/bin/linting.mjs index dc7eced..7e08f3f 100644 --- a/packages/linting/bin/linting.mjs +++ b/packages/linting/bin/linting.mjs @@ -91,11 +91,7 @@ const createConfig = (pkg) => { imports.push(`import nextPlugin from '@next/eslint-plugin-next'`); configs.push('next(nextPlugin)'); } else { - // TODO - Remove compat layer once https://github.com/vercel/next.js/issues/64409 is closed - imports.push(`const {fixupConfigRules} = require('@eslint/compat')`); - configs.push( - `...fixupConfigRules(require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next')))`, - ); + configs.push(`require('@atmina/linting/eslint/next')(require('@next/eslint-plugin-next'))`); } } @@ -130,8 +126,6 @@ const main = async () => { 'prettier', // Enables autocomplete in eslint.config.js '@types/eslint', - // Required for linting next - TODO remove once https://github.com/vercel/next.js/issues/64409 is merged - '@eslint/compat', '@atmina/linting', ]); diff --git a/packages/linting/eslint/next.js b/packages/linting/eslint/next.js index 8af708f..b493443 100644 --- a/packages/linting/eslint/next.js +++ b/packages/linting/eslint/next.js @@ -1,13 +1,14 @@ const react = require('./react'); +const {fixupConfigRules} = require('@eslint/compat'); /** - * @type {(nextPlugin: import('eslint').ESLint.Plugin) => import('eslint').Linter.FlatConfig} + * @type {(nextPlugin: import('eslint').ESLint.Plugin) => import('@eslint/compat').FixupConfig} */ module.exports = (nextPlugin) => { // We don't want to add the Next.js plugin as a dependency, so we just ask // the caller to provide it (attempting to `require()` it here would // fail). - return { + return fixupConfigRules({ files: ['**/*.{ts,tsx,js,jsx}'], plugins: {'@next/next': nextPlugin, ...react.plugins}, settings: {...react.settings}, @@ -16,5 +17,7 @@ module.exports = (nextPlugin) => { ...nextPlugin.configs['core-web-vitals'].rules, ...react.rules, }, - }; + // fixupConfigRules always returns an array. Since we only pass one object, it should be safe to just return the first + // element to avoid a breaking change + })[0]; }; diff --git a/packages/linting/package.json b/packages/linting/package.json index f8019de..8efe6c2 100644 --- a/packages/linting/package.json +++ b/packages/linting/package.json @@ -1,6 +1,6 @@ { "name": "@atmina/linting", - "version": "3.0.0", + "version": "2.3.0", "description": "A collection of opinionated in-house linting rules.", "main": "index.js", "scripts": {}, @@ -21,6 +21,7 @@ "author": "ATMINA Solutions GmbH ", "license": "MIT", "devDependencies": { + "@eslint/compat": "^1.2.0", "@types/eslint": "9.6.1", "@types/node": "20.16.10", "@types/prettier": "3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a8d3eed..3832d2c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,9 +23,6 @@ importers: '@atmina/linting': specifier: workspace:* version: link:../../packages/linting - '@eslint/compat': - specifier: ^1.2.0 - version: 1.2.0(eslint@8.57.1) '@next/eslint-plugin-next': specifier: ^14.2.14 version: 14.2.14 @@ -102,6 +99,9 @@ importers: specifier: ^5.0.0 version: 5.0.0 devDependencies: + '@eslint/compat': + specifier: ^1.2.0 + version: 1.2.0(eslint@9.12.0(jiti@1.21.0)) '@types/eslint': specifier: 9.6.1 version: 9.6.1 @@ -1838,9 +1838,9 @@ snapshots: '@eslint-community/regexpp@4.11.0': {} - '@eslint/compat@1.2.0(eslint@8.57.1)': + '@eslint/compat@1.2.0(eslint@9.12.0(jiti@1.21.0))': optionalDependencies: - eslint: 8.57.1 + eslint: 9.12.0(jiti@1.21.0) '@eslint/config-array@0.18.0': dependencies: @@ -2570,7 +2570,7 @@ snapshots: '@typescript-eslint/parser': 8.0.0(eslint@8.57.1)(typescript@5.6.2) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.1) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1))(eslint@8.57.1) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.1) eslint-plugin-jsx-a11y: 6.10.0(eslint@8.57.1) eslint-plugin-react: 7.34.2(eslint@8.57.1) @@ -2593,7 +2593,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.1): + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1))(eslint@8.57.1): dependencies: debug: 4.3.4 enhanced-resolve: 5.16.1 @@ -2645,7 +2645,7 @@ snapshots: '@typescript-eslint/parser': 8.0.0(eslint@8.57.1)(typescript@5.6.2) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.1) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@8.0.0(eslint@8.57.1)(typescript@5.6.2))(eslint@8.57.1))(eslint@8.57.1) transitivePeerDependencies: - supports-color