-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheslint.config.mjs
More file actions
197 lines (193 loc) · 5.93 KB
/
Copy patheslint.config.mjs
File metadata and controls
197 lines (193 loc) · 5.93 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
import nx from '@nx/eslint-plugin';
import storybook from 'eslint-plugin-storybook';
import { defineConfig } from 'eslint/config';
import importPlugin from 'eslint-plugin-import';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import tseslint from 'typescript-eslint';
import {
definedGlobalIgnores,
defineGlobalRules,
defineProdRules,
defineDevRules,
} from './eslint.shared.mjs';
export const sharedConfig = defineConfig(
...nx.configs['flat/base'],
...nx.configs['flat/react'],
...nx.configs['flat/typescript'],
...nx.configs['flat/javascript'],
...storybook.configs['flat/recommended'],
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
plugins: {
import: importPlugin,
'jsx-a11y': jsxA11y,
},
settings: {
...importPlugin.flatConfigs.typescript.settings,
'import/ignore': ['node_modules'],
},
},
defineGlobalRules({
rules: {
/**
* nx — a graph rule, not a prod/dev quality rule, so it lives at the
* all-files layer: libs, apps and internals are all fenced by it.
*/
'@nx/enforce-module-boundaries': [
'error',
{
enforceBuildableLibDependency: true,
allow: [
'^.*/eslint(\\.base)?\\.config\\.[cm]?js$',
'^.*/eslint\\.shared\\.[cm]?js$',
],
// Internals are dev-only tooling that is never published, so nothing
// that ships (libs, apps) may import them. The allow-lists below
// already exclude `scope:internal`; the explicit `notDependOn…`
// keeps that true if someone widens an allow-list later.
depConstraints: [
{
sourceTag: 'scope:internal',
onlyDependOnLibsWithTags: ['scope:internal', 'scope:shared'],
},
{
sourceTag: 'scope:shared',
onlyDependOnLibsWithTags: ['scope:shared'],
notDependOnLibsWithTags: ['scope:internal'],
},
{
sourceTag: 'scope:react-native',
onlyDependOnLibsWithTags: [
'scope:shared',
'scope:react-native',
'scope:ui-shared',
],
notDependOnLibsWithTags: ['scope:internal'],
},
{
sourceTag: 'scope:react',
onlyDependOnLibsWithTags: [
'scope:shared',
'scope:react',
'scope:ui-shared',
],
notDependOnLibsWithTags: ['scope:internal'],
},
],
},
],
/**
* React
*/
'react/self-closing-comp': ['error', { component: true, html: true }],
/**
* import
*/
'import/no-unused-modules': 'error',
'import/no-mutable-exports': 'error',
'import/no-duplicates': 'error',
'import/no-cycle': ['error', { ignoreExternal: true }],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
/**
* typescript
*/
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/array-type': ['error', { default: 'array' }],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'warn',
/**
* Others
*/
'eqeqeq': ['error', 'always', { null: 'ignore' }],
'default-param-last': 'error',
'no-negated-condition': 'error',
'no-unused-vars': 'off',
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react',
importNames: ['forwardRef'],
message: 'Use ref as a regular prop instead (React 19 pattern).',
},
{
name: 'react-native',
importNames: ['TouchableOpacity'],
message: 'Prefer usage of `Pressable`.',
},
{
name: 'react-native',
importNames: ['Animated', 'Easing', 'LayoutAnimation'],
message: 'Prefer react-native-reanimated for animations.',
},
{
name: 'react',
importNames: ['ElementRef'],
message: 'ElementRef is deprecated. Use ComponentRef<T> instead.',
},
{
name: 'react',
importNames: ['MutableRefObject'],
message: 'MutableRefObject is deprecated. Use RefObject instead.',
},
{
name: '@base-ui/react',
message:
'Use path import "@base-ui/react/<component-name>" instead.',
},
],
},
],
},
}),
defineDevRules({
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
}),
eslintPluginPrettierRecommended,
definedGlobalIgnores,
);
export const prodConfig = defineConfig(
...sharedConfig,
defineProdRules({
rules: {
...jsxA11y.flatConfigs.strict.rules,
'react/display-name': 'error',
'no-console': 'error',
'import/no-extraneous-dependencies': ['error'],
'import/no-default-export': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-require-imports': 'error',
},
}),
);