-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
150 lines (136 loc) · 3.9 KB
/
eslint.config.mjs
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import typescriptEslint from 'typescript-eslint'
import eslint from '@eslint/js'
import configPrettier from 'eslint-config-prettier'
import pluginImport from 'eslint-plugin-import'
import pluginJest from 'eslint-plugin-jest'
import pluginReact from 'eslint-plugin-react'
import pluginReactHooks from 'eslint-plugin-react-hooks'
// @ts-check
// Docs: https://eslint.org/docs/latest/use/configure/configuration-files
// Use `yarn lint-check --inspect-config` to launch web-based config inspector.
export default typescriptEslint.config([
{
name: 'global-ignores',
ignores: [
// - Implicitly contains '**/node_modules/' & '**/.git/.'.
// - Does not take .gitignore into account.
// - Paths are relative to project root (location of this config file).
'apps/*/build/',
'packages/*/dist/',
'.yarn/',
'.pnp.*',
'**/.history/',
],
},
//
// Core ESLint
//
eslint.configs.recommended,
{
name: 'core-rules',
rules: {
'arrow-body-style': ['warn', 'as-needed'],
curly: ['warn', 'all'],
eqeqeq: ['warn', 'always'],
'no-console': 'warn',
'sort-imports': ['warn', { ignoreDeclarationSort: true }],
'no-unused-vars': 'off', // Turned off in favor of TypeScript-specific version
},
settings: { react: { version: 'detect' } },
languageOptions: { globals: pluginJest.environments.globals.globals },
},
//
// TypeScript
//
// NOTE: 'recommendedTypeChecked' requires a build step before linting. Unfortunately there is no clear error if
// packages/react-hook-tracer/dist is missing, just lots of @typescript-eslint/no-unsafe-.. errors.
typescriptEslint.configs.recommendedTypeChecked,
{
name: 'typescript-rules',
languageOptions: {
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
},
{
// Disable type-aware linting for non-TypeScript files.
name: 'disable-type-aware-linting',
files: ['**/*.{js,cjs,mjs}'],
extends: [typescriptEslint.configs.disableTypeChecked],
},
//
// Import-plugin
//
pluginImport.flatConfigs.recommended,
{
name: 'import-rules',
rules: {
'import/no-unresolved': 'off', // handled by TypeScript
'import/order': [
'warn',
{
groups: [
['builtin', 'external'],
['internal'],
['parent'],
['sibling', 'index'],
['object', 'type'],
['unknown'],
],
'newlines-between': 'always',
warnOnUnassignedImports: true,
alphabetize: { order: 'asc' },
pathGroups: [
{
pattern: '?(react|react-dom|react-dom/client)',
group: 'builtin',
position: 'before',
},
{ pattern: './*.css', group: 'unknown', position: 'after' },
],
pathGroupsExcludedImportTypes: ['react', 'react-dom'],
},
],
},
},
//
// React
//
pluginReact.configs.flat.recommended,
pluginReactHooks.configs['recommended-latest'],
{
name: 'react-rules',
rules: {
'react/react-in-jsx-scope': 'off',
'react/no-unescaped-entities': 'off',
},
},
//
// Jest
//
{
name: 'jest-rules',
files: ['**/test/**/*.*', '**/*.test.*'],
extends: [pluginJest.configs['flat/recommended']],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'warn',
},
},
//
// Prettier
//
// Must be last to properly override other configs. Turns off rules that are handled by or conflict with prettier.
configPrettier,
])