Skip to content

Commit 48800a5

Browse files
authored
chore: move to eslint flat config (#435)
1 parent 87e9c2b commit 48800a5

File tree

8 files changed

+707
-1338
lines changed

8 files changed

+707
-1338
lines changed

.eslintignore

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

.eslintrc.cjs

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

eslint.config.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// @ts-check
2+
import { builtinModules } from 'node:module'
3+
import eslint from '@eslint/js'
4+
import pluginN from 'eslint-plugin-n'
5+
import pluginImportX from 'eslint-plugin-import-x'
6+
import pluginRegExp from 'eslint-plugin-regexp'
7+
import tseslint from 'typescript-eslint'
8+
import globals from 'globals'
9+
10+
export default tseslint.config(
11+
{
12+
ignores: ['**/dist/**', '**/playground-temp/**', '**/temp/**'],
13+
},
14+
eslint.configs.recommended,
15+
...tseslint.configs.recommended,
16+
...tseslint.configs.stylistic,
17+
pluginN.configs['flat/recommended'],
18+
pluginRegExp.configs['flat/recommended'],
19+
{
20+
name: 'main',
21+
languageOptions: {
22+
parser: tseslint.parser,
23+
parserOptions: {
24+
sourceType: 'module',
25+
ecmaVersion: 2021,
26+
},
27+
globals: {
28+
...globals.es2021,
29+
...globals.node,
30+
},
31+
},
32+
plugins: {
33+
n: pluginN,
34+
'import-x': pluginImportX,
35+
},
36+
rules: {
37+
eqeqeq: ['warn', 'always', { null: 'never' }],
38+
'no-debugger': ['error'],
39+
'no-empty': ['warn', { allowEmptyCatch: true }],
40+
'prefer-const': [
41+
'warn',
42+
{
43+
destructuring: 'all',
44+
},
45+
],
46+
47+
'n/no-process-exit': 'off',
48+
'n/no-deprecated-api': 'off',
49+
'n/no-unpublished-import': 'off',
50+
'n/no-unpublished-require': 'off',
51+
'n/no-unsupported-features/es-syntax': 'off',
52+
'n/no-missing-import': [
53+
'error',
54+
{
55+
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'],
56+
},
57+
],
58+
59+
'@typescript-eslint/explicit-module-boundary-types': [
60+
'error',
61+
{ allowArgumentsExplicitlyTypedAsAny: true },
62+
],
63+
'@typescript-eslint/no-empty-function': [
64+
'error',
65+
{ allow: ['arrowFunctions'] },
66+
],
67+
'@typescript-eslint/no-empty-interface': 'off',
68+
'@typescript-eslint/no-explicit-any': 'off',
69+
'no-extra-semi': 'off',
70+
'@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier
71+
'@typescript-eslint/no-inferrable-types': 'off',
72+
'@typescript-eslint/no-unused-vars': [
73+
'error',
74+
{
75+
args: 'all',
76+
argsIgnorePattern: '^_',
77+
caughtErrors: 'all',
78+
caughtErrorsIgnorePattern: '^_',
79+
destructuredArrayIgnorePattern: '^_',
80+
varsIgnorePattern: '^_',
81+
ignoreRestSiblings: true,
82+
},
83+
],
84+
'@typescript-eslint/no-var-requires': 'off',
85+
'@typescript-eslint/consistent-type-imports': [
86+
'error',
87+
{ prefer: 'type-imports', disallowTypeAnnotations: false },
88+
],
89+
// disable rules set in @typescript-eslint/stylistic which conflict with current code
90+
// we should discuss if we want to enable these as they encourage consistent code
91+
'@typescript-eslint/array-type': 'off',
92+
'@typescript-eslint/consistent-type-definitions': 'off',
93+
'@typescript-eslint/prefer-for-of': 'off',
94+
'@typescript-eslint/prefer-function-type': 'off',
95+
96+
'import-x/no-nodejs-modules': [
97+
'error',
98+
{ allow: builtinModules.map((mod) => `node:${mod}`) },
99+
],
100+
'import-x/no-duplicates': 'error',
101+
'import-x/order': 'error',
102+
'sort-imports': [
103+
'error',
104+
{
105+
ignoreCase: false,
106+
ignoreDeclarationSort: true,
107+
ignoreMemberSort: false,
108+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
109+
allowSeparatedGroups: false,
110+
},
111+
],
112+
113+
'regexp/prefer-regexp-exec': 'error',
114+
'regexp/prefer-regexp-test': 'error',
115+
// in some cases using explicit letter-casing is more performant than the `i` flag
116+
'regexp/use-ignore-case': 'off',
117+
},
118+
},
119+
{
120+
name: 'vite/globals',
121+
files: ['packages/**/*.?([cm])[jt]s?(x)'],
122+
ignores: ['**/__tests__/**'],
123+
rules: {
124+
'no-restricted-globals': ['error', 'require', '__dirname', '__filename'],
125+
},
126+
},
127+
{
128+
name: 'disables/playground',
129+
files: [
130+
'playground/**/*.?([cm])[jt]s?(x)',
131+
'packages/plugin-react-swc/playground/**/*.?([cm])[jt]s?(x)',
132+
],
133+
rules: {
134+
'n/no-extraneous-import': 'off',
135+
'n/no-extraneous-require': 'off',
136+
'n/no-missing-import': 'off',
137+
'n/no-missing-require': 'off',
138+
'n/no-unsupported-features/es-builtins': 'off',
139+
'n/no-unsupported-features/node-builtins': 'off',
140+
'@typescript-eslint/explicit-module-boundary-types': 'off',
141+
'@typescript-eslint/no-unused-expressions': 'off',
142+
'@typescript-eslint/no-unused-vars': 'off',
143+
'no-undef': 'off',
144+
'no-empty': 'off',
145+
'no-constant-condition': 'off',
146+
'@typescript-eslint/no-empty-function': 'off',
147+
},
148+
},
149+
{
150+
name: 'disables/js',
151+
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
152+
rules: {
153+
'@typescript-eslint/explicit-module-boundary-types': 'off',
154+
'@typescript-eslint/no-unused-vars': 'off',
155+
},
156+
},
157+
{
158+
name: 'disables/dts',
159+
files: ['**/*.d.ts'],
160+
rules: {
161+
'@typescript-eslint/consistent-indexed-object-style': 'off',
162+
'@typescript-eslint/triple-slash-reference': 'off',
163+
},
164+
},
165+
)

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,24 @@
3232
"ci-publish": "tsx scripts/publishCI.ts"
3333
},
3434
"devDependencies": {
35-
"@eslint-types/import": "^2.29.1",
36-
"@eslint-types/typescript-eslint": "^7.5.0",
35+
"@eslint/js": "^9.22.0",
3736
"@types/fs-extra": "^11.0.4",
3837
"@types/node": "^20.17.7",
39-
"@typescript-eslint/eslint-plugin": "^7.18.0",
40-
"@typescript-eslint/parser": "^7.18.0",
4138
"@vitejs/release-scripts": "^1.3.2",
42-
"eslint": "^8.57.1",
43-
"eslint-define-config": "^2.1.0",
44-
"eslint-plugin-import": "^2.31.0",
45-
"eslint-plugin-n": "^17.14.0",
39+
"eslint": "^9.22.0",
40+
"eslint-plugin-import-x": "^4.8.0",
41+
"eslint-plugin-n": "^17.16.2",
4642
"eslint-plugin-regexp": "^2.7.0",
4743
"fs-extra": "^11.2.0",
44+
"globals": "^16.0.0",
4845
"lint-staged": "^15.2.10",
4946
"picocolors": "^1.1.1",
5047
"playwright-chromium": "^1.51.1",
5148
"prettier": "^3.0.3",
5249
"simple-git-hooks": "^2.11.1",
5350
"tsx": "^4.19.2",
5451
"typescript": "^5.7.2",
52+
"typescript-eslint": "^8.26.1",
5553
"vite": "^6.0.0",
5654
"vitest": "^3.0.4"
5755
},

packages/plugin-react/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// eslint-disable-next-line import/no-duplicates
21
import type * as babelCore from '@babel/core'
3-
// eslint-disable-next-line import/no-duplicates
42
import type { ParserOptions, TransformOptions } from '@babel/core'
53
import { createFilter } from 'vite'
64
import type {

playground/ssr-react/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function listenNavigation(onNavigation) {
5757
* @param {MouseEvent} e
5858
*/
5959
function onClick(e) {
60-
let link = e.target.closest('a')
60+
const link = e.target.closest('a')
6161
if (
6262
link &&
6363
link instanceof HTMLAnchorElement &&

0 commit comments

Comments
 (0)