Skip to content

Commit

Permalink
feature: Migrate next config to flat config format
Browse files Browse the repository at this point in the history
  • Loading branch information
Karibash committed Jul 29, 2024
1 parent 24c0956 commit 583d03e
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-mails-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agaroot/eslint-config-next": major
---

Migrate next config to flat config format
9 changes: 0 additions & 9 deletions packages/next/.eslintrc.cjs

This file was deleted.

49 changes: 24 additions & 25 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,37 @@ Use this setting to ensure consistent code writing and maintain high code qualit
## 🚀 Installation

```shell
$ npm install -D @agaroot/eslint-config-next
npm install -D eslint @agaroot/eslint-config-common @agaroot/eslint-config-definer @agaroot/eslint-config-javascript @agaroot/eslint-config-next @agaroot/eslint-config-react

# Needs install peer dependencies
$ npm install -D @next/eslint-plugin-next
# If you are using TypeScript, install the following package.
npm install -D @agaroot/eslint-config-typescript
```

## 👏 Getting Started

Create a `.eslintrc.js` file in the root directory of your project, and add `@agaroot/eslint-config-next` to the `extends` array.

The following is the recommended configuration when using TypeScript.
Create a `eslint.config.js` file in the root directory of your project.

```js
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
'@agaroot/eslint-config-common',
'@agaroot/eslint-config-react',
'@agaroot/eslint-config-next',
],
parserOptions: {
project: './tsconfig.json',
},
settings: {
'import/resolver': {
typescript: {
project: './tsconfig.json',
},
},
},
};
import { common } from '@agaroot/eslint-config-common';
import { define } from '@agaroot/eslint-config-definer';
import { javascript } from '@agaroot/eslint-config-javascript';
import { next } from '@agaroot/eslint-config-next';
import { react } from '@agaroot/eslint-config-react';
import { typescript } from '@agaroot/eslint-config-typescript';

const config = define([
common,
javascript,
next,
react,
// If you are using TypeScript, add the following line.
typescript,
]);

export default config({
// If you are using TypeScript, add the following line.
tsconfigPath: './tsconfig.json',
});
```

## 🤝 Contributing
Expand Down
14 changes: 14 additions & 0 deletions packages/next/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { common } from '@agaroot/eslint-config-common';
import { define } from '@agaroot/eslint-config-definer';
import { javascript } from '@agaroot/eslint-config-javascript';
import { typescript } from '@agaroot/eslint-config-typescript';

const config = define([
common,
javascript,
typescript,
]);

export default config({
tsconfigPath: './tsconfig.json',
});
6 changes: 0 additions & 6 deletions packages/next/index.cjs

This file was deleted.

48 changes: 35 additions & 13 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@agaroot/eslint-config-next",
"type": "module",
"version": "2.1.1",
"description": "ESLint config for AGAROOT",
"keywords": [
Expand All @@ -22,30 +23,51 @@
"url": "git+https://github.com/agaroot-technologies/eslint-config.git"
},
"license": "MIT",
"main": "index.cjs",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"exports": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"files": [
"index.cjs",
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"lint": "eslint . --ext .js,.cjs"
"build": "pkgroll",
"lint": "eslint ."
},
"dependencies": {
"@next/eslint-plugin-next": "^14.2.5"
},
"devDependencies": {
"@agaroot/eslint-config-common": "workspace:*",
"@next/eslint-plugin-next": "14.2.5",
"@typescript-eslint/eslint-plugin": "7.17.0",
"@typescript-eslint/parser": "7.17.0",
"@agaroot/eslint-config-definer": "workspace:*",
"@agaroot/eslint-config-javascript": "workspace:*",
"@agaroot/eslint-config-typescript": "workspace:*",
"@tsconfig/strictest": "2.0.5",
"@types/eslint": "8.56.11",
"eslint": "8.57.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "6.9.0",
"eslint-plugin-react": "7.35.0",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-unused-imports": "3.2.0"
"pkgroll": "2.4.1"
},
"peerDependencies": {
"@next/eslint-plugin-next": "^13.0.0 || ^14.0.0",
"@agaroot/eslint-config-common": "workspace:*",
"@agaroot/eslint-config-javascript": "workspace:*",
"@agaroot/eslint-config-react": "workspace:*",
"@agaroot/eslint-config-typescript": "workspace:*",
"eslint": "^8.0.0"
},
"peerDependenciesMeta": {
"@agaroot/eslint-config-typescript": {
"optional": true
}
}
}
23 changes: 23 additions & 0 deletions packages/next/src/configurators/next-configurator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import eslintPluginNext from '@next/eslint-plugin-next';

import type { Configurator } from '@agaroot/eslint-config-definer';
import type { ESLint, Linter } from 'eslint';

export const nextConfigurator: Configurator = () => {
return [
{
name: '@next/next/core-web-vitals',
plugins: {
'@next/next': eslintPluginNext as ESLint.Plugin,
},
rules: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginNext.configs.recommended.rules as Linter.RulesRecord,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginNext.configs['core-web-vitals'].rules as Linter.RulesRecord,
},
},
];
};
7 changes: 7 additions & 0 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { define } from '@agaroot/eslint-config-definer';

import { nextConfigurator } from './configurators/next-configurator';

export const next = define([
nextConfigurator,
]);
12 changes: 12 additions & 0 deletions packages/next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": [
"@tsconfig/strictest/tsconfig.json"
],
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true
}
}
77 changes: 27 additions & 50 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 583d03e

Please sign in to comment.