-
Notifications
You must be signed in to change notification settings - Fork 2
/
eslint.config.js
158 lines (151 loc) · 5.42 KB
/
eslint.config.js
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
151
152
153
154
155
156
157
158
import jsPlugin from '@eslint/js';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import prettierConfig from 'eslint-config-prettier';
import cypressPlugin from 'eslint-plugin-cypress';
import deprecationPlugin from 'eslint-plugin-deprecation';
import importPlugin from 'eslint-plugin-import';
import jestPlugin from 'eslint-plugin-jest';
import jestDOMPlugin from 'eslint-plugin-jest-dom';
import markdownPlugin from 'eslint-plugin-markdown';
import testingLibraryPlugin from 'eslint-plugin-testing-library';
import tsSortKeysPlugin from 'eslint-plugin-typescript-sort-keys';
import globals from 'globals';
export default [
jsPlugin.configs.recommended,
prettierConfig,
// Global ignores
{
ignores: ['dist/', 'vitest.config.ts', 'public/'],
},
// General rules
{
files: ['**/*.{js,jsx,ts,tsx}'],
languageOptions: {
globals: {
...globals.browser,
},
},
rules: {
'no-shadow': 'error',
'prefer-const': ['error', { destructuring: 'all' }],
'sort-keys': 'warn',
},
},
// Plugin Import
// source: https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561
{
languageOptions: {
parserOptions: {
// Eslint doesn't supply ecmaVersion in `parser.js` `context.parserOptions`
// This is required to avoid ecmaVersion < 2015 error or 'import' / 'export' error
ecmaVersion: 'latest',
sourceType: 'module',
},
},
plugins: { import: importPlugin },
rules: {
...importPlugin.configs.recommended.rules,
// TODO enable this once https://github.com/import-js/eslint-plugin-import/pull/2813 is merged + published
// 'import/extensions': ['error', 'ignorePackages'],
'import/order': [
'error',
{
alphabetize: { caseInsensitive: true, order: 'asc' },
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
],
'newlines-between': 'always',
},
],
},
settings: {
'import/internal-regex': '^~/',
'import/parsers': {
espree: ['.js', '.cjs', '.mjs', '.jsx'],
},
'import/resolver': {
node: { extensions: ['.ts', '.tsx'] },
typescript: { alwaysTryTypes: true },
},
},
},
// Typescript
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tsParser,
parserOptions: { project: ['./tsconfig.json'] },
},
plugins: {
'@typescript-eslint': tsPlugin,
deprecation: deprecationPlugin,
import: importPlugin,
'typescript-sort-keys': tsSortKeysPlugin,
},
rules: {
...tsPlugin.configs.recommended.rules,
...tsPlugin.configs.stylistic.rules,
...deprecationPlugin.configs.recommended.rules,
...importPlugin.configs.recommended.rules,
...importPlugin.configs.typescript.rules,
...tsSortKeysPlugin.configs.recommended.rules,
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{ ignorePrimitives: { boolean: true, string: true } },
],
'@typescript-eslint/strict-boolean-expressions': [
'error',
{ allowNullableBoolean: true, allowNullableString: true },
],
},
},
// Markdown
{
files: ['**/*.md'],
plugins: { markdown: markdownPlugin },
processor: 'markdown/markdown',
// The markdown plugin exposes three configuration blocks and is supposed
// to be included as ...markdownPlugin.configs.recommended, but doing so in
// this config makes it so that issues in markdown code blocks are missed.
rules: markdownPlugin.configs.recommended[2].rules,
},
// Jest/Vitest
{
files: ['**/*.test.{js,jsx,ts,tsx}'],
plugins: {
jest: jestPlugin,
'jest-dom': jestDOMPlugin,
'testing-library': testingLibraryPlugin,
},
rules: {
...jestPlugin.configs.recommended.rules,
...jestDOMPlugin.configs.recommended.rules,
...testingLibraryPlugin.configs.react.rules,
},
settings: {
jest: {
// we're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but it means we have to explicitly
// set the jest version.
version: 28,
},
},
},
// Cypress
{
files: ['cypress/**/*.ts'],
plugins: { cypress: cypressPlugin },
rules: cypressPlugin.configs.recommended.rules,
},
];