generated from blameitonyourisp/js-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc
383 lines (361 loc) · 17.5 KB
/
.eslintrc
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
{
// This file is an opinionated eslint configuration. In terms of number of
// rules specified in this file, it is a reasonably detailed/specific
// configuration. For more information for getting started with eslint, see
// here: https://eslint.org/docs/latest/use/getting-started. For more
// information specifically on configuring eslint with a .eslintrc, see
// here: https://eslint.org/docs/latest/use/configure.
// Language option configuration, for more information, see here:
// https://eslint.org/docs/latest/use/configure/language-options#specifying-environments.
"env": {
"browser": true,
"es2022": true,
"node": true
},
// Default option set provided by eslint, which the rules object below
// either add to or overwrite.
"extends": "eslint:recommended",
// Specify language options which should be supported, most notably node
// modules instead of commonjs. For more information, see here:
// https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options.
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
// Specify plugins used by this configuration, for more information, see
// here: https://eslint.org/docs/latest/use/configure/plugins.
"plugins": [
"regex",
"eslint-comments"
],
// Rules which add to or overwrite the existing default rule set implied by
// the "extends" field. For more information on rule configuration, see
// here: https://eslint.org/docs/latest/rules. For more information on any
// rule set below, see https://eslint.org/docs/latest/rules/<rule-name>.
// Note that not ALL rules are explicitly set/unset below. Use of ESLint
// warnings, which may often be ignored, is generally avoided in favour of
// throwing an error for any incorrect formatting.
"rules": {
// Plugin-specific eslint configurations.
// Regex plugin configuration used for ensuring that specific patterns
// are/are not matched in any given script. For more information on
// configuration, see here: https://github.com/gmullerb/eslint-plugin-regex.
// Invalid regex configuration - i.e. patterns which are not valid in
// any script. Plugin provides replacement method for regex/invalid
// rules to automatically resolve a given issue. As such these patterns
// are preferred over the regex/required patterns.
"regex/invalid": ["error", [
// Ensure that each file starts with the required header, including
// license text, jsdoc file description, and @ts-check or
// @ts-nocheck directive (in listed order). Note that no rules are
// included to check for/prevent duplicate header elements
// elsewhere in a script, although these should be very obvious to
// spot any time someone is working on a given script.
{
"id": "noMissingScriptHeader",
"regex": "(?<!.|\n)(?!\/\/ Copyright \\(c\\) \\d{4} .*\\. All rights reserved\\.\n\/\/\n\/\/ This source code file is licensed under the terms of the MIT license, a copy\n\/\/ of which may be found in the LICENSE\\.md file in the root of this repository\\.\n\/\/\n\/\/ For a template copy of the license see one of the following 3rd party sites:\n\/\/ {6}- <https:\/\/opensource\\.org\/licenses\/MIT>\n\/\/ {6}- <https:\/\/choosealicense\\.com\/licenses\/mit>\n\/\/ {6}- <https:\/\/spdx\\.org\/licenses\/MIT>\n\n\/\\*\\*\\s*\n([^\\*]|(\\*(?!\/)))*\\s*\\*\\s*@file\\s.*\n([^\\*]|(\\*(?!(\/)|(\\s*@))))*(\\s*\\*\\s*@author\\s.*\n)+\\s*\\*\/\n\n\/\/ (@ts-check|@ts-nocheck)(\n| .*\n)\n)",
"message": "Script must start with license information, file description, and @ts-check or @ts-nocheck directive.",
"replacement": {
// Insert placeholder header at start of file.
"function": "return `// Copyright (c) <INSERT_YEAR_HERE> <INSERT_OWNER_HERE>. All rights reserved.\n//\n// This source code file is licensed under the terms of the MIT license, a copy\n// of which may be found in the LICENSE.md file in the root of this repository.\n//\n// For a template copy of the license see one of the following 3rd party sites:\n// - <https://opensource.org/licenses/MIT>\n// - <https://choosealicense.com/licenses/mit>\n// - <https://spdx.org/licenses/MIT>\n\n/**\n * @file <INSERT_FILE_DESCRIPTION_HERE>\n * @author <INSERT_AUTHOR_HERE>\n */\n\n// @ts-check\n\n`"
}
},
// Ensure that all placeholder header details have been populated
// when the header has been added using the regex/invalid
// replacement function.
{
"id": "noMissingHeaderDetails",
"regex": "(?<=\/\/.*|\/\\*\\*.*\n([^\\*]|(\\*(?!\/)))*\\s*\\*.*)<INSERT_[_A-Z]*_HERE>",
"message": "All header details must be populated."
},
// Ensure that no invalid block tags are used in a scripts (mainly
// for enforcing correct block tags when using multiple import
// blocks).
{
"id": "noInvalidBlockTags",
"regex": "(?<=\/\/ )@@(?!((no-)?(body|exports|imports)|imports(-(node|dependencies|utils|package|module|submodule|types)))\\s)",
"message": "Invalid @@<block> block tags not permitted. Remove block tag, or use a valid tag.",
"replacement": {
// Remove @@ in front of matched invalid tag.
"function": "return ``"
}
},
// Ensure that no block tag has a description (i.e. a newline
// character immediately follows the end of the tag).
{
"id": "noBlockTagDescriptions",
"regex": "(?<=\/\/ @@[-a-z]*) .*",
"message": "Block tag descriptions are not permitted.",
"replacement": {
// Remove any matched block tag description.
"function": "return ``"
}
},
// Ensure that every block tag is preceded by a blank line. New
// lines AFTER block tags at the end of a file are enforced by
// the eslint "eol-last" setting.
{
"id": "noBlockTagPreviousLine",
"regex": "(?<!\n\n)\/\/ @@.*",
"message": "Block tags must be preceded by a blank line.",
"replacement": {
// Insert extra newline before matched tag.
"function": "return `\n${text}`"
}
},
// Ensure that any block with the "no-" prefix has no content
// contained within it before the start of the next block.
{
"id": "noUsedEmptyBlocks",
"regex": "(?<=\/\/ @@)no-.*(?=\n)(?!\n*(\/\/ @@.*|$(?!\n)))",
"message": "Cannot use @@no-<block> to mark a non-empty block, use @@<block> instead.",
"replacement": {
// Remove "no-" prefix from matched tag.
"function": "return `${text.replace('no-', '')}`"
}
},
// Ensure that any block without the "no-" prefix has some content
// contained within it before the start of the next block.
{
"id": "noUnusedBlocks",
"regex": "(?<=\/\/ @@)[^no-].*(?=\n*(\/\/ @@.*|$(?!\n)))",
"message": "Cannot use @@<block> to mark an empty block, use @@no-<block> instead.",
"replacement": {
// Add "no-" prefix tp matched tag.
"function": "return `no-${text}`"
}
},
// Ensure that body or export blocks do not appear more than once
// in a given script.
{
"id": "noDuplicateUniqueBlocks",
"regex": "(?<=\/\/ @@(no-)?body(.*\n)*)\/\/ @@(no-)?body|(?<=\/\/ @@(no-)?exports(.*\n)*)\/\/ @@(no-)?exports",
"message": "Unique blocks @@body and @@export cannot appear more than once in a script.",
"replacement": {
// Remove duplicate matched tag.
"function": "return ``"
}
},
// Ensure that every script has one or more import block(s), a
// body block, and and export block. Additionally ensures that
// these blocks appear in the correct order.
{
"id": "noMissingBlocks",
"regex": "(?<!.|\n)(?!(.*\n)*\/\/ @@((no-)?imports|imports-[a-z]*)\\s(.*\n)*\/\/ @@(no-)?body\\s(.*\n)*\/\/ @@(no-)?exports\\s)",
"message": "One or more @@<block> tags missing, or blocks are in incorrect order."
}
]],
// No configuration for regex/required since absence of a given pattern
// causes an error which highlights the whole file, which can be a
// little frustrating. Additionally, the regex/required patterns cannot
// be automatically fixed with the replacement option.
// Plugin configuration for the eslint-comments plugin, mainly for
// ensuring that there are no unused, unrestricted or unclosed eslint
// directives. For more information, please see the plugin page here:
// https://mysticatea.github.io/eslint-plugin-eslint-comments/.
// Best practice rules for eslint-comments plugin.
"eslint-comments/disable-enable-pair": "error",
"eslint-comments/no-aggregating-enable": "off",
"eslint-comments/no-duplicate-disable": "error",
"eslint-comments/no-unlimited-disable": "error",
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unused-enable": "error",
// Stylistic suggestions for eslint-comments plugin.
"eslint-comments/no-restricted-disable": "off",
"eslint-comments/no-use": "off",
"eslint-comments/require-description": "error",
// Eslint "problems" relating to possible logic errors in code. Most
// rules turned on by default, the following configuration turns off
// or changes inconvenient default settings. For more information, see
// here: https://eslint.org/docs/latest/rules/#possible-problems.
"no-control-regex": "off",
"no-duplicate-imports": "error",
"no-ex-assign": "off",
"no-unused-private-class-members": "error",
// Eslint "suggestions" relating to alternate ways of organising code
// which will not give rise to logical errors if not followed, but may
// be preferable for reducing unnecessary blocks, or enforcing naming
// conventions etc. Most rules in this category are disabled by
// default, and this configuration only enables a selection. For more
// information on all available rules in this category, see here:
// https://eslint.org/docs/latest/rules/#suggestions.
"curly": ["error", "all"],
"default-case": ["error", {
"commentPattern": "^@no-default"
}],
"default-case-last": "error",
"default-param-last": "error",
"eqeqeq": "error",
"func-style": ["error", "declaration", {
"allowArrowFunctions": true
}],
"grouped-accessor-pairs": "error",
"guard-for-in": "off",
"id-denylist": ["error", "err", "e", "ev", "cb"],
"id-match": ["error", "(^[A-Z]?[a-z0-9]*([A-Z][a-z0-9]*)*$)|(^([A-Z0-9]+_?)*$)", {
"properties": false,
"classFields": false,
"onlyDeclarations": true,
"ignoreDestructuring": true
}],
"multiline-comment-style": ["error", "separate-lines"],
"new-cap": ["error", {
"newIsCap": true,
"capIsNew": true,
"capIsNewExceptions": ["Array"]
}],
"no-else-return": "error",
"no-extra-label": "error",
"no-label-var": "error",
"no-lone-blocks": "error",
"no-useless-return": "error",
"no-var": "error",
"prefer-const": "error",
"spaced-comment": ["error", "always"],
"yoda": "error",
// Eslint "layout" rules which have no impact on how the code runs, and
// only relate to how the code appears in the editor. The majority of
// these rules are turned off by default, and this configuration sets
// ALL rules in this category. If the rule should remain off, this
// configuration explicitly sets it to off below. For more information,
// see here: https://eslint.org/docs/latest/rules/#layout--formatting.
"array-bracket-newline": ["error", "consistent"],
"array-bracket-spacing": ["error", "never"],
"array-element-newline": ["error", "consistent"],
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": ["error", {
"before": true,
"after": true
}],
"block-spacing": ["error", "always"],
"brace-style": ["error", "stroustrup", {
"allowSingleLine": true
}],
"comma-dangle": ["error", "only-multiline"],
"comma-spacing": ["error", {
"before": false,
"after": true
}],
"comma-style": ["error", "last"],
"computed-property-spacing": ["error", "never", {
"enforceForClassMembers": true
}],
"dot-location": ["error", "property"],
"eol-last": ["error", "always"],
"func-call-spacing": ["error", "never"],
"function-call-argument-newline": ["error", "consistent"],
"function-paren-newline": ["error", "consistent"],
"generator-star-spacing": ["error", {
"before": false,
"after": true
}],
"implicit-arrow-linebreak": ["error", "beside"],
"indent": ["error", 4, {
"ignoredNodes": ["ConditionalExpression"],
"SwitchCase": 1
}],
"jsx-quotes": ["error", "prefer-double"],
"key-spacing": ["error", {
"beforeColon": false,
"afterColon": true,
"mode": "strict"
}],
"keyword-spacing": ["error", {
"before": true,
"after": true
}],
"line-comment-position": ["off"],
"linebreak-style": ["error", "unix"],
"lines-around-comment": ["off"],
"lines-between-class-members": ["error", {
"enforce": [
{ "blankLine": "always", "prev": "method", "next": "method" },
{ "blankLine": "always", "prev": "method", "next": "field" },
{ "blankLine": "always", "prev": "field", "next": "method" },
{ "blankLine": "never", "prev": "field", "next": "field" }
]
}],
"max-len": ["error", {
"code": 80,
"tabWidth": 4,
"comments": 80,
"ignorePattern": "^.*@no-wrap$",
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}],
"new-parens": ["error", "always"],
"newline-per-chained-call": ["error", {
"ignoreChainWithDepth": 3
}],
"no-extra-parens": ["off"],
"no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": ["error", {
"ignoreEOLComments": false,
"exceptions": { "Property": false }
}],
"no-multiple-empty-lines": ["error", {
"max": 1,
"maxEOF": 1,
"maxBOF": 1
}],
"no-tabs": "error",
"no-trailing-spaces": ["error", {
"skipBlankLines": false,
"ignoreComments": false
}],
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": ["error", "beside"],
"object-curly-newline": ["error", {
"consistent": true
}],
"object-curly-spacing": ["error", "always"],
"operator-linebreak": ["error", "after", {
"overrides": {
":": "before",
"?": "before"
}
}],
"padded-blocks": ["error", "never"],
"padding-line-between-statements": ["off"],
"quotes": ["error", "double"],
"rest-spread-spacing": ["error", "never"],
"semi": ["error", "never"],
"semi-spacing": ["error", {
"before": false,
"after": true
}],
"semi-style": ["error", "last"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": ["error", {
"words": true,
"nonwords": true,
"overrides": {
"++": false,
"--": false,
"!": false,
"~": false
}
}],
"switch-colon-spacing": ["error", {
"before": false,
"after": true
}],
"template-curly-spacing": ["error", "never"],
"template-tag-spacing": ["error", "never"],
"unicode-bom": ["error", "never"],
"wrap-iife": ["error", "inside"],
"yield-star-spacing": ["error", {
"before": false,
"after": true
}]
}
}