Skip to content

Commit

Permalink
Add an experimental flat config support
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Sep 24, 2024
1 parent 63a6921 commit 500a008
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 1 deletion.
24 changes: 24 additions & 0 deletions base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ Add `@herp-inc` to the `extends` section of your [ESLint configuration](http://e
}
}
```

## [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files) support (experimental)

> [!WARNING]
> This feature is still experimental, and thus may encounter breaking changes even in a minor version.
Make sure that the following packages are installed as peer dependencies.

| Package | Version |
| -------------------------------------------------------------------------------- | ---------------- |
| [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) | `^8.56.0 \|\| 9` |
| [`eslint`](https://www.npmjs.com/package/eslint) | `^8.56.0 \|\| 9` |
| [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier) | `9` |
| [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import) | `^2.30.0` |
| [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | `7 \|\| 8` |

```eslint.config.js
import config from '@herp-inc/eslint-config/flat';

export default [
...config,
// Add your additional configurations here
];
```
53 changes: 53 additions & 0 deletions base/flat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import eslint from '@eslint/js';
import importPlugin from 'eslint-plugin-import';
import eslintConfigPrettier from 'eslint-config-prettier';
import tseslint from 'typescript-eslint';

import config from './index.js';

export default [
eslint.configs.recommended,
...tseslint
.config(
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
eslintConfigPrettier,
importPlugin.flatConfigs.recommended,
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': [
'.cjs',
'.cts',
'.ctsx',
'.js',
'.jsx',
'.mjs',
'.mts',
'.mtsx',
'.ts',
'.tsx',
],
},
},
},
{
rules: config.rules,
},
)
.map((config) => ({
...config,
files: ['**/*.{cts,ctsx,mts,mtsx,ts,tsx}'],
})),
{
files: ['**/*.d.ts', '**/*.d.*.ts'],
rules: {
'import/no-default-export': 'off',
},
},
];
20 changes: 19 additions & 1 deletion base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"version": "202409.0.0",
"description": "ESLint shareable config for TypeScript environments",
"main": "index.js",
"exports": {
".": {
"require": "./index.js"
},
"./flat": {
"import": "./flat.mjs"
}
},
"repository": {
"type": "git",
"url": "https://github.com/herp-inc/eslint-config"
Expand All @@ -19,10 +27,20 @@
},
"homepage": "https://github.com/herp-inc/eslint-config",
"peerDependencies": {
"@eslint/js": "^8.56.0 || 9",
"@typescript-eslint/eslint-plugin": "7 || 8",
"@typescript-eslint/parser": "7 || 8",
"eslint": "^8.56.0 || 9",
"eslint-config-prettier": "*",
"eslint-plugin-import": "^2.30.0"
"eslint-plugin-import": "^2.30.0",
"typescript-eslint": "7 || 8"
},
"peerDependenciesMeta": {
"@eslint/js": {
"optional": true
},
"typescript-eslint": {
"optional": true
}
}
}
23 changes: 23 additions & 0 deletions jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ Add `@herp-inc/eslint-config-jest` to the `extends` section of your [ESLint conf
]
}
```

## [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files) support (experimental)

> [!WARNING]
> This feature is still experimental, and thus may encounter breaking changes even in a minor version.
Make sure that the following packages are installed as peer dependencies.

| Package | Version |
| ------------------------------------------------------------------------ | ---------------- |
| [`eslint`](https://www.npmjs.com/package/eslint) | `^8.21.0 \|\| 9` |
| [`eslint-plugin-jest`](https://www.npmjs.com/package/eslint-plugin-jest) | `^28.8.0` |

```eslint.config.js
import config from '@herp-inc/eslint-config/flat';
import configJest from '@herp-inc/eslint-config-jest/flat';

export default [
...config,
...configJest,
// Add your additional configurations here
];
```
14 changes: 14 additions & 0 deletions jest/flat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import jest from 'eslint-plugin-jest';

import config from './index.js';

export default [
{
files: ['**/*.test.*'],
...jest.configs['flat/recommended'],
rules: {
...jest.configs['flat/recommended'].rules,
...config.rules,
},
},
];
8 changes: 8 additions & 0 deletions jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"version": "202409.0.0",
"description": "ESLint shareable config for Jest environments",
"main": "index.js",
"exports": {
".": {
"require": "./index.js"
},
"./flat": {
"import": "./flat.mjs"
}
},
"repository": {
"type": "git",
"url": "https://github.com/herp-inc/eslint-config"
Expand Down
24 changes: 24 additions & 0 deletions jsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,27 @@ Add `@herp-inc/eslint-config-jsx` to the `extends` section of your [ESLint confi
]
}
```

## [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files) support (experimental)

> [!WARNING]
> This feature is still experimental, and thus may encounter breaking changes even in a minor version.
Make sure that the following packages are installed as peer dependencies.

| Package | Version |
| -------------------------------------------------------------------------------- | ---------------- |
| [`eslint`](https://www.npmjs.com/package/eslint) | `^8.21.0 \|\| 9` |
| [`eslint-plugin-jsx-a11y`](https://www.npmjs.com/package/eslint-plugin-jsx-a11y) | `^6.9.0` |
| [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react) | `^7.35.0` |

```eslint.config.js
import config from '@herp-inc/eslint-config/flat';
import configJSX from '@herp-inc/eslint-config-jsx/flat';

export default [
...config,
...configJSX,
// Add your additional configurations here
];
```
13 changes: 13 additions & 0 deletions jsx/flat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import jsxA11y from 'eslint-plugin-jsx-a11y';

import config from './index.js';

export default [
jsxA11y.flatConfigs.recommended,
{
rules: config.rules,
},
].map((config) => ({
...config,
files: ['**/*.{ctsx,jsx,mtsx,tsx}'],
}));
8 changes: 8 additions & 0 deletions jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"version": "202409.0.0",
"description": "ESLint shareable config for JSX environments",
"main": "index.js",
"exports": {
".": {
"require": "./index.js"
},
"./flat": {
"import": "./flat.mjs"
}
},
"repository": {
"type": "git",
"url": "https://github.com/herp-inc/eslint-config"
Expand Down
23 changes: 23 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,26 @@ Add `@herp-inc/eslint-config-node` to the `extends` section of your [ESLint conf
"extends": ["@herp-inc", "@herp-inc/eslint-config-node"]
}
```

## [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files) support (experimental)

> [!WARNING]
> This feature is still experimental, and thus may encounter breaking changes even in a minor version.
Make sure that the following packages are installed as peer dependencies.

| Package | Version |
| ------------------------------------------------------------------ | ---------------- |
| [`eslint`](https://www.npmjs.com/package/eslint) | `^8.21.0 \|\| 9` |
| [`eslint-plugin-n`](https://www.npmjs.com/package/eslint-plugin-n) | `^17.10.0` |

```eslint.config.js
import config from '@herp-inc/eslint-config/flat';
import configNode from '@herp-inc/eslint-config-node/flat';

export default [
...config,
...configNode,
// Add your additional configurations here
];
```
10 changes: 10 additions & 0 deletions node/flat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import nodePlugin from 'eslint-plugin-n';

import config from './index.js';

export default [
nodePlugin.configs['flat/recommended'],
{
rules: config.rules,
},
];
8 changes: 8 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"version": "202409.0.0",
"description": "ESLint shareable config for Node.js environments",
"main": "index.js",
"exports": {
".": {
"require": "./index.js"
},
"./flat": {
"import": "./flat.mjs"
}
},
"repository": {
"type": "git",
"url": "https://github.com/herp-inc/eslint-config"
Expand Down

0 comments on commit 500a008

Please sign in to comment.