-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path.eslintrc.js
264 lines (261 loc) · 7.86 KB
/
.eslintrc.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
"use strict";
// Open `test/__snapshots__/examples.test.js.snap` to see what the files here in
// `example/` look like after running `eslint --fix`. Each file has slightly
// different configuration – see below.
const vue = require("eslint-plugin-vue");
module.exports = {
root: true,
parserOptions: {
sourceType: "module",
},
env: { es6: true },
rules: {
// The actual rule names are "simple-import-sort/imports" and
// "simple-import-sort/exports", but for technical reasons they’re called
// just "imports" and "exports" within the examples of this repo.
// "simple-import-sort/imports": "error",
// "simple-import-sort/exports": "error",
imports: "error",
exports: "error",
},
overrides: [
{
// This file only enables the “imports” rule from this plugin. After
// autofixing, there might be some oddly placed spaces.
files: ["1.spaces.just-sort.js"],
},
{
// You can enable some builtin rules to fix up the spaces after sorting.
files: ["2.spaces.eslint-builtin.js"],
rules: {
"comma-spacing": "error",
indent: "error",
"object-curly-spacing": "error",
// There might be more rules you want to enable. See:
// https://eslint.org/docs/rules/
},
},
{
// Alternatively, use Prettier (https://prettier.io/) to fix formatting.
// This is the much easier and recommended approach.
files: ["3.spaces.prettier.js"],
// This doesn’t need any extra ESLint config, only Prettier setup.
},
{
// Use these rules from eslint-plugin-import
// (https://github.com/benmosher/eslint-plugin-import/) if you want hoist
// imports to the top, add a blank line after them and merge duplicates.
files: ["eslint-plugin-import.js"],
plugins: ["import"],
rules: {
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
},
},
{
// ignore.js shows how to ignore sorting and errors when needed.
files: ["ignore.js"],
plugins: ["import"],
rules: {
"no-duplicate-imports": "error",
"import/no-duplicates": "error",
},
},
{
files: ["groups.custom.js"],
rules: {
imports: [
"error",
{
groups: [
// Node.js builtins. You could also generate this regex if you use a `.js` config.
// For example: `^(${require("module").builtinModules.join("|")})(/|$)`
// Note that if you use the `node:` prefix for Node.js builtins,
// you can avoid this complexity: You can simply use "^node:".
[
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)",
],
// Packages. `react` related packages come first.
["^react", "^@?\\w"],
// Internal packages.
["^(@|@company|@ui|components|utils|config|vendored-lib)(/.*|$)"],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["^.+\\.s?css$"],
],
},
],
},
},
{
files: ["groups.no-blank-lines.js"],
rules: {
imports: [
"error",
{
// The default grouping, but with no blank lines.
groups: [["^\\u0000", "^node:", "^@?\\w", "^", "^\\."]],
},
],
},
},
{
files: ["groups.default-reverse.js"],
rules: {
imports: [
"error",
{
// The default grouping, but in reverse.
groups: [["^\\."], ["^"], ["^@?\\w"], ["^node:"], ["^\\u0000"]],
},
],
},
},
{
files: ["groups.type-imports-first.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports first as a separate group.
groups: [["^.*\\u0000$"], ["^\\u0000"], ["^node:"], ["^@?\\w"], ["^"], ["^\\."]],
},
],
},
},
{
files: ["groups.type-imports-last.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports last as a separate group.
groups: [["^\\u0000"], ["^node:"], ["^@?\\w"], ["^"], ["^\\."], ["^.+\\u0000$"]],
},
],
},
},
{
files: ["groups.type-imports-first-sorted.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports first as a separate
// group, sorting that group like non-type imports are grouped.
groups: [
["^node:.*\\u0000$", "^@?\\w.*\\u0000$", "^[^.].*\\u0000$", "^\\..*\\u0000$"],
["^\\u0000"],
["^node:"],
["^@?\\w"],
["^"],
["^\\."],
],
},
],
},
},
{
files: ["groups.type-imports-last-sorted.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports last as a separate
// group, sorting that group like non-type imports are grouped.
groups: [
["^\\u0000"],
["^node:"],
["^@?\\w"],
["^"],
["^\\."],
["^node:.*\\u0000$", "^@?\\w.*\\u0000$", "^[^.].*\\u0000$", "^\\..*\\u0000$"],
],
},
],
},
},
{
files: ["groups.type-imports-first-in-each-group.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports first in each group.
groups: [
["^\\u0000"],
["^node:.*\\u0000$", "^node:"],
["^@?\\w.*\\u0000$", "^@?\\w"],
["(?<=\\u0000)$", "^"],
["^\\..*\\u0000$", "^\\."],
],
},
],
},
},
{
files: ["groups.type-imports-last-in-each-group.ts"],
parser: "@typescript-eslint/parser",
rules: {
imports: [
"error",
{
// The default grouping, but with type imports last in each group.
groups: [
["^\\u0000"],
["^node:", "^node:.*\\u0000$"],
["^@?\\w", "^@?\\w.*\\u0000$"],
["(?<!\\u0000)$", "(?<=\\u0000)$"],
["^\\.", "^\\..*\\u0000$"],
],
},
],
},
},
{
files: ["groups.none.js"],
rules: {
imports: [
"error",
{
// No grouping, only alphabetical sorting.
groups: [],
},
],
},
},
{
// These files are used in README.md.
files: ["readme-*.js"],
parser: "@babel/eslint-parser",
},
{
// TypeScript.
files: ["*.ts"],
parser: "@typescript-eslint/parser",
},
{
// Vue `<script>` tags.
files: ["*.vue"],
parser: vue.configs.base.parser,
plugins: ["vue"],
},
{
// Markdown JS code blocks.
files: ["*.md"],
plugins: ["markdown"],
processor: "markdown/markdown"
},
],
};