-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
233 lines (230 loc) · 7.31 KB
/
index.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
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
226
227
228
229
230
231
232
233
// @ts-check
// Disable type-aware linting for performance reasons.
// const fs = require('fs')
// const path = require('path')
// const tsConfig = fs.existsSync('tsconfig.json')
// ? path.resolve('tsconfig.json')
// : undefined
const tsConfig = undefined
/** @type {import("eslint").Linter.Config} */
const eslintConfig = {
ignorePatterns: [
'**/node_modules/**',
'**/.next/**',
'**/dist/**',
'**/.next/**',
'**/storybook-static/**',
],
extends: ['next/core-web-vitals', 'plugin:prettier/recommended'],
plugins: ['tailwindcss'],
rules: {
'@next/next/no-html-link-for-pages': 'off',
'no-unused-vars': ['off'],
'react/jsx-sort-props': ['warn', { reservedFirst: ['key'] }],
'tailwindcss/classnames-order': ['warn'],
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
eqeqeq: ['error'],
},
overrides: [
{
files: ['**/*.d.ts', '**/*.ts', '**/*.tsx'],
excludedFiles: [
'**/node_modules/**',
'**/.next/**',
'**/dist/**',
'**/storybook-static/**',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: tsConfig,
},
plugins: ['@typescript-eslint', 'import', 'unused-imports', 'regex'],
rules: {
'@typescript-eslint/no-unused-vars': ['off'],
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal'],
pathGroups: [
{
pattern: '@dao-dao/**',
group: 'external',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ['@dao-dao/**'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/no-duplicates': 'error',
'sort-imports': [
'error',
{
// Let eslint-plugin-import handle declaration groups above.
ignoreDeclarationSort: true,
// Sort within import statements.
ignoreMemberSort: false,
},
],
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'regex/invalid': [
'error',
[
{
regex: '\\@\\/\\.\\.\\/\\.\\.\\/packages',
replacement: '@dao-dao',
message:
'Import from @dao-dao/* instead of a relative path (i.e. replace "@/../../packages" with "@dao-dao").',
},
{
regex: '\\@dao\\-dao\\/stateless\\/(components|theme)[^\'"]*',
replacement: '@dao-dao/stateless',
files: {
// Let storybook files (stories and files within the storybook
// package like decorators) import specific stateless files,
// like other storybook files.
ignore: '.*\\.stories\\.tsx|packages/storybook',
},
message:
'Import from root @dao-dao/stateless instead of a direct path. Ensure the export has been added to its sibling index.',
},
{
regex: '(?:\\.\\.\\/)+(atoms|components|hooks|util)',
replacement: {
function: '"@/" + $[1]',
},
files: {
// Only in apps.
inspect: 'apps\\/.+',
},
message:
'Import from root using prefix @/ instead of a relative path.',
},
{
regex:
'(?:(?:\\.\\.\\/)+|\\@\\/)(atoms|components|hooks|util)/[^\'"]+',
replacement: {
function: '"@/" + $[1]',
},
files: {
// Only in apps.
inspect: 'apps\\/.+',
},
message:
'Import from root @/ instead of a direct path. Ensure the export has been added to its sibling index.',
},
{
regex: '(\\bt\\(\\s*\'[^\\.\']+\'|i18nKey="[^\\."]+")',
message:
'No top-level i18n keys allowed. Organize top-level keys into a nested object.',
},
{
regex: 'dangerouslySetInnerHTML',
message: 'dangerouslySetInnerHTML is not allowed.',
},
{
regex: 'eval\\(',
message: 'eval is not allowed.',
},
{
regex: 'animate-spin([^-])',
replacement: {
function: '"animate-spin-medium" + $[1]',
},
message:
'`animate-spin` is too fast. Use `animate-spin-medium` for a chiller vibe.',
},
{
regex: '\\b(FC|FunctionComponent)\\b',
message:
"Using React's FunctionComponent is discouraged. Type the props explicitly: `export const Component = (props: ComponentProps) => { ... }`",
},
// Make sure GNU AGPLv3 header is not in the packages. This may
// happen if code gets copied from an app to a package. The packages
// use a different license than the apps.
{
regex:
'// GNU AFFERO GENERAL PUBLIC LICENSE Version 3\\. Copyright \\(C\\) 2022 DAO DAO Contributors\\.\n// See the "LICENSE" file in the root directory of this package for more copyright information\\.\n?\n?',
replacement: '',
files: {
// Only in packages.
inspect: 'packages\\/.+',
},
message: 'Do not include the GNU AGPLv3 header in package files.',
},
],
],
},
},
// i18n linting
{
files: ['**/*.d.ts', '**/*.ts', '**/*.tsx'],
excludedFiles: [
'**/node_modules/**',
'**/.next/**',
'**/dist/**',
'**/storybook-static/**',
// Don't care about i18n in storybook files.
'**/*.stories.tsx',
],
extends: ['plugin:react-i18n/recommended', 'plugin:i18next/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: tsConfig,
},
rules: {
'i18next/no-literal-string': [
'warn',
{
mode: 'jsx-only',
'jsx-attributes': {
include: [
'label',
'placeholder',
'alt',
'title',
'aria-label',
'aria-placeholder',
'name',
'description',
'subtitle',
],
},
'object-properties': {
exclude: [
// inline Number.toLocaleString, notation: 'compact'
'notation',
],
},
words: {
exclude: [
// Defaults wrapped in whitespace.
'\\s*[0-9!-/:-@[-`{-~]+\\s*',
'\\s*[A-Z_-]+\\s*',
],
},
},
],
},
},
],
}
module.exports = eslintConfig