-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheslint.config.js
180 lines (168 loc) · 4.46 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// eslint.config.js
import js from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import parser from '@typescript-eslint/parser';
import importPlugin from 'eslint-plugin-import';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import storybookPlugin from 'eslint-plugin-storybook';
import globals from 'globals';
export default [
// Base JS recommended rules
js.configs.recommended,
// Base configuration for all files
{
files: ['**/*.{js,jsx,ts,tsx,mjs,cjs}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
react: reactPlugin,
'react-hooks': reactHooksPlugin,
storybook: storybookPlugin,
import: importPlugin,
'@typescript-eslint': tseslint,
'jsx-a11y': jsxA11yPlugin,
},
settings: {
react: {
version: 'detect',
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
rules: {
// Core rules
'prefer-const': 0,
'comma-dangle': 0,
'no-console': 0,
'arrow-parens': 0,
'no-prototype-builtins': 0,
'class-methods-use-this': 0,
'no-param-reassign': 0,
'no-mixed-operators': 0,
'no-else-return': 0,
'prefer-promise-reject-errors': 0,
// React rules
'react/boolean-prop-naming': [
'error',
{
rule: '^(is|use|active|should|default|show|hide|are|does|do|when|include|allow|auto|preserve|no|danger|serif|apply|fonts|disable)([A-Z]([A-Za-z0-9]?)+|)',
message:
'Boolean props should have `is|use|active|should|default|show|hide|are|does|do|when|include|allow|auto|preserve|no|danger|serif|apply|fonts|disable` prefix',
},
],
'react/display-name': 'error',
'react/prop-types': 'warn',
'react/jsx-sort-props': [
'error',
{
callbacksLast: true,
shorthandFirst: true,
shorthandLast: false,
noSortAlphabetically: true,
reservedFirst: true,
},
],
// Import rules
'import/extensions': 0,
'import/no-unresolved': 0,
'import/no-anonymous-default-export': 0,
'import/no-extraneous-dependencies': 'error',
'import/no-unused-modules': 'error',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always',
},
],
// React Hooks rules
'react-hooks/exhaustive-deps': 'warn',
},
},
// TypeScript files
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser,
parserOptions: {
project: './tsconfig.json',
},
},
rules: {
// We need to disable JS rule and enable TS-specific one
'no-unused-vars': 'off',
// These rules are manually set to match the original rules
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
// Script files override
{
files: ['./scripts/**/*.{cjs,js,mjs}'],
rules: {
// Cannot check since no-var-requires might be missing in the current TS ESLint plugin
'no-var-requires': 'off',
},
},
// Storybook files override
{
files: ['**/*.stories.tsx', '**/storybook/**/*.tsx'],
rules: {
'react/function-component-definition': 0,
'react/boolean-prop-naming': 0,
'react/prop-types': 0,
'react/no-unescaped-entities': 0,
},
},
// Test files override
{
files: ['**/*.test.ts', '**/*.test.tsx'],
rules: {
'no-unused-vars': 'off',
'react/prop-types': 'off',
'no-undef': 'off',
},
},
// All TypeScript files
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'react/prop-types': 'off',
'react-hooks/exhaustive-deps': 'off',
'react/boolean-prop-naming': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': [
'error',
{ ignoreDeclarationMerge: true },
],
},
},
// Apply specific ignore patterns
{
ignores: ['*.js', '*.d.ts'],
},
];