Skip to content

Commit

Permalink
fix: wrap config ourselves, clean up migration guide, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarendorff2 committed Oct 7, 2024
1 parent 7e760e5 commit 252d69c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 46 deletions.
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 1 addition & 5 deletions apps/compatibility-check/eslint.config.js
Original file line number Diff line number Diff line change
@@ -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')),
];
1 change: 0 additions & 1 deletion apps/compatibility-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 1 addition & 7 deletions packages/linting/bin/linting.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'))`);
}
}

Expand Down Expand Up @@ -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',
]);

Expand Down
9 changes: 6 additions & 3 deletions packages/linting/eslint/next.js
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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];
};
3 changes: 2 additions & 1 deletion packages/linting/package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -21,6 +21,7 @@
"author": "ATMINA Solutions GmbH <[email protected]>",
"license": "MIT",
"devDependencies": {
"@eslint/compat": "^1.2.0",
"@types/eslint": "9.6.1",
"@types/node": "20.16.10",
"@types/prettier": "3.0.0",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 252d69c

Please sign in to comment.