@whoj/eslint-config 1.5.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,626 @@
1
+ import {
2
+ __commonJS,
3
+ init_esm_shims
4
+ } from "./chunk-MKNYKNDN.js";
5
+
6
+ // node_modules/.pnpm/estraverse@5.3.0/node_modules/estraverse/estraverse.js
7
+ var require_estraverse = __commonJS({
8
+ "node_modules/.pnpm/estraverse@5.3.0/node_modules/estraverse/estraverse.js"(exports) {
9
+ "use strict";
10
+ init_esm_shims();
11
+ (function clone(exports2) {
12
+ "use strict";
13
+ var Syntax, VisitorOption, VisitorKeys, BREAK, SKIP, REMOVE;
14
+ function deepCopy(obj) {
15
+ var ret = {}, key, val;
16
+ for (key in obj) {
17
+ if (obj.hasOwnProperty(key)) {
18
+ val = obj[key];
19
+ if (typeof val === "object" && val !== null) {
20
+ ret[key] = deepCopy(val);
21
+ } else {
22
+ ret[key] = val;
23
+ }
24
+ }
25
+ }
26
+ return ret;
27
+ }
28
+ function upperBound(array, func) {
29
+ var diff, len, i, current;
30
+ len = array.length;
31
+ i = 0;
32
+ while (len) {
33
+ diff = len >>> 1;
34
+ current = i + diff;
35
+ if (func(array[current])) {
36
+ len = diff;
37
+ } else {
38
+ i = current + 1;
39
+ len -= diff + 1;
40
+ }
41
+ }
42
+ return i;
43
+ }
44
+ Syntax = {
45
+ AssignmentExpression: "AssignmentExpression",
46
+ AssignmentPattern: "AssignmentPattern",
47
+ ArrayExpression: "ArrayExpression",
48
+ ArrayPattern: "ArrayPattern",
49
+ ArrowFunctionExpression: "ArrowFunctionExpression",
50
+ AwaitExpression: "AwaitExpression",
51
+ // CAUTION: It's deferred to ES7.
52
+ BlockStatement: "BlockStatement",
53
+ BinaryExpression: "BinaryExpression",
54
+ BreakStatement: "BreakStatement",
55
+ CallExpression: "CallExpression",
56
+ CatchClause: "CatchClause",
57
+ ChainExpression: "ChainExpression",
58
+ ClassBody: "ClassBody",
59
+ ClassDeclaration: "ClassDeclaration",
60
+ ClassExpression: "ClassExpression",
61
+ ComprehensionBlock: "ComprehensionBlock",
62
+ // CAUTION: It's deferred to ES7.
63
+ ComprehensionExpression: "ComprehensionExpression",
64
+ // CAUTION: It's deferred to ES7.
65
+ ConditionalExpression: "ConditionalExpression",
66
+ ContinueStatement: "ContinueStatement",
67
+ DebuggerStatement: "DebuggerStatement",
68
+ DirectiveStatement: "DirectiveStatement",
69
+ DoWhileStatement: "DoWhileStatement",
70
+ EmptyStatement: "EmptyStatement",
71
+ ExportAllDeclaration: "ExportAllDeclaration",
72
+ ExportDefaultDeclaration: "ExportDefaultDeclaration",
73
+ ExportNamedDeclaration: "ExportNamedDeclaration",
74
+ ExportSpecifier: "ExportSpecifier",
75
+ ExpressionStatement: "ExpressionStatement",
76
+ ForStatement: "ForStatement",
77
+ ForInStatement: "ForInStatement",
78
+ ForOfStatement: "ForOfStatement",
79
+ FunctionDeclaration: "FunctionDeclaration",
80
+ FunctionExpression: "FunctionExpression",
81
+ GeneratorExpression: "GeneratorExpression",
82
+ // CAUTION: It's deferred to ES7.
83
+ Identifier: "Identifier",
84
+ IfStatement: "IfStatement",
85
+ ImportExpression: "ImportExpression",
86
+ ImportDeclaration: "ImportDeclaration",
87
+ ImportDefaultSpecifier: "ImportDefaultSpecifier",
88
+ ImportNamespaceSpecifier: "ImportNamespaceSpecifier",
89
+ ImportSpecifier: "ImportSpecifier",
90
+ Literal: "Literal",
91
+ LabeledStatement: "LabeledStatement",
92
+ LogicalExpression: "LogicalExpression",
93
+ MemberExpression: "MemberExpression",
94
+ MetaProperty: "MetaProperty",
95
+ MethodDefinition: "MethodDefinition",
96
+ ModuleSpecifier: "ModuleSpecifier",
97
+ NewExpression: "NewExpression",
98
+ ObjectExpression: "ObjectExpression",
99
+ ObjectPattern: "ObjectPattern",
100
+ PrivateIdentifier: "PrivateIdentifier",
101
+ Program: "Program",
102
+ Property: "Property",
103
+ PropertyDefinition: "PropertyDefinition",
104
+ RestElement: "RestElement",
105
+ ReturnStatement: "ReturnStatement",
106
+ SequenceExpression: "SequenceExpression",
107
+ SpreadElement: "SpreadElement",
108
+ Super: "Super",
109
+ SwitchStatement: "SwitchStatement",
110
+ SwitchCase: "SwitchCase",
111
+ TaggedTemplateExpression: "TaggedTemplateExpression",
112
+ TemplateElement: "TemplateElement",
113
+ TemplateLiteral: "TemplateLiteral",
114
+ ThisExpression: "ThisExpression",
115
+ ThrowStatement: "ThrowStatement",
116
+ TryStatement: "TryStatement",
117
+ UnaryExpression: "UnaryExpression",
118
+ UpdateExpression: "UpdateExpression",
119
+ VariableDeclaration: "VariableDeclaration",
120
+ VariableDeclarator: "VariableDeclarator",
121
+ WhileStatement: "WhileStatement",
122
+ WithStatement: "WithStatement",
123
+ YieldExpression: "YieldExpression"
124
+ };
125
+ VisitorKeys = {
126
+ AssignmentExpression: ["left", "right"],
127
+ AssignmentPattern: ["left", "right"],
128
+ ArrayExpression: ["elements"],
129
+ ArrayPattern: ["elements"],
130
+ ArrowFunctionExpression: ["params", "body"],
131
+ AwaitExpression: ["argument"],
132
+ // CAUTION: It's deferred to ES7.
133
+ BlockStatement: ["body"],
134
+ BinaryExpression: ["left", "right"],
135
+ BreakStatement: ["label"],
136
+ CallExpression: ["callee", "arguments"],
137
+ CatchClause: ["param", "body"],
138
+ ChainExpression: ["expression"],
139
+ ClassBody: ["body"],
140
+ ClassDeclaration: ["id", "superClass", "body"],
141
+ ClassExpression: ["id", "superClass", "body"],
142
+ ComprehensionBlock: ["left", "right"],
143
+ // CAUTION: It's deferred to ES7.
144
+ ComprehensionExpression: ["blocks", "filter", "body"],
145
+ // CAUTION: It's deferred to ES7.
146
+ ConditionalExpression: ["test", "consequent", "alternate"],
147
+ ContinueStatement: ["label"],
148
+ DebuggerStatement: [],
149
+ DirectiveStatement: [],
150
+ DoWhileStatement: ["body", "test"],
151
+ EmptyStatement: [],
152
+ ExportAllDeclaration: ["source"],
153
+ ExportDefaultDeclaration: ["declaration"],
154
+ ExportNamedDeclaration: ["declaration", "specifiers", "source"],
155
+ ExportSpecifier: ["exported", "local"],
156
+ ExpressionStatement: ["expression"],
157
+ ForStatement: ["init", "test", "update", "body"],
158
+ ForInStatement: ["left", "right", "body"],
159
+ ForOfStatement: ["left", "right", "body"],
160
+ FunctionDeclaration: ["id", "params", "body"],
161
+ FunctionExpression: ["id", "params", "body"],
162
+ GeneratorExpression: ["blocks", "filter", "body"],
163
+ // CAUTION: It's deferred to ES7.
164
+ Identifier: [],
165
+ IfStatement: ["test", "consequent", "alternate"],
166
+ ImportExpression: ["source"],
167
+ ImportDeclaration: ["specifiers", "source"],
168
+ ImportDefaultSpecifier: ["local"],
169
+ ImportNamespaceSpecifier: ["local"],
170
+ ImportSpecifier: ["imported", "local"],
171
+ Literal: [],
172
+ LabeledStatement: ["label", "body"],
173
+ LogicalExpression: ["left", "right"],
174
+ MemberExpression: ["object", "property"],
175
+ MetaProperty: ["meta", "property"],
176
+ MethodDefinition: ["key", "value"],
177
+ ModuleSpecifier: [],
178
+ NewExpression: ["callee", "arguments"],
179
+ ObjectExpression: ["properties"],
180
+ ObjectPattern: ["properties"],
181
+ PrivateIdentifier: [],
182
+ Program: ["body"],
183
+ Property: ["key", "value"],
184
+ PropertyDefinition: ["key", "value"],
185
+ RestElement: ["argument"],
186
+ ReturnStatement: ["argument"],
187
+ SequenceExpression: ["expressions"],
188
+ SpreadElement: ["argument"],
189
+ Super: [],
190
+ SwitchStatement: ["discriminant", "cases"],
191
+ SwitchCase: ["test", "consequent"],
192
+ TaggedTemplateExpression: ["tag", "quasi"],
193
+ TemplateElement: [],
194
+ TemplateLiteral: ["quasis", "expressions"],
195
+ ThisExpression: [],
196
+ ThrowStatement: ["argument"],
197
+ TryStatement: ["block", "handler", "finalizer"],
198
+ UnaryExpression: ["argument"],
199
+ UpdateExpression: ["argument"],
200
+ VariableDeclaration: ["declarations"],
201
+ VariableDeclarator: ["id", "init"],
202
+ WhileStatement: ["test", "body"],
203
+ WithStatement: ["object", "body"],
204
+ YieldExpression: ["argument"]
205
+ };
206
+ BREAK = {};
207
+ SKIP = {};
208
+ REMOVE = {};
209
+ VisitorOption = {
210
+ Break: BREAK,
211
+ Skip: SKIP,
212
+ Remove: REMOVE
213
+ };
214
+ function Reference(parent, key) {
215
+ this.parent = parent;
216
+ this.key = key;
217
+ }
218
+ Reference.prototype.replace = function replace2(node) {
219
+ this.parent[this.key] = node;
220
+ };
221
+ Reference.prototype.remove = function remove() {
222
+ if (Array.isArray(this.parent)) {
223
+ this.parent.splice(this.key, 1);
224
+ return true;
225
+ } else {
226
+ this.replace(null);
227
+ return false;
228
+ }
229
+ };
230
+ function Element(node, path, wrap, ref) {
231
+ this.node = node;
232
+ this.path = path;
233
+ this.wrap = wrap;
234
+ this.ref = ref;
235
+ }
236
+ function Controller() {
237
+ }
238
+ Controller.prototype.path = function path() {
239
+ var i, iz, j, jz, result, element;
240
+ function addToPath(result2, path2) {
241
+ if (Array.isArray(path2)) {
242
+ for (j = 0, jz = path2.length; j < jz; ++j) {
243
+ result2.push(path2[j]);
244
+ }
245
+ } else {
246
+ result2.push(path2);
247
+ }
248
+ }
249
+ if (!this.__current.path) {
250
+ return null;
251
+ }
252
+ result = [];
253
+ for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
254
+ element = this.__leavelist[i];
255
+ addToPath(result, element.path);
256
+ }
257
+ addToPath(result, this.__current.path);
258
+ return result;
259
+ };
260
+ Controller.prototype.type = function() {
261
+ var node = this.current();
262
+ return node.type || this.__current.wrap;
263
+ };
264
+ Controller.prototype.parents = function parents() {
265
+ var i, iz, result;
266
+ result = [];
267
+ for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
268
+ result.push(this.__leavelist[i].node);
269
+ }
270
+ return result;
271
+ };
272
+ Controller.prototype.current = function current() {
273
+ return this.__current.node;
274
+ };
275
+ Controller.prototype.__execute = function __execute(callback, element) {
276
+ var previous, result;
277
+ result = void 0;
278
+ previous = this.__current;
279
+ this.__current = element;
280
+ this.__state = null;
281
+ if (callback) {
282
+ result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
283
+ }
284
+ this.__current = previous;
285
+ return result;
286
+ };
287
+ Controller.prototype.notify = function notify(flag) {
288
+ this.__state = flag;
289
+ };
290
+ Controller.prototype.skip = function() {
291
+ this.notify(SKIP);
292
+ };
293
+ Controller.prototype["break"] = function() {
294
+ this.notify(BREAK);
295
+ };
296
+ Controller.prototype.remove = function() {
297
+ this.notify(REMOVE);
298
+ };
299
+ Controller.prototype.__initialize = function(root, visitor) {
300
+ this.visitor = visitor;
301
+ this.root = root;
302
+ this.__worklist = [];
303
+ this.__leavelist = [];
304
+ this.__current = null;
305
+ this.__state = null;
306
+ this.__fallback = null;
307
+ if (visitor.fallback === "iteration") {
308
+ this.__fallback = Object.keys;
309
+ } else if (typeof visitor.fallback === "function") {
310
+ this.__fallback = visitor.fallback;
311
+ }
312
+ this.__keys = VisitorKeys;
313
+ if (visitor.keys) {
314
+ this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
315
+ }
316
+ };
317
+ function isNode(node) {
318
+ if (node == null) {
319
+ return false;
320
+ }
321
+ return typeof node === "object" && typeof node.type === "string";
322
+ }
323
+ function isProperty(nodeType, key) {
324
+ return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && "properties" === key;
325
+ }
326
+ function candidateExistsInLeaveList(leavelist, candidate) {
327
+ for (var i = leavelist.length - 1; i >= 0; --i) {
328
+ if (leavelist[i].node === candidate) {
329
+ return true;
330
+ }
331
+ }
332
+ return false;
333
+ }
334
+ Controller.prototype.traverse = function traverse2(root, visitor) {
335
+ var worklist, leavelist, element, node, nodeType, ret, key, current, current2, candidates, candidate, sentinel;
336
+ this.__initialize(root, visitor);
337
+ sentinel = {};
338
+ worklist = this.__worklist;
339
+ leavelist = this.__leavelist;
340
+ worklist.push(new Element(root, null, null, null));
341
+ leavelist.push(new Element(null, null, null, null));
342
+ while (worklist.length) {
343
+ element = worklist.pop();
344
+ if (element === sentinel) {
345
+ element = leavelist.pop();
346
+ ret = this.__execute(visitor.leave, element);
347
+ if (this.__state === BREAK || ret === BREAK) {
348
+ return;
349
+ }
350
+ continue;
351
+ }
352
+ if (element.node) {
353
+ ret = this.__execute(visitor.enter, element);
354
+ if (this.__state === BREAK || ret === BREAK) {
355
+ return;
356
+ }
357
+ worklist.push(sentinel);
358
+ leavelist.push(element);
359
+ if (this.__state === SKIP || ret === SKIP) {
360
+ continue;
361
+ }
362
+ node = element.node;
363
+ nodeType = node.type || element.wrap;
364
+ candidates = this.__keys[nodeType];
365
+ if (!candidates) {
366
+ if (this.__fallback) {
367
+ candidates = this.__fallback(node);
368
+ } else {
369
+ throw new Error("Unknown node type " + nodeType + ".");
370
+ }
371
+ }
372
+ current = candidates.length;
373
+ while ((current -= 1) >= 0) {
374
+ key = candidates[current];
375
+ candidate = node[key];
376
+ if (!candidate) {
377
+ continue;
378
+ }
379
+ if (Array.isArray(candidate)) {
380
+ current2 = candidate.length;
381
+ while ((current2 -= 1) >= 0) {
382
+ if (!candidate[current2]) {
383
+ continue;
384
+ }
385
+ if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
386
+ continue;
387
+ }
388
+ if (isProperty(nodeType, candidates[current])) {
389
+ element = new Element(candidate[current2], [key, current2], "Property", null);
390
+ } else if (isNode(candidate[current2])) {
391
+ element = new Element(candidate[current2], [key, current2], null, null);
392
+ } else {
393
+ continue;
394
+ }
395
+ worklist.push(element);
396
+ }
397
+ } else if (isNode(candidate)) {
398
+ if (candidateExistsInLeaveList(leavelist, candidate)) {
399
+ continue;
400
+ }
401
+ worklist.push(new Element(candidate, key, null, null));
402
+ }
403
+ }
404
+ }
405
+ }
406
+ };
407
+ Controller.prototype.replace = function replace2(root, visitor) {
408
+ var worklist, leavelist, node, nodeType, target, element, current, current2, candidates, candidate, sentinel, outer, key;
409
+ function removeElem(element2) {
410
+ var i, key2, nextElem, parent;
411
+ if (element2.ref.remove()) {
412
+ key2 = element2.ref.key;
413
+ parent = element2.ref.parent;
414
+ i = worklist.length;
415
+ while (i--) {
416
+ nextElem = worklist[i];
417
+ if (nextElem.ref && nextElem.ref.parent === parent) {
418
+ if (nextElem.ref.key < key2) {
419
+ break;
420
+ }
421
+ --nextElem.ref.key;
422
+ }
423
+ }
424
+ }
425
+ }
426
+ this.__initialize(root, visitor);
427
+ sentinel = {};
428
+ worklist = this.__worklist;
429
+ leavelist = this.__leavelist;
430
+ outer = {
431
+ root
432
+ };
433
+ element = new Element(root, null, null, new Reference(outer, "root"));
434
+ worklist.push(element);
435
+ leavelist.push(element);
436
+ while (worklist.length) {
437
+ element = worklist.pop();
438
+ if (element === sentinel) {
439
+ element = leavelist.pop();
440
+ target = this.__execute(visitor.leave, element);
441
+ if (target !== void 0 && target !== BREAK && target !== SKIP && target !== REMOVE) {
442
+ element.ref.replace(target);
443
+ }
444
+ if (this.__state === REMOVE || target === REMOVE) {
445
+ removeElem(element);
446
+ }
447
+ if (this.__state === BREAK || target === BREAK) {
448
+ return outer.root;
449
+ }
450
+ continue;
451
+ }
452
+ target = this.__execute(visitor.enter, element);
453
+ if (target !== void 0 && target !== BREAK && target !== SKIP && target !== REMOVE) {
454
+ element.ref.replace(target);
455
+ element.node = target;
456
+ }
457
+ if (this.__state === REMOVE || target === REMOVE) {
458
+ removeElem(element);
459
+ element.node = null;
460
+ }
461
+ if (this.__state === BREAK || target === BREAK) {
462
+ return outer.root;
463
+ }
464
+ node = element.node;
465
+ if (!node) {
466
+ continue;
467
+ }
468
+ worklist.push(sentinel);
469
+ leavelist.push(element);
470
+ if (this.__state === SKIP || target === SKIP) {
471
+ continue;
472
+ }
473
+ nodeType = node.type || element.wrap;
474
+ candidates = this.__keys[nodeType];
475
+ if (!candidates) {
476
+ if (this.__fallback) {
477
+ candidates = this.__fallback(node);
478
+ } else {
479
+ throw new Error("Unknown node type " + nodeType + ".");
480
+ }
481
+ }
482
+ current = candidates.length;
483
+ while ((current -= 1) >= 0) {
484
+ key = candidates[current];
485
+ candidate = node[key];
486
+ if (!candidate) {
487
+ continue;
488
+ }
489
+ if (Array.isArray(candidate)) {
490
+ current2 = candidate.length;
491
+ while ((current2 -= 1) >= 0) {
492
+ if (!candidate[current2]) {
493
+ continue;
494
+ }
495
+ if (isProperty(nodeType, candidates[current])) {
496
+ element = new Element(candidate[current2], [key, current2], "Property", new Reference(candidate, current2));
497
+ } else if (isNode(candidate[current2])) {
498
+ element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
499
+ } else {
500
+ continue;
501
+ }
502
+ worklist.push(element);
503
+ }
504
+ } else if (isNode(candidate)) {
505
+ worklist.push(new Element(candidate, key, null, new Reference(node, key)));
506
+ }
507
+ }
508
+ }
509
+ return outer.root;
510
+ };
511
+ function traverse(root, visitor) {
512
+ var controller = new Controller();
513
+ return controller.traverse(root, visitor);
514
+ }
515
+ function replace(root, visitor) {
516
+ var controller = new Controller();
517
+ return controller.replace(root, visitor);
518
+ }
519
+ function extendCommentRange(comment, tokens) {
520
+ var target;
521
+ target = upperBound(tokens, function search(token) {
522
+ return token.range[0] > comment.range[0];
523
+ });
524
+ comment.extendedRange = [comment.range[0], comment.range[1]];
525
+ if (target !== tokens.length) {
526
+ comment.extendedRange[1] = tokens[target].range[0];
527
+ }
528
+ target -= 1;
529
+ if (target >= 0) {
530
+ comment.extendedRange[0] = tokens[target].range[1];
531
+ }
532
+ return comment;
533
+ }
534
+ function attachComments(tree, providedComments, tokens) {
535
+ var comments = [], comment, len, i, cursor;
536
+ if (!tree.range) {
537
+ throw new Error("attachComments needs range information");
538
+ }
539
+ if (!tokens.length) {
540
+ if (providedComments.length) {
541
+ for (i = 0, len = providedComments.length; i < len; i += 1) {
542
+ comment = deepCopy(providedComments[i]);
543
+ comment.extendedRange = [0, tree.range[0]];
544
+ comments.push(comment);
545
+ }
546
+ tree.leadingComments = comments;
547
+ }
548
+ return tree;
549
+ }
550
+ for (i = 0, len = providedComments.length; i < len; i += 1) {
551
+ comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
552
+ }
553
+ cursor = 0;
554
+ traverse(tree, {
555
+ enter: function(node) {
556
+ var comment2;
557
+ while (cursor < comments.length) {
558
+ comment2 = comments[cursor];
559
+ if (comment2.extendedRange[1] > node.range[0]) {
560
+ break;
561
+ }
562
+ if (comment2.extendedRange[1] === node.range[0]) {
563
+ if (!node.leadingComments) {
564
+ node.leadingComments = [];
565
+ }
566
+ node.leadingComments.push(comment2);
567
+ comments.splice(cursor, 1);
568
+ } else {
569
+ cursor += 1;
570
+ }
571
+ }
572
+ if (cursor === comments.length) {
573
+ return VisitorOption.Break;
574
+ }
575
+ if (comments[cursor].extendedRange[0] > node.range[1]) {
576
+ return VisitorOption.Skip;
577
+ }
578
+ }
579
+ });
580
+ cursor = 0;
581
+ traverse(tree, {
582
+ leave: function(node) {
583
+ var comment2;
584
+ while (cursor < comments.length) {
585
+ comment2 = comments[cursor];
586
+ if (node.range[1] < comment2.extendedRange[0]) {
587
+ break;
588
+ }
589
+ if (node.range[1] === comment2.extendedRange[0]) {
590
+ if (!node.trailingComments) {
591
+ node.trailingComments = [];
592
+ }
593
+ node.trailingComments.push(comment2);
594
+ comments.splice(cursor, 1);
595
+ } else {
596
+ cursor += 1;
597
+ }
598
+ }
599
+ if (cursor === comments.length) {
600
+ return VisitorOption.Break;
601
+ }
602
+ if (comments[cursor].extendedRange[0] > node.range[1]) {
603
+ return VisitorOption.Skip;
604
+ }
605
+ }
606
+ });
607
+ return tree;
608
+ }
609
+ exports2.Syntax = Syntax;
610
+ exports2.traverse = traverse;
611
+ exports2.replace = replace;
612
+ exports2.attachComments = attachComments;
613
+ exports2.VisitorKeys = VisitorKeys;
614
+ exports2.VisitorOption = VisitorOption;
615
+ exports2.Controller = Controller;
616
+ exports2.cloneEnvironment = function() {
617
+ return clone({});
618
+ };
619
+ return exports2;
620
+ })(exports);
621
+ }
622
+ });
623
+
624
+ export {
625
+ require_estraverse
626
+ };