-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.mjs
133 lines (121 loc) · 3.49 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
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import tsParser from '@typescript-eslint/parser'
import eslintConfigPrettier from 'eslint-config-prettier'
import json from 'eslint-plugin-json'
import reactHooks from 'eslint-plugin-react-hooks'
import unusedImports from 'eslint-plugin-unused-imports'
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import tseslint from 'typescript-eslint'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})
// TODO: Once https://github.com/facebook/react/pull/30774 is closed,
// we can remove all compat things and fixup plugin rules.
// With a little bit of luck, alexg will remember what to do, but might need to
// be poked.
export default [
// Ignore options
{
ignores: [
'target/**',
'**/.vscode',
'**/__generated__/',
'**/node_modules/',
'**/build/',
'**/coverage/',
'**/dist/',
'**/bin/',
'**/*.log*',
'**/yarn.lock',
'**/.yarn/',
'**/.pnp.js',
],
},
// Plugin options
// eslint:recommended
js.configs.recommended,
// plugin/@typescript-eslint/recommended
...tseslint.configs.recommended,
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: { ...globals.node, ...globals.browser },
parser: tsParser,
},
},
// plugin:json/recommended
{
files: ['**/*.json'],
...json.configs['recommended'],
},
// plugin:react-hooks/recommended
// SEE: https://github.com/facebook/react/pull/30774
...fixupConfigRules(compat.extends('plugin:react-hooks/recommended')),
// Note: prettier needs to always be last in the list, it disables eslint style rules.
eslintConfigPrettier,
// Plugins
// unused-imports
{
plugins: {
'unused-imports': unusedImports,
},
rules: {
'@typescript-eslint/no-unused-vars': ['off'],
'unused-imports/no-unused-imports': ['error'],
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
},
// react-hooks
// SEE: https://github.com/facebook/react/pull/30774
{
plugins: {
'react-hooks': fixupPluginRules(reactHooks),
},
rules: {
curly: ['error'],
'spaced-comment': ['error', 'always'],
'no-restricted-syntax': [
'error',
{
selector: 'TSTypeAliasDeclaration[id.name=Props]',
message:
'Type declarations for props should be named to reflect what it is used for. Use\nProps as a suffix.\n',
},
{
selector: 'TSInterfaceDeclaration[id.name=Props]',
message:
'Interface declarations for props should be named to reflect what it is used for.\nUse Props as a suffix.\n',
},
],
// Use unused-imports instead of the built-in support
'@typescript-eslint/no-unused-vars': ['off'],
'unused-imports/no-unused-imports': ['error'],
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
},
]