forked from pixiebrix/eslint-config-pixiebrix
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
159 lines (151 loc) · 4.54 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
const config = {
env: {
browser: true,
},
settings: {
"import/resolver": {
typescript: {},
},
"import/ignore": [
"react-select", // For some reason it points to a flow JS file
],
react: {
version: "detect",
},
},
plugins: ["filenames", "jsx-a11y"],
extends: [
"xo", // Full config: https://github.com/xojs/eslint-config-xo/blob/main/index.js
"xo-typescript", // Full config: https://github.com/xojs/eslint-config-xo-typescript/blob/main/index.js
"prettier", // Disable style-related rules
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:security/recommended",
"plugin:unicorn/recommended",
"plugin:jsx-a11y/recommended",
],
rules: {
// Enable extra rules
"filenames/match-exported": "error",
"no-restricted-imports": [
"error",
{
// Documentation: https://eslint.org/docs/rules/no-restricted-imports#options
patterns: [
{
group: ["*/__mocks__/*"],
message:
"Mocks should not be imported directly, they’re automatically picked up where needed.",
},
{
group: ["lodash/*"],
message: 'You can import "lodash" instead of "lodash/*."',
},
{
group: ["react-bootstrap/*", "!react-bootstrap/types"],
message:
'You can import "react-bootstrap" instead of "react-bootstrap/*".',
},
{
group: ["../*"],
message:
'Use root-based imports (`import "@/something"`) instead of relative imports.',
},
],
},
],
"no-mixed-operators": [
"error",
{
// Customize the defaults to force being explicit about use of null-coalescing operator because its precedence
// is unintuitive. See: https://eslint.org/docs/rules/no-mixed-operators
groups: [
// Conflicts with Prettier: https://github.com/prettier/prettier/issues/3968
// ["+", "-", "*", "/", "%", "**", "??"],
["&", "|", "^", "~", "<<", ">>", ">>>", "??"],
["==", "!=", "===", "!==", ">", ">=", "<", "<=", "??"],
["&&", "||", "??"],
["in", "instanceof", "??"],
],
},
],
// Customize some rules
quotes: ["error", "double", { avoidEscape: true }], // Matches Prettier, but also replaces backticks
"unicorn/prevent-abbreviations": [
"error",
{
extendDefaultReplacements: false,
replacements: {
err: {
error: true,
},
},
},
],
"unicorn/filename-case": [
"error",
{
cases: {
camelCase: true,
pascalCase: true,
},
},
],
// Smart allows for != null. See: https://github.com/pixiebrix/pixiebrix-extension/pull/887#pullrequestreview-711873690
eqeqeq: ["error", "smart"],
"@typescript-eslint/naming-convention": [
"error",
{
selector: "variable",
modifiers: ["const", "exported"],
types: ["boolean", "string", "number"],
format: ["UPPER_CASE"],
},
],
// Disable recommended rules
// It's fine because eqeqeq covers it. See https://github.com/pixiebrix/pixiebrix-extension/pull/887#pullrequestreview-711873690
"no-eq-null": "off",
"import/named": "off", // TypeScript does this natively
"import/no-unresolved": "off", // TypeScript does this natively
"react/prop-types": "off",
"unicorn/prefer-node-protocol": "off", // Not fully supported by TS
"unicorn/prefer-set-has": "off", // Not always worth the extra code
"unicorn/require-post-message-target-origin": "off", // Incompatible https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1396
"no-warning-comments": "off", // Only useful if there aren't hundreds of other real warnings
"@typescript-eslint/no-implicit-any-catch": "off", // Already covered by tsconfig
// Too strict for now
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off",
// Maybe later, opinionated
"unicorn/no-null": "off",
"unicorn/prefer-ternary": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-empty-function": "off",
},
overrides: [], // Used below
};
config.overrides.push({
files: ["src/*"],
rules: {
"no-restricted-imports": [
"error",
{
// Documentation: https://eslint.org/docs/rules/no-restricted-imports#options
patterns: [
// Extend the existing patterns
...config.rules["no-restricted-imports"][1].patterns,
{
group: ["./*"],
message:
'Use root-based imports (`import "@/something"`) instead of relative imports.',
},
],
},
],
},
});
module.exports = config;