Skip to content

Commit 7ddb177

Browse files
authored
repo: switch to flat config (#15)
We can use flat configs to lint the repo itself.
1 parent c835568 commit 7ddb177

File tree

5 files changed

+126
-56
lines changed

5 files changed

+126
-56
lines changed

.env.yarn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
ESLINT_USE_FLAT_CONFIG=false

.eslintrc.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

eslint.config.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
const eslintjs = require('@eslint/js');
2+
const { defineConfig } = require('eslint/config');
3+
const globals = require('globals');
4+
const eslintPlugin = require('eslint-plugin-eslint-plugin');
5+
const importPlugin = require('eslint-plugin-import-x');
6+
const flowPlugin = require('eslint-plugin-ft-flow');
7+
const { FlatCompat } = require('@eslint/eslintrc');
8+
const babelParser = require('@babel/eslint-parser');
9+
const prettierConfig = require('eslint-config-prettier');
10+
11+
const compat = new FlatCompat({
12+
baseDirectory: __dirname,
13+
});
14+
15+
module.exports = defineConfig([
16+
{
17+
ignores: ['lib', 'reports', 'examples'],
18+
},
19+
{
20+
files: [
21+
'src/**/*.js',
22+
'scripts/**/*.js',
23+
'__tests__/**/*.js',
24+
'__mocks__/**/*.js',
25+
],
26+
plugins: {
27+
eslint: eslintjs,
28+
'eslint-plugin': eslintPlugin,
29+
'ft-flow': flowPlugin,
30+
'import-x': importPlugin.flatConfigs.recommended.plugins['import-x'],
31+
},
32+
languageOptions: {
33+
globals: {
34+
...globals.node,
35+
},
36+
parser: babelParser,
37+
},
38+
extends: [
39+
eslintjs.configs.recommended,
40+
importPlugin.flatConfigs.recommended,
41+
],
42+
rules: {
43+
...prettierConfig.rules,
44+
'no-template-curly-in-string': 'off',
45+
'import-x/no-extraneous-dependencies': 'error',
46+
},
47+
settings: {
48+
'import-x/resolver': 'typescript',
49+
},
50+
},
51+
...compat.config(flowPlugin.configs.recommended).map(config => ({
52+
...config,
53+
files: [
54+
'src/**/*.js',
55+
'flow/*.js',
56+
'__mocks__/**/*.js',
57+
'__tests__/**/*.js',
58+
],
59+
})),
60+
{
61+
files: ['src/rules/*'],
62+
extends: [eslintPlugin.configs['flat/rules-recommended']],
63+
rules: {
64+
'eslint-plugin/require-meta-docs-description': [
65+
'error',
66+
{
67+
pattern: '^(Enforce|Require|Disallow)',
68+
},
69+
],
70+
'eslint-plugin/require-meta-docs-url': [
71+
'error',
72+
{
73+
pattern:
74+
'https://github.com/es-tooling/eslint-plugin-jsx-a11y-x/tree/HEAD/docs/rules/{{name}}.md',
75+
},
76+
],
77+
'eslint-plugin/require-meta-type': 'off',
78+
// disable temporarily
79+
'eslint-plugin/prefer-message-ids': 'off',
80+
},
81+
},
82+
{
83+
files: ['__tests__/src/rules/*.js'],
84+
extends: [eslintPlugin.configs['flat/tests-recommended']],
85+
},
86+
{
87+
files: ['__tests__/**/*'],
88+
languageOptions: {
89+
globals: {
90+
jest: true,
91+
},
92+
},
93+
},
94+
]);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"generate-list-of-rules": "eslint-doc-generator --rule-doc-title-format prefix-name --rule-doc-section-options false --config-emoji recommended,☑️ --ignore-config flat/recommended --ignore-config flat/strict",
3333
"lint": "yarn lint:js && yarn lint:docs",
3434
"lint:docs": "yarn generate-list-of-rules --check",
35-
"lint:js": "eslint .",
35+
"lint:js": "eslint",
3636
"lint:js:fix": "yarn lint:js --fix",
3737
"pregenerate-list-of-rules": "yarn build",
3838
"prepublishOnly": "yarn lint && yarn flow && yarn tests-only",
@@ -73,6 +73,7 @@
7373
"@babel/register": "^7.25.9",
7474
"@changesets/changelog-github": "^0.5.1",
7575
"@changesets/cli": "^2.29.4",
76+
"@eslint/eslintrc": "^3.3.1",
7677
"@eslint/js": "^9.26.0",
7778
"auto-changelog": "^2.5.0",
7879
"babel-plugin-add-module-exports": "^1.0.4",
@@ -87,6 +88,7 @@
8788
"eslint-plugin-import-x": "^4.11.1",
8889
"estraverse": "^5.3.0",
8990
"flow-bin": "^0.147.0",
91+
"hermes-eslint": "^0.28.1",
9092
"in-publish": "^2.0.1",
9193
"jackspeak": "=2.1.1",
9294
"jscodeshift": "^17.0.0",

yarn.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,6 +3805,7 @@ __metadata:
38053805
"@babel/register": "npm:^7.25.9"
38063806
"@changesets/changelog-github": "npm:^0.5.1"
38073807
"@changesets/cli": "npm:^2.29.4"
3808+
"@eslint/eslintrc": "npm:^3.3.1"
38083809
"@eslint/js": "npm:^9.26.0"
38093810
aria-query: "npm:^5.3.2"
38103811
array-includes: "npm:^3.1.8"
@@ -3828,6 +3829,7 @@ __metadata:
38283829
estraverse: "npm:^5.3.0"
38293830
flow-bin: "npm:^0.147.0"
38303831
hasown: "npm:^2.0.2"
3832+
hermes-eslint: "npm:^0.28.1"
38313833
in-publish: "npm:^2.0.1"
38323834
jackspeak: "npm:=2.1.1"
38333835
jscodeshift: "npm:^17.0.0"
@@ -4549,6 +4551,33 @@ __metadata:
45494551
languageName: node
45504552
linkType: hard
45514553

4554+
"hermes-eslint@npm:^0.28.1":
4555+
version: 0.28.1
4556+
resolution: "hermes-eslint@npm:0.28.1"
4557+
dependencies:
4558+
esrecurse: "npm:^4.3.0"
4559+
hermes-estree: "npm:0.28.1"
4560+
hermes-parser: "npm:0.28.1"
4561+
checksum: 10c0/1998bb1e957be3f2b5f195e77d25999085cf658509b2c51c191b3cf752a45f4f93561e175a70ccf0c3f590db5d09a827e0e3cfe7b8470f123ee757ffd1f884df
4562+
languageName: node
4563+
linkType: hard
4564+
4565+
"hermes-estree@npm:0.28.1":
4566+
version: 0.28.1
4567+
resolution: "hermes-estree@npm:0.28.1"
4568+
checksum: 10c0/aa00f437c82099b9043e384b529c75de21d0111b792ab7480fe992975b5f9535a8581664789db197824a7825ea66d2fd70eb20cb568c5315804421deaf009500
4569+
languageName: node
4570+
linkType: hard
4571+
4572+
"hermes-parser@npm:0.28.1":
4573+
version: 0.28.1
4574+
resolution: "hermes-parser@npm:0.28.1"
4575+
dependencies:
4576+
hermes-estree: "npm:0.28.1"
4577+
checksum: 10c0/c6d3c01fb1ea5232f4587b6b038f5c2c6414932e7c48efbe156ab160e2bcaac818c9eb2f828f30967a24b40f543cad503baed0eedf5a7e877852ed271915981f
4578+
languageName: node
4579+
linkType: hard
4580+
45524581
"http-cache-semantics@npm:^4.1.1":
45534582
version: 4.2.0
45544583
resolution: "http-cache-semantics@npm:4.2.0"

0 commit comments

Comments
 (0)