-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
225 lines (209 loc) · 6.26 KB
/
Copy patheslint.config.mjs
File metadata and controls
225 lines (209 loc) · 6.26 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* eslint-disable perfectionist/sort-objects */
import eslint from '@eslint/js'
import json from '@eslint/json'
import markdown from '@eslint/markdown'
import pluginNext from '@next/eslint-plugin-next'
import tsPlugin from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import eslintConfigPrettier from 'eslint-config-prettier/flat'
import importPlugin from 'eslint-plugin-import'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import perfectionist from 'eslint-plugin-perfectionist'
import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import workspaces from 'eslint-plugin-workspaces'
import { defineConfig } from 'eslint/config'
import globals from 'globals'
const perfectionistImportGroups = {
customGroups: [
{
elementNamePattern: ['^~'],
groupName: 'type-parent',
selector: 'type',
},
{
elementNamePattern: ['^~'],
groupName: 'value-parent',
},
{
elementNamePattern: ['.css$'],
groupName: 'unknown',
},
],
internalPattern: ['^@meldingen'],
}
const perfectionistCustomGridPropsOrder = {
customGroups: [
{
groupName: 'narrow',
elementNamePattern: 'narrow',
},
{
groupName: 'medium',
elementNamePattern: 'medium',
},
{
groupName: 'wide',
elementNamePattern: 'wide',
},
],
groups: ['narrow', 'medium', 'wide'],
}
export default defineConfig(
// Global
{
ignores: [
// Ignore generated files
'**/vendor/',
'**/build/',
'**/coverage/',
'**/dist/',
'**/tmp/',
// Ignore generated api client
'libs/api-client',
// Next.js generated files
'**/.next/',
'**/next-env.d.ts',
],
},
{
languageOptions: {
globals: { ...globals.browser, ...globals.es6, ...globals.node, ...globals.vitest },
},
},
// JavaScript, TypeScript & React
{
files: ['**/*.{js,jsx,ts,tsx,mjs,cjs}'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
plugins: {
'@typescript-eslint': tsPlugin,
import: importPlugin,
'jsx-a11y': jsxA11y,
perfectionist,
'prefer-arrow-functions': preferArrowFunctions,
react,
'react-hooks': reactHooks,
workspaces,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
// This uses eslint-import-resolver-typescript
typescript: {},
node: {
extensions: ['js', 'jsx', 'ts', 'tsx'],
},
},
react: { version: 'detect' },
},
rules: {
...eslint.configs.recommended.rules,
...jsxA11y.configs.strict.rules,
...perfectionist.configs['recommended-natural'].rules,
...react.configs.recommended.rules,
...tsPlugin.configs.recommended.rules,
...workspaces.configs.recommended.rules,
// TypeScript
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['warn'],
// Import
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import/newline-after-import': 'error',
'import/no-cycle': 'error',
'import/no-default-export': 'error',
'import/no-named-as-default': 'error',
'no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@amsterdam/design-system-react', '@amsterdam/design-system-react/dist/Grid'],
importNames: ['Grid'],
message: 'Import Alert from @meldingen/ui',
},
{
group: ['@amsterdam/design-system-react', '@amsterdam/design-system-react/dist/Heading'],
importNames: ['Heading'],
message: 'Import Alert from @meldingen/ui',
},
],
},
],
// ESLint
'no-console': 'error',
'no-unused-vars': 'off', // Handled by @typescript-eslint/no-unused-vars
'prefer-arrow-functions/prefer-arrow-functions': 'error',
// Perfectionist
'perfectionist/sort-imports': ['error', perfectionistImportGroups],
'perfectionist/sort-modules': 'off', // This impacts readability in a negative way. We want to decide the order of modules ourselves.
'perfectionist/sort-objects': ['error', perfectionistCustomGridPropsOrder],
'perfectionist/sort-union-types': 'off', // This causes more issues than it solves
// React
'react/display-name': 'off',
'react/function-component-definition': 'off',
'react/jsx-props-no-spreading': 'off',
'react/react-in-jsx-scope': 'off',
'react/require-default-props': 'off',
'react-hooks/exhaustive-deps': 'warn',
'react-hooks/rules-of-hooks': 'error',
},
},
// Don't force using type over interface in .d.ts files
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/consistent-type-definitions': 'off',
},
},
// Don't force named exports for non-React files
{
files: ['**/*.{js,ts,mjs,cjs}'],
rules: {
'import/no-default-export': 'off',
},
},
// JSON
{
files: ['**/*.json'],
language: 'json/json',
plugins: { json },
...json.configs.recommended,
},
// Markdown
{
...markdown.configs.recommended[0],
language: 'markdown/gfm',
},
// Next.js apps
{
files: ['apps/melding-form/**/*', 'apps/back-office/**/*'],
plugins: {
'@next/next': pluginNext,
},
rules: {
...pluginNext.configs.recommended.rules,
...pluginNext.configs['core-web-vitals'].rules,
'@next/next/no-html-link-for-pages': ['error', ['apps/melding-form/src', 'apps/back-office/src']],
},
},
{
files: ['**/error.tsx', '**/page.tsx', '**/layout.tsx', '**/not-found.tsx'],
rules: {
'import/no-default-export': 'off',
},
},
// Global Prettier config. Defined here to make sure no other rules override it.
eslintConfigPrettier,
)