Skip to content

Commit 89a0a5d

Browse files
committed
refactor: eslint config approach
1 parent bc6620b commit 89a0a5d

File tree

7 files changed

+83
-62
lines changed

7 files changed

+83
-62
lines changed

eslint.config.mjs

Lines changed: 79 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,38 @@ import { fixupConfigRules } from '@eslint/compat';
44
import { FlatCompat } from '@eslint/eslintrc';
55
import js from '@eslint/js';
66
import { defineConfig, globalIgnores } from 'eslint/config';
7+
import prettierConfig from 'eslint-config-prettier/flat';
8+
import jest from 'eslint-plugin-jest';
9+
import * as jestFormatting from 'eslint-plugin-jest-formatting';
710
import globals from 'globals';
811
import tseslint from 'typescript-eslint';
912

1013
const compat = new FlatCompat({
1114
baseDirectory: import.meta.dirname,
12-
recommendedConfig: js.configs.recommended,
1315
});
1416

1517
const config = defineConfig(
18+
js.configs.recommended,
19+
tseslint.configs.recommendedTypeChecked,
1620
{
21+
name: 'Language options',
1722
languageOptions: {
1823
globals: {
19-
...globals.es2019,
24+
...globals.node,
25+
},
26+
parser: tseslint.parser,
27+
parserOptions: {
28+
projectService: true,
29+
tsconfigRootDir: import.meta.dirname,
2030
},
2131
},
22-
23-
extends: fixupConfigRules(
24-
compat.extends(
25-
'eslint:recommended',
26-
'plugin:import/recommended',
27-
'plugin:jest/recommended',
28-
'plugin:jest-formatting/recommended',
29-
'prettier'
30-
)
31-
),
32+
},
33+
{
34+
// TODO: replace import with import-x
35+
name: 'Import plugin config',
36+
extends: fixupConfigRules(compat.extends('plugin:import/recommended')),
3237

3338
rules: {
34-
'max-lines-per-function': 'off',
35-
3639
'import/order': [
3740
'warn',
3841
{
@@ -55,54 +58,84 @@ const config = defineConfig(
5558
},
5659
},
5760
{
58-
files: ['**/*.ts'],
59-
60-
languageOptions: {
61-
parser: tseslint.parser,
62-
parserOptions: {
63-
project: './tsconfig.eslint.json',
64-
tsconfigRootDir: import.meta.dirname,
65-
},
66-
},
67-
68-
extends: fixupConfigRules(
69-
compat.extends(
70-
'plugin:@typescript-eslint/recommended',
71-
'plugin:@typescript-eslint/recommended-type-checked',
72-
'plugin:import/typescript'
73-
)
74-
),
75-
61+
name: 'Rules overrides for all files',
7662
rules: {
77-
'@typescript-eslint/explicit-function-return-type': 'off',
63+
// Base
64+
'max-lines-per-function': 'off',
7865

66+
// TypeScript
67+
'@typescript-eslint/explicit-function-return-type': 'off',
7968
'@typescript-eslint/no-unused-vars': [
8069
'warn',
8170
{
8271
argsIgnorePattern: '^_',
8372
},
8473
],
85-
8674
'@typescript-eslint/no-use-before-define': 'off',
75+
},
76+
},
77+
{
78+
name: 'Rule overrides for TypeScript files',
79+
files: ['**/*.ts', '**/*.mts'],
80+
rules: {
81+
// Import
82+
// Rules enabled by `import/recommended` but are better handled by
83+
// TypeScript and @typescript-eslint.
8784
'import/default': 'off',
8885
'import/export': 'off',
8986
'import/namespace': 'off',
9087
'import/no-unresolved': 'off',
9188
},
92-
93-
settings: {
94-
'import/resolver': {
95-
node: {
96-
extensions: ['.js', '.ts'],
97-
},
98-
99-
typescript: {
100-
alwaysTryTypes: true,
101-
},
102-
},
89+
},
90+
// {
91+
// files: ['**/*.ts'],
92+
//
93+
// extends: fixupConfigRules(
94+
// compat.extends(
95+
// 'plugin:import/typescript'
96+
// )
97+
// ),
98+
//
99+
// rules: {
100+
// 'import/default': 'off',
101+
// 'import/export': 'off',
102+
// 'import/namespace': 'off',
103+
// 'import/no-unresolved': 'off',
104+
// },
105+
//
106+
// settings: {
107+
// 'import/resolver': {
108+
// node: {
109+
// extensions: ['.js', '.ts'],
110+
// },
111+
//
112+
// typescript: {
113+
// alwaysTryTypes: true,
114+
// },
115+
// },
116+
// },
117+
// },
118+
{
119+
name: 'Jest config',
120+
files: ['**/*.test.ts', '**/*.test.js'],
121+
...jest.configs['flat/recommended'],
122+
...jestFormatting.configs['flat/recommended'],
123+
},
124+
{
125+
name: 'Plain JS',
126+
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
127+
extends: [tseslint.configs.disableTypeChecked],
128+
},
129+
{
130+
name: 'Config files',
131+
files: ['./*.js', './*.cjs', './*.mjs', '**/*.config.*js'],
132+
rules: {
133+
'@typescript-eslint/no-require-imports': 'off',
134+
'import/no-unresolved': 'off',
103135
},
104136
},
105-
globalIgnores(['**/coverage/', '**/dist/'])
137+
globalIgnores(['**/coverage/', '**/dist/']),
138+
prettierConfig // must always be the last one
106139
);
107140

108141
export default config;

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
"@swc/jest": "^0.2.37",
6767
"@types/jest": "^29.5.14",
6868
"@types/node": "^22.9.3",
69-
"@typescript-eslint/eslint-plugin": "^8.43.0",
70-
"@typescript-eslint/parser": "^8.43.0",
7169
"@typescript-eslint/rule-tester": "^8.43.0",
7270
"del-cli": "^6.0.0",
7371
"eslint": "^9.35.0",

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/lib/test-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import tsESLintParser from '@typescript-eslint/parser';
21
import { RuleTester, RunTests } from '@typescript-eslint/rule-tester';
2+
import { parser } from 'typescript-eslint';
33

44
import { TestingLibraryPluginRuleModule } from '../../lib/utils';
55

@@ -35,7 +35,7 @@ class TestingLibraryRuleTester extends RuleTester {
3535
export const createRuleTester = () =>
3636
new TestingLibraryRuleTester({
3737
languageOptions: {
38-
parser: tsESLintParser,
38+
parser,
3939
parserOptions: {
4040
ecmaFeatures: {
4141
jsx: true,

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["./tests/**/*.ts"]
3+
"exclude": ["./tests", "./tools"]
44
}

tsconfig.eslint.json

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

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"outDir": "dist",
1717
"sourceMap": false
1818
},
19-
"include": ["./lib/**/*.ts", "./tests/**/*.ts"]
19+
"include": ["**/*.ts"]
2020
}

0 commit comments

Comments
 (0)