-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy patheslint.config.js
More file actions
127 lines (118 loc) · 3.03 KB
/
eslint.config.js
File metadata and controls
127 lines (118 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// @ts-check
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import vitest from '@vitest/eslint-plugin';
import { defineConfig, globalIgnores } from 'eslint/config';
import prettierConfig from 'eslint-config-prettier/flat';
import { importX } from 'eslint-plugin-import-x';
import nodePlugin from 'eslint-plugin-n';
import globals from 'globals';
import tseslint from 'typescript-eslint';
const __dirname = dirname(fileURLToPath(import.meta.url));
const config = defineConfig(
js.configs.recommended,
tseslint.configs.recommendedTypeChecked,
importX.flatConfigs.recommended,
importX.flatConfigs.typescript,
nodePlugin.configs['flat/recommended'],
{
name: 'Language options',
files: ['**/*.{js,mjs,cjs,ts,mts}'],
languageOptions: {
globals: {
...globals.node,
},
ecmaVersion: 'latest',
sourceType: 'module',
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
},
{
name: 'Rules overrides for all files',
rules: {
// Base
'max-lines-per-function': 'off',
'no-console': 'warn',
// TypeScript
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-use-before-define': 'off',
// Import
'import-x/order': [
'warn',
{
groups: [
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'object',
'type',
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],
'import-x/first': 'error',
'import-x/no-empty-named-blocks': 'error',
'import-x/no-extraneous-dependencies': 'error',
'import-x/no-mutable-exports': 'error',
'import-x/no-named-default': 'error',
'import-x/no-relative-packages': 'warn',
// Node
// This one is covered by TypeScript
'n/no-missing-import': 'off',
},
},
{
name: 'Rule overrides only for TypeScript files',
files: ['**/*.{ts,mts}'],
rules: {
// Rules enabled by `import-x/recommended` but are better handled by
// TypeScript and typescript-eslint.
'import-x/default': 'off',
'import-x/export': 'off',
'import-x/namespace': 'off',
'import-x/no-unresolved': 'off',
},
},
{
name: 'Vitest config',
files: ['**/*.test.ts', '**/*.test.js'],
...vitest.configs.recommended,
rules: {
...vitest.configs.recommended.rules,
'vitest/padding-around-all': 'warn',
},
},
{
name: 'Plain JS',
files: ['**/*.{js,mjs,cjs}'],
extends: [tseslint.configs.disableTypeChecked],
},
{
name: 'Config files',
files: ['**/*rc*.{js,mjs,cjs}', '**/*.config.{js,cjs,mjs,ts}'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'import-x/no-named-as-default-member': 'off',
},
},
globalIgnores(['**/coverage/', '**/dist/']),
prettierConfig // must always be the last one
);
export default config;