This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.cjs
139 lines (138 loc) · 3.99 KB
/
.eslintrc.cjs
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
const TAILWIND_CONFIG = {
extends: ['plugin:tailwindcss/recommended'],
rules: {
'tailwindcss/classnames-order': 'off', // conflicts with prettier-plugin-tailwindcss
'tailwindcss/enforces-negative-arbitrary-values': 'error',
'tailwindcss/enforces-shorthand': 'error',
'tailwindcss/migration-from-tailwind-2': 'error',
'tailwindcss/no-custom-classname': 'error'
}
}
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
reportUnusedDisableDirectives: true,
ignorePatterns: ['next-env.d.ts'],
overrides: [
// Rules for all files
{
files: '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier'
],
plugins: ['import', 'unicorn'],
rules: {
'prefer-object-has-own': 'error',
'logical-assignment-operators': [
'error',
'always',
{ enforceForIfStatements: true }
],
'@typescript-eslint/prefer-optional-chain': 'error',
'no-else-return': ['error', { allowElseIf: false }],
'no-lonely-if': 'error',
'prefer-destructuring': [
'error',
{ VariableDeclarator: { object: true } }
],
'import/no-duplicates': 'error',
'no-negated-condition': 'off',
'unicorn/no-negated-condition': 'error',
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
'object-shorthand': ['error', 'always'],
// todo: enable
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-comment': 'off'
}
},
// Rules for React files
{
files: '**',
extends: [
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:@next/next/recommended'
],
rules: {
'react/prop-types': 'off',
'react/no-unknown-property': ['error', { ignore: ['jsx'] }],
'react-hooks/exhaustive-deps': 'error',
'react/self-closing-comp': 'error',
'no-restricted-syntax': [
'error',
{
// ❌ useMemo(…, [])
selector:
'CallExpression[callee.name=useMemo][arguments.1.type=ArrayExpression][arguments.1.elements.length=0]',
message:
"`useMemo` with an empty dependency array can't provide a stable reference, use `useRef` instead."
}
],
'react/jsx-filename-extension': [
'error',
{ extensions: ['.tsx', '.jsx'], allow: 'as-needed' }
],
'react/jsx-curly-brace-presence': 'error',
'react/jsx-boolean-value': 'error'
},
settings: {
react: { version: 'detect' }
}
},
// Rules for TypeScript files
{
files: '**/*.{ts,tsx,cts,mts}',
extends: [
// TODO: fix errors
// 'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
parserOptions: {
project: ['tsconfig.json']
},
rules: {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'error'
}
},
// Core
{
...TAILWIND_CONFIG,
files: '**',
plugins: ['typescript-sort-keys'],
settings: {
tailwindcss: {
config: 'tailwind.config.cjs',
callees: ['cn']
}
},
rules: {
...TAILWIND_CONFIG.rules
}
},
{
files: [
'prettier.config.cjs',
'postcss.config.cjs',
'tailwind.config.cjs',
'next.config.mjs',
'.eslintrc.cjs'
],
env: {
node: true
}
},
{
files: ['**/*.d.ts'],
rules: {
'no-var': 'off'
}
}
]
}