-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheslint.config.js
More file actions
133 lines (130 loc) · 4.1 KB
/
eslint.config.js
File metadata and controls
133 lines (130 loc) · 4.1 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
128
129
130
131
132
133
import { fileURLToPath } from 'node:url'
import { includeIgnoreFile } from '@eslint/compat'
import js from '@eslint/js'
import stylistic from '@stylistic/eslint-plugin'
import { defineConfig } from 'eslint/config'
import importPlugin from 'eslint-plugin-import'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import { reactRefresh } from 'eslint-plugin-react-refresh'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import storybook from 'eslint-plugin-storybook'
import globals from 'globals'
import tseslint from 'typescript-eslint'
const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url))
export default defineConfig([
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'),
{
// eslint for js and ts files
files: ['**/*.{ts,tsx,js}'],
languageOptions: { globals: { ...globals.browser } },
extends: [
js.configs.recommended,
],
rules: {
eqeqeq: ['error', 'always', { null: 'ignore' }],
'func-style': ['error', 'declaration', { allowTypeAnnotation: true }],
'prefer-destructuring': ['error', { object: true, array: false }],
},
},
{
// stylistic rules
extends: [
stylistic.configs.recommended,
],
rules: {
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
},
],
'@stylistic/jsx-self-closing-comp': 'error',
'@stylistic/quote-props': ['error', 'as-needed'],
},
},
{
// sort the imports
files: ['**/*.{ts,tsx,js}'],
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
},
},
{
// ensure imports consistently have an extension
plugins: {
import: importPlugin,
},
rules: {
'import/extensions': ['error', 'ignorePackages'],
},
},
{
// typescript only
files: ['**/*.{ts,tsx}'],
languageOptions: {
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
react,
'react-hooks': reactHooks,
},
extends: [
tseslint.configs.strictTypeChecked,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite(),
],
rules: {
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-deprecated': 'error',
// allow using any - see row.ts - it's not easy to replace with unknown for example
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/switch-exhaustiveness-check': ['error', { allowDefaultCaseForExhaustiveSwitch: false }],
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
},
settings: { react: { version: 'detect' } },
},
{
// typescript stylistic rules
files: ['**/*.{ts,tsx}'],
extends: [
tseslint.configs.stylisticTypeChecked,
],
},
{
// tests only
files: ['test/**/*.{ts,tsx}', '**/*.test.{ts,tsx}'],
rules: {
// fix an issue with vi.fn in an object (localStorage mock in our tests): see https://github.com/vitest-dev/eslint-plugin-vitest/issues/591
'@typescript-eslint/unbound-method': 'off',
},
},
{
// storybook stories
files: ['**/*.stories.tsx'],
extends: [
storybook.configs['flat/recommended'],
],
},
])