@ttsc/lint 0.5.0-dev.20260429 → 0.5.0-dev.20260429-4
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.
- package/{go-plugin/go.mod → go.mod} +3 -3
- package/package.json +6 -7
- package/{go-plugin/lint → plugin}/ast_helpers.go +1 -1
- package/{go-plugin/lint → plugin}/compile.go +1 -1
- package/{go-plugin/lint → plugin}/config.go +1 -1
- package/{go-plugin/lint → plugin}/engine.go +6 -6
- package/{go-plugin/lint → plugin}/host.go +1 -1
- package/{go-plugin → plugin}/main.go +3 -5
- package/{go-plugin/lint → plugin}/rules_arrays.go +5 -3
- package/{go-plugin/lint → plugin}/rules_console.go +3 -3
- package/{go-plugin/lint → plugin}/rules_debugger.go +5 -5
- package/{go-plugin/lint → plugin}/rules_dupes.go +5 -5
- package/{go-plugin/lint → plugin}/rules_empty.go +4 -4
- package/{go-plugin/lint → plugin}/rules_eval.go +7 -5
- package/{go-plugin/lint → plugin}/rules_finally.go +3 -3
- package/{go-plugin/lint → plugin}/rules_logic.go +11 -11
- package/{go-plugin/lint → plugin}/rules_loops.go +3 -3
- package/{go-plugin/lint → plugin}/rules_misc.go +5 -5
- package/{go-plugin/lint → plugin}/rules_problems.go +41 -29
- package/{go-plugin/lint → plugin}/rules_protos.go +7 -5
- package/{go-plugin/lint → plugin}/rules_self.go +5 -5
- package/{go-plugin/lint → plugin}/rules_strings.go +11 -9
- package/{go-plugin/lint → plugin}/rules_suggestions.go +83 -61
- package/{go-plugin/lint → plugin}/rules_throw.go +3 -3
- package/{go-plugin/lint → plugin}/rules_ts.go +29 -19
- package/{go-plugin/lint → plugin}/rules_ts_extra.go +57 -35
- package/{go-plugin/lint → plugin}/rules_var.go +3 -3
- package/{index.cjs → src/index.cjs} +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package main
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"strings"
|
|
@@ -11,8 +11,10 @@ import (
|
|
|
11
11
|
// https://eslint.org/docs/latest/rules/no-template-curly-in-string
|
|
12
12
|
type noTemplateCurlyInString struct{}
|
|
13
13
|
|
|
14
|
-
func (noTemplateCurlyInString) Name() string
|
|
15
|
-
func (noTemplateCurlyInString) Visits() []shimast.Kind
|
|
14
|
+
func (noTemplateCurlyInString) Name() string { return "no-template-curly-in-string" }
|
|
15
|
+
func (noTemplateCurlyInString) Visits() []shimast.Kind {
|
|
16
|
+
return []shimast.Kind{shimast.KindStringLiteral}
|
|
17
|
+
}
|
|
16
18
|
func (noTemplateCurlyInString) Check(ctx *Context, node *shimast.Node) {
|
|
17
19
|
text := stringLiteralText(node)
|
|
18
20
|
if hasTemplatePlaceholder(text) {
|
|
@@ -45,8 +47,8 @@ func hasTemplatePlaceholder(text string) bool {
|
|
|
45
47
|
// https://eslint.org/docs/latest/rules/no-multi-str
|
|
46
48
|
type noMultiStr struct{}
|
|
47
49
|
|
|
48
|
-
func (noMultiStr) Name() string
|
|
49
|
-
func (noMultiStr) Visits() []shimast.Kind
|
|
50
|
+
func (noMultiStr) Name() string { return "no-multi-str" }
|
|
51
|
+
func (noMultiStr) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindStringLiteral} }
|
|
50
52
|
func (noMultiStr) Check(ctx *Context, node *shimast.Node) {
|
|
51
53
|
src := nodeText(ctx.File, node)
|
|
52
54
|
// Look for `\` immediately before a newline in the *raw* source text.
|
|
@@ -72,8 +74,8 @@ func hasBackslashLineContinuation(src string) bool {
|
|
|
72
74
|
// https://eslint.org/docs/latest/rules/no-useless-concat
|
|
73
75
|
type noUselessConcat struct{}
|
|
74
76
|
|
|
75
|
-
func (noUselessConcat) Name() string
|
|
76
|
-
func (noUselessConcat) Visits() []shimast.Kind
|
|
77
|
+
func (noUselessConcat) Name() string { return "no-useless-concat" }
|
|
78
|
+
func (noUselessConcat) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
77
79
|
func (noUselessConcat) Check(ctx *Context, node *shimast.Node) {
|
|
78
80
|
expr := node.AsBinaryExpression()
|
|
79
81
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -103,8 +105,8 @@ func isStringLikeLiteral(node *shimast.Node) bool {
|
|
|
103
105
|
// https://eslint.org/docs/latest/rules/no-octal
|
|
104
106
|
type noOctal struct{}
|
|
105
107
|
|
|
106
|
-
func (noOctal) Name() string
|
|
107
|
-
func (noOctal) Visits() []shimast.Kind
|
|
108
|
+
func (noOctal) Name() string { return "no-octal" }
|
|
109
|
+
func (noOctal) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindNumericLiteral} }
|
|
108
110
|
func (noOctal) Check(ctx *Context, node *shimast.Node) {
|
|
109
111
|
src := nodeText(ctx.File, node)
|
|
110
112
|
src = strings.TrimLeft(src, " \t")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Bulk implementation of ESLint's "Suggestions" category — rules that
|
|
2
2
|
// don't catch outright bugs but flag stylistic or maintainability
|
|
3
3
|
// patterns. AST-only, no scope analysis.
|
|
4
|
-
package
|
|
4
|
+
package main
|
|
5
5
|
|
|
6
6
|
import (
|
|
7
7
|
"strings"
|
|
@@ -13,8 +13,8 @@ import (
|
|
|
13
13
|
// answer in production code.
|
|
14
14
|
type noAlert struct{}
|
|
15
15
|
|
|
16
|
-
func (noAlert) Name() string
|
|
17
|
-
func (noAlert) Visits() []shimast.Kind
|
|
16
|
+
func (noAlert) Name() string { return "no-alert" }
|
|
17
|
+
func (noAlert) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindCallExpression} }
|
|
18
18
|
func (noAlert) Check(ctx *Context, node *shimast.Node) {
|
|
19
19
|
call := node.AsCallExpression()
|
|
20
20
|
if call == nil {
|
|
@@ -70,8 +70,8 @@ func (noBitwise) Check(ctx *Context, node *shimast.Node) {
|
|
|
70
70
|
// errors elsewhere; lint catches them earlier.
|
|
71
71
|
type noCaller struct{}
|
|
72
72
|
|
|
73
|
-
func (noCaller) Name() string
|
|
74
|
-
func (noCaller) Visits() []shimast.Kind
|
|
73
|
+
func (noCaller) Name() string { return "no-caller" }
|
|
74
|
+
func (noCaller) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindPropertyAccessExpression} }
|
|
75
75
|
func (noCaller) Check(ctx *Context, node *shimast.Node) {
|
|
76
76
|
access := node.AsPropertyAccessExpression()
|
|
77
77
|
if access == nil {
|
|
@@ -121,8 +121,8 @@ func (noCaseDeclarations) Check(ctx *Context, node *shimast.Node) {
|
|
|
121
121
|
// (loop body should usually be reorganized).
|
|
122
122
|
type noContinue struct{}
|
|
123
123
|
|
|
124
|
-
func (noContinue) Name() string
|
|
125
|
-
func (noContinue) Visits() []shimast.Kind
|
|
124
|
+
func (noContinue) Name() string { return "no-continue" }
|
|
125
|
+
func (noContinue) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindContinueStatement} }
|
|
126
126
|
func (noContinue) Check(ctx *Context, node *shimast.Node) {
|
|
127
127
|
ctx.Report(node, "Unexpected use of continue statement.")
|
|
128
128
|
}
|
|
@@ -130,8 +130,8 @@ func (noContinue) Check(ctx *Context, node *shimast.Node) {
|
|
|
130
130
|
// no-delete-var: `delete x` where `x` is a variable. Strict-mode error.
|
|
131
131
|
type noDeleteVar struct{}
|
|
132
132
|
|
|
133
|
-
func (noDeleteVar) Name() string
|
|
134
|
-
func (noDeleteVar) Visits() []shimast.Kind
|
|
133
|
+
func (noDeleteVar) Name() string { return "no-delete-var" }
|
|
134
|
+
func (noDeleteVar) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindDeleteExpression} }
|
|
135
135
|
func (noDeleteVar) Check(ctx *Context, node *shimast.Node) {
|
|
136
136
|
del := node.AsDeleteExpression()
|
|
137
137
|
if del == nil {
|
|
@@ -146,8 +146,8 @@ func (noDeleteVar) Check(ctx *Context, node *shimast.Node) {
|
|
|
146
146
|
// when developers want to also catch `undefined`.
|
|
147
147
|
type noEqNull struct{}
|
|
148
148
|
|
|
149
|
-
func (noEqNull) Name() string
|
|
150
|
-
func (noEqNull) Visits() []shimast.Kind
|
|
149
|
+
func (noEqNull) Name() string { return "no-eq-null" }
|
|
150
|
+
func (noEqNull) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
151
151
|
func (noEqNull) Check(ctx *Context, node *shimast.Node) {
|
|
152
152
|
expr := node.AsBinaryExpression()
|
|
153
153
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -170,8 +170,8 @@ func isNullLiteral(node *shimast.Node) bool {
|
|
|
170
170
|
// keeping false-positives down.
|
|
171
171
|
type noExtraBind struct{}
|
|
172
172
|
|
|
173
|
-
func (noExtraBind) Name() string
|
|
174
|
-
func (noExtraBind) Visits() []shimast.Kind
|
|
173
|
+
func (noExtraBind) Name() string { return "no-extra-bind" }
|
|
174
|
+
func (noExtraBind) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindCallExpression} }
|
|
175
175
|
func (noExtraBind) Check(ctx *Context, node *shimast.Node) {
|
|
176
176
|
call := node.AsCallExpression()
|
|
177
177
|
if call == nil || call.Expression == nil {
|
|
@@ -233,8 +233,8 @@ func bodyReferencesThis(node *shimast.Node) bool {
|
|
|
233
233
|
// confusing and rarely needed.
|
|
234
234
|
type noLabels struct{}
|
|
235
235
|
|
|
236
|
-
func (noLabels) Name() string
|
|
237
|
-
func (noLabels) Visits() []shimast.Kind
|
|
236
|
+
func (noLabels) Name() string { return "no-labels" }
|
|
237
|
+
func (noLabels) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindLabeledStatement} }
|
|
238
238
|
func (noLabels) Check(ctx *Context, node *shimast.Node) {
|
|
239
239
|
ctx.Report(node, "Unexpected labeled statement.")
|
|
240
240
|
}
|
|
@@ -243,8 +243,8 @@ func (noLabels) Check(ctx *Context, node *shimast.Node) {
|
|
|
243
243
|
// the braces add no scope (in non-strict mode) and obscure intent.
|
|
244
244
|
type noLoneBlocks struct{}
|
|
245
245
|
|
|
246
|
-
func (noLoneBlocks) Name() string
|
|
247
|
-
func (noLoneBlocks) Visits() []shimast.Kind
|
|
246
|
+
func (noLoneBlocks) Name() string { return "no-lone-blocks" }
|
|
247
|
+
func (noLoneBlocks) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBlock} }
|
|
248
248
|
func (noLoneBlocks) Check(ctx *Context, node *shimast.Node) {
|
|
249
249
|
parent := node.Parent
|
|
250
250
|
if parent == nil {
|
|
@@ -290,8 +290,8 @@ func (noLoneBlocks) Check(ctx *Context, node *shimast.Node) {
|
|
|
290
290
|
// no-lonely-if: `else { if (...) {...} }` should be `else if (...)`.
|
|
291
291
|
type noLonelyIf struct{}
|
|
292
292
|
|
|
293
|
-
func (noLonelyIf) Name() string
|
|
294
|
-
func (noLonelyIf) Visits() []shimast.Kind
|
|
293
|
+
func (noLonelyIf) Name() string { return "no-lonely-if" }
|
|
294
|
+
func (noLonelyIf) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindIfStatement} }
|
|
295
295
|
func (noLonelyIf) Check(ctx *Context, node *shimast.Node) {
|
|
296
296
|
parent := node.Parent
|
|
297
297
|
if parent == nil || parent.Kind != shimast.KindBlock {
|
|
@@ -318,8 +318,8 @@ func (noLonelyIf) Check(ctx *Context, node *shimast.Node) {
|
|
|
318
318
|
// no-multi-assign: `a = b = 1`. Confusing right-to-left chains.
|
|
319
319
|
type noMultiAssign struct{}
|
|
320
320
|
|
|
321
|
-
func (noMultiAssign) Name() string
|
|
322
|
-
func (noMultiAssign) Visits() []shimast.Kind
|
|
321
|
+
func (noMultiAssign) Name() string { return "no-multi-assign" }
|
|
322
|
+
func (noMultiAssign) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
323
323
|
func (noMultiAssign) Check(ctx *Context, node *shimast.Node) {
|
|
324
324
|
expr := node.AsBinaryExpression()
|
|
325
325
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -394,8 +394,10 @@ func isNegatedExpression(node *shimast.Node) bool {
|
|
|
394
394
|
// no-nested-ternary: `a ? b : c ? d : e`.
|
|
395
395
|
type noNestedTernary struct{}
|
|
396
396
|
|
|
397
|
-
func (noNestedTernary) Name() string
|
|
398
|
-
func (noNestedTernary) Visits() []shimast.Kind
|
|
397
|
+
func (noNestedTernary) Name() string { return "no-nested-ternary" }
|
|
398
|
+
func (noNestedTernary) Visits() []shimast.Kind {
|
|
399
|
+
return []shimast.Kind{shimast.KindConditionalExpression}
|
|
400
|
+
}
|
|
399
401
|
func (noNestedTernary) Check(ctx *Context, node *shimast.Node) {
|
|
400
402
|
cond := node.AsConditionalExpression()
|
|
401
403
|
if cond == nil {
|
|
@@ -415,8 +417,8 @@ func hasConditional(node *shimast.Node) bool {
|
|
|
415
417
|
// avoid the constructor.
|
|
416
418
|
type noNew struct{}
|
|
417
419
|
|
|
418
|
-
func (noNew) Name() string
|
|
419
|
-
func (noNew) Visits() []shimast.Kind
|
|
420
|
+
func (noNew) Name() string { return "no-new" }
|
|
421
|
+
func (noNew) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindExpressionStatement} }
|
|
420
422
|
func (noNew) Check(ctx *Context, node *shimast.Node) {
|
|
421
423
|
stmt := node.AsExpressionStatement()
|
|
422
424
|
if stmt == nil || stmt.Expression == nil {
|
|
@@ -430,8 +432,10 @@ func (noNew) Check(ctx *Context, node *shimast.Node) {
|
|
|
430
432
|
// no-new-func: `new Function("...")` — a third form of dynamic eval.
|
|
431
433
|
type noNewFunc struct{}
|
|
432
434
|
|
|
433
|
-
func (noNewFunc) Name() string
|
|
434
|
-
func (noNewFunc) Visits() []shimast.Kind
|
|
435
|
+
func (noNewFunc) Name() string { return "no-new-func" }
|
|
436
|
+
func (noNewFunc) Visits() []shimast.Kind {
|
|
437
|
+
return []shimast.Kind{shimast.KindNewExpression, shimast.KindCallExpression}
|
|
438
|
+
}
|
|
435
439
|
func (noNewFunc) Check(ctx *Context, node *shimast.Node) {
|
|
436
440
|
var callee *shimast.Node
|
|
437
441
|
if node.Kind == shimast.KindNewExpression {
|
|
@@ -448,8 +452,10 @@ func (noNewFunc) Check(ctx *Context, node *shimast.Node) {
|
|
|
448
452
|
// no-array-constructor but for objects.
|
|
449
453
|
type noObjectConstructor struct{}
|
|
450
454
|
|
|
451
|
-
func (noObjectConstructor) Name() string
|
|
452
|
-
func (noObjectConstructor) Visits() []shimast.Kind
|
|
455
|
+
func (noObjectConstructor) Name() string { return "no-object-constructor" }
|
|
456
|
+
func (noObjectConstructor) Visits() []shimast.Kind {
|
|
457
|
+
return []shimast.Kind{shimast.KindNewExpression, shimast.KindCallExpression}
|
|
458
|
+
}
|
|
453
459
|
func (noObjectConstructor) Check(ctx *Context, node *shimast.Node) {
|
|
454
460
|
var callee *shimast.Node
|
|
455
461
|
var argCount int
|
|
@@ -478,8 +484,10 @@ func (noObjectConstructor) Check(ctx *Context, node *shimast.Node) {
|
|
|
478
484
|
// deprecated and forbidden in template literals.
|
|
479
485
|
type noOctalEscape struct{}
|
|
480
486
|
|
|
481
|
-
func (noOctalEscape) Name() string
|
|
482
|
-
func (noOctalEscape) Visits() []shimast.Kind
|
|
487
|
+
func (noOctalEscape) Name() string { return "no-octal-escape" }
|
|
488
|
+
func (noOctalEscape) Visits() []shimast.Kind {
|
|
489
|
+
return []shimast.Kind{shimast.KindStringLiteral, shimast.KindNoSubstitutionTemplateLiteral}
|
|
490
|
+
}
|
|
483
491
|
func (noOctalEscape) Check(ctx *Context, node *shimast.Node) {
|
|
484
492
|
src := nodeText(ctx.File, node)
|
|
485
493
|
if hasOctalEscape(src) {
|
|
@@ -535,8 +543,10 @@ func (noPlusPlus) Check(ctx *Context, node *shimast.Node) {
|
|
|
535
543
|
// because the count is invisible.
|
|
536
544
|
type noRegexSpaces struct{}
|
|
537
545
|
|
|
538
|
-
func (noRegexSpaces) Name() string
|
|
539
|
-
func (noRegexSpaces) Visits() []shimast.Kind
|
|
546
|
+
func (noRegexSpaces) Name() string { return "no-regex-spaces" }
|
|
547
|
+
func (noRegexSpaces) Visits() []shimast.Kind {
|
|
548
|
+
return []shimast.Kind{shimast.KindRegularExpressionLiteral}
|
|
549
|
+
}
|
|
540
550
|
func (noRegexSpaces) Check(ctx *Context, node *shimast.Node) {
|
|
541
551
|
src := nodeText(ctx.File, node)
|
|
542
552
|
if regexHasMultipleSpaces(src) {
|
|
@@ -584,8 +594,10 @@ func regexHasMultipleSpaces(src string) bool {
|
|
|
584
594
|
// no-return-assign: `return a = b` mixes assignment with return.
|
|
585
595
|
type noReturnAssign struct{}
|
|
586
596
|
|
|
587
|
-
func (noReturnAssign) Name() string
|
|
588
|
-
func (noReturnAssign) Visits() []shimast.Kind
|
|
597
|
+
func (noReturnAssign) Name() string { return "no-return-assign" }
|
|
598
|
+
func (noReturnAssign) Visits() []shimast.Kind {
|
|
599
|
+
return []shimast.Kind{shimast.KindReturnStatement, shimast.KindArrowFunction}
|
|
600
|
+
}
|
|
589
601
|
func (noReturnAssign) Check(ctx *Context, node *shimast.Node) {
|
|
590
602
|
switch node.Kind {
|
|
591
603
|
case shimast.KindReturnStatement:
|
|
@@ -611,8 +623,8 @@ func (noReturnAssign) Check(ctx *Context, node *shimast.Node) {
|
|
|
611
623
|
// pattern outside of `for` headers.
|
|
612
624
|
type noSequences struct{}
|
|
613
625
|
|
|
614
|
-
func (noSequences) Name() string
|
|
615
|
-
func (noSequences) Visits() []shimast.Kind
|
|
626
|
+
func (noSequences) Name() string { return "no-sequences" }
|
|
627
|
+
func (noSequences) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
616
628
|
func (noSequences) Check(ctx *Context, node *shimast.Node) {
|
|
617
629
|
expr := node.AsBinaryExpression()
|
|
618
630
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -667,8 +679,8 @@ func (noShadowRestrictedNames) Check(ctx *Context, node *shimast.Node) {
|
|
|
667
679
|
// because it's writable in older environments.
|
|
668
680
|
type noUndefined struct{}
|
|
669
681
|
|
|
670
|
-
func (noUndefined) Name() string
|
|
671
|
-
func (noUndefined) Visits() []shimast.Kind
|
|
682
|
+
func (noUndefined) Name() string { return "no-undefined" }
|
|
683
|
+
func (noUndefined) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindIdentifier} }
|
|
672
684
|
func (noUndefined) Check(ctx *Context, node *shimast.Node) {
|
|
673
685
|
if identifierText(node) != "undefined" {
|
|
674
686
|
return
|
|
@@ -719,8 +731,10 @@ func nodesShareLoc(a, b *shimast.Node) bool {
|
|
|
719
731
|
// no-unneeded-ternary: `x ? true : false` → `Boolean(x)` / `!!x`.
|
|
720
732
|
type noUnneededTernary struct{}
|
|
721
733
|
|
|
722
|
-
func (noUnneededTernary) Name() string
|
|
723
|
-
func (noUnneededTernary) Visits() []shimast.Kind
|
|
734
|
+
func (noUnneededTernary) Name() string { return "no-unneeded-ternary" }
|
|
735
|
+
func (noUnneededTernary) Visits() []shimast.Kind {
|
|
736
|
+
return []shimast.Kind{shimast.KindConditionalExpression}
|
|
737
|
+
}
|
|
724
738
|
func (noUnneededTernary) Check(ctx *Context, node *shimast.Node) {
|
|
725
739
|
cond := node.AsConditionalExpression()
|
|
726
740
|
if cond == nil {
|
|
@@ -739,8 +753,10 @@ func (noUnneededTernary) Check(ctx *Context, node *shimast.Node) {
|
|
|
739
753
|
// Filtered down to common patterns ESLint flags by default.
|
|
740
754
|
type noUnusedExpressions struct{}
|
|
741
755
|
|
|
742
|
-
func (noUnusedExpressions) Name() string
|
|
743
|
-
func (noUnusedExpressions) Visits() []shimast.Kind
|
|
756
|
+
func (noUnusedExpressions) Name() string { return "no-unused-expressions" }
|
|
757
|
+
func (noUnusedExpressions) Visits() []shimast.Kind {
|
|
758
|
+
return []shimast.Kind{shimast.KindExpressionStatement}
|
|
759
|
+
}
|
|
744
760
|
func (noUnusedExpressions) Check(ctx *Context, node *shimast.Node) {
|
|
745
761
|
stmt := node.AsExpressionStatement()
|
|
746
762
|
if stmt == nil || stmt.Expression == nil {
|
|
@@ -800,8 +816,8 @@ func isProductiveExpression(node *shimast.Node) bool {
|
|
|
800
816
|
// — call/apply with no this binding is just a regular call.
|
|
801
817
|
type noUselessCall struct{}
|
|
802
818
|
|
|
803
|
-
func (noUselessCall) Name() string
|
|
804
|
-
func (noUselessCall) Visits() []shimast.Kind
|
|
819
|
+
func (noUselessCall) Name() string { return "no-useless-call" }
|
|
820
|
+
func (noUselessCall) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindCallExpression} }
|
|
805
821
|
func (noUselessCall) Check(ctx *Context, node *shimast.Node) {
|
|
806
822
|
call := node.AsCallExpression()
|
|
807
823
|
if call == nil || call.Expression == nil || call.Expression.Kind != shimast.KindPropertyAccessExpression {
|
|
@@ -900,8 +916,8 @@ func (noUselessRename) Check(ctx *Context, node *shimast.Node) {
|
|
|
900
916
|
// object-shorthand: `{ x: x }` → `{ x }`.
|
|
901
917
|
type objectShorthand struct{}
|
|
902
918
|
|
|
903
|
-
func (objectShorthand) Name() string
|
|
904
|
-
func (objectShorthand) Visits() []shimast.Kind
|
|
919
|
+
func (objectShorthand) Name() string { return "object-shorthand" }
|
|
920
|
+
func (objectShorthand) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindPropertyAssignment} }
|
|
905
921
|
func (objectShorthand) Check(ctx *Context, node *shimast.Node) {
|
|
906
922
|
prop := node.AsPropertyAssignment()
|
|
907
923
|
if prop == nil || prop.Name() == nil || prop.Initializer == nil {
|
|
@@ -920,8 +936,10 @@ func (objectShorthand) Check(ctx *Context, node *shimast.Node) {
|
|
|
920
936
|
// operator-assignment: `x = x + 1` → `x += 1`.
|
|
921
937
|
type operatorAssignment struct{}
|
|
922
938
|
|
|
923
|
-
func (operatorAssignment) Name() string
|
|
924
|
-
func (operatorAssignment) Visits() []shimast.Kind
|
|
939
|
+
func (operatorAssignment) Name() string { return "operator-assignment" }
|
|
940
|
+
func (operatorAssignment) Visits() []shimast.Kind {
|
|
941
|
+
return []shimast.Kind{shimast.KindBinaryExpression}
|
|
942
|
+
}
|
|
925
943
|
func (operatorAssignment) Check(ctx *Context, node *shimast.Node) {
|
|
926
944
|
expr := node.AsBinaryExpression()
|
|
927
945
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -958,8 +976,10 @@ func isCompoundEligibleOperator(kind shimast.Kind) bool {
|
|
|
958
976
|
// prefer-exponentiation-operator: `Math.pow(a, b)` → `a ** b`.
|
|
959
977
|
type preferExponentiationOperator struct{}
|
|
960
978
|
|
|
961
|
-
func (preferExponentiationOperator) Name() string
|
|
962
|
-
func (preferExponentiationOperator) Visits() []shimast.Kind
|
|
979
|
+
func (preferExponentiationOperator) Name() string { return "prefer-exponentiation-operator" }
|
|
980
|
+
func (preferExponentiationOperator) Visits() []shimast.Kind {
|
|
981
|
+
return []shimast.Kind{shimast.KindCallExpression}
|
|
982
|
+
}
|
|
963
983
|
func (preferExponentiationOperator) Check(ctx *Context, node *shimast.Node) {
|
|
964
984
|
call := node.AsCallExpression()
|
|
965
985
|
if call == nil {
|
|
@@ -974,8 +994,8 @@ func (preferExponentiationOperator) Check(ctx *Context, node *shimast.Node) {
|
|
|
974
994
|
// prefer-spread: `fn.apply(null, args)` → `fn(...args)`.
|
|
975
995
|
type preferSpread struct{}
|
|
976
996
|
|
|
977
|
-
func (preferSpread) Name() string
|
|
978
|
-
func (preferSpread) Visits() []shimast.Kind
|
|
997
|
+
func (preferSpread) Name() string { return "prefer-spread" }
|
|
998
|
+
func (preferSpread) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindCallExpression} }
|
|
979
999
|
func (preferSpread) Check(ctx *Context, node *shimast.Node) {
|
|
980
1000
|
call := node.AsCallExpression()
|
|
981
1001
|
if call == nil || call.Expression == nil {
|
|
@@ -1007,8 +1027,8 @@ func (preferSpread) Check(ctx *Context, node *shimast.Node) {
|
|
|
1007
1027
|
// a non-literal.
|
|
1008
1028
|
type preferTemplate struct{}
|
|
1009
1029
|
|
|
1010
|
-
func (preferTemplate) Name() string
|
|
1011
|
-
func (preferTemplate) Visits() []shimast.Kind
|
|
1030
|
+
func (preferTemplate) Name() string { return "prefer-template" }
|
|
1031
|
+
func (preferTemplate) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
1012
1032
|
func (preferTemplate) Check(ctx *Context, node *shimast.Node) {
|
|
1013
1033
|
expr := node.AsBinaryExpression()
|
|
1014
1034
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -1054,8 +1074,10 @@ func concatChainShape(node *shimast.Node) (hasString bool, hasOther bool) {
|
|
|
1054
1074
|
// never yield are usually unintended.
|
|
1055
1075
|
type requireYield struct{}
|
|
1056
1076
|
|
|
1057
|
-
func (requireYield) Name() string
|
|
1058
|
-
func (requireYield) Visits() []shimast.Kind
|
|
1077
|
+
func (requireYield) Name() string { return "require-yield" }
|
|
1078
|
+
func (requireYield) Visits() []shimast.Kind {
|
|
1079
|
+
return []shimast.Kind{shimast.KindFunctionDeclaration, shimast.KindFunctionExpression, shimast.KindMethodDeclaration}
|
|
1080
|
+
}
|
|
1059
1081
|
func (requireYield) Check(ctx *Context, node *shimast.Node) {
|
|
1060
1082
|
if !hasAsteriskModifier(node) {
|
|
1061
1083
|
return
|
|
@@ -1112,8 +1134,8 @@ func subtreeContainsYield(node *shimast.Node) bool {
|
|
|
1112
1134
|
// function/script scope.
|
|
1113
1135
|
type varsOnTop struct{}
|
|
1114
1136
|
|
|
1115
|
-
func (varsOnTop) Name() string
|
|
1116
|
-
func (varsOnTop) Visits() []shimast.Kind
|
|
1137
|
+
func (varsOnTop) Name() string { return "vars-on-top" }
|
|
1138
|
+
func (varsOnTop) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindVariableStatement} }
|
|
1117
1139
|
func (varsOnTop) Check(ctx *Context, node *shimast.Node) {
|
|
1118
1140
|
stmt := node.AsVariableStatement()
|
|
1119
1141
|
if stmt == nil || stmt.DeclarationList == nil {
|
|
@@ -1180,8 +1202,8 @@ func parentStatements(parent *shimast.Node) []*shimast.Node {
|
|
|
1180
1202
|
// comparison as "yoda conditions". Default mode forbids them.
|
|
1181
1203
|
type yoda struct{}
|
|
1182
1204
|
|
|
1183
|
-
func (yoda) Name() string
|
|
1184
|
-
func (yoda) Visits() []shimast.Kind
|
|
1205
|
+
func (yoda) Name() string { return "yoda" }
|
|
1206
|
+
func (yoda) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindBinaryExpression} }
|
|
1185
1207
|
func (yoda) Check(ctx *Context, node *shimast.Node) {
|
|
1186
1208
|
expr := node.AsBinaryExpression()
|
|
1187
1209
|
if expr == nil || expr.OperatorToken == nil {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package main
|
|
2
2
|
|
|
3
3
|
import shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
4
4
|
|
|
@@ -6,8 +6,8 @@ import shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
|
6
6
|
// https://eslint.org/docs/latest/rules/no-throw-literal
|
|
7
7
|
type noThrowLiteral struct{}
|
|
8
8
|
|
|
9
|
-
func (noThrowLiteral) Name() string
|
|
10
|
-
func (noThrowLiteral) Visits() []shimast.Kind
|
|
9
|
+
func (noThrowLiteral) Name() string { return "no-throw-literal" }
|
|
10
|
+
func (noThrowLiteral) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindThrowStatement} }
|
|
11
11
|
func (noThrowLiteral) Check(ctx *Context, node *shimast.Node) {
|
|
12
12
|
throw := node.AsThrowStatement()
|
|
13
13
|
if throw == nil {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package main
|
|
2
2
|
|
|
3
3
|
import shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
4
4
|
|
|
@@ -6,8 +6,8 @@ import shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
|
6
6
|
// `@typescript-eslint/no-explicit-any`.
|
|
7
7
|
type noExplicitAny struct{}
|
|
8
8
|
|
|
9
|
-
func (noExplicitAny) Name() string
|
|
10
|
-
func (noExplicitAny) Visits() []shimast.Kind
|
|
9
|
+
func (noExplicitAny) Name() string { return "no-explicit-any" }
|
|
10
|
+
func (noExplicitAny) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindAnyKeyword} }
|
|
11
11
|
func (noExplicitAny) Check(ctx *Context, node *shimast.Node) {
|
|
12
12
|
ctx.Report(node, "Unexpected any. Specify a different type.")
|
|
13
13
|
}
|
|
@@ -15,8 +15,10 @@ func (noExplicitAny) Check(ctx *Context, node *shimast.Node) {
|
|
|
15
15
|
// no-non-null-assertion: ban the postfix `!` non-null assertion.
|
|
16
16
|
type noNonNullAssertion struct{}
|
|
17
17
|
|
|
18
|
-
func (noNonNullAssertion) Name() string
|
|
19
|
-
func (noNonNullAssertion) Visits() []shimast.Kind
|
|
18
|
+
func (noNonNullAssertion) Name() string { return "no-non-null-assertion" }
|
|
19
|
+
func (noNonNullAssertion) Visits() []shimast.Kind {
|
|
20
|
+
return []shimast.Kind{shimast.KindNonNullExpression}
|
|
21
|
+
}
|
|
20
22
|
func (noNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
|
|
21
23
|
ctx.Report(node, "Forbidden non-null assertion.")
|
|
22
24
|
}
|
|
@@ -25,8 +27,10 @@ func (noNonNullAssertion) Check(ctx *Context, node *shimast.Node) {
|
|
|
25
27
|
// for the supertype with extra ceremony.
|
|
26
28
|
type noEmptyInterface struct{}
|
|
27
29
|
|
|
28
|
-
func (noEmptyInterface) Name() string
|
|
29
|
-
func (noEmptyInterface) Visits() []shimast.Kind
|
|
30
|
+
func (noEmptyInterface) Name() string { return "no-empty-interface" }
|
|
31
|
+
func (noEmptyInterface) Visits() []shimast.Kind {
|
|
32
|
+
return []shimast.Kind{shimast.KindInterfaceDeclaration}
|
|
33
|
+
}
|
|
30
34
|
func (noEmptyInterface) Check(ctx *Context, node *shimast.Node) {
|
|
31
35
|
decl := node.AsInterfaceDeclaration()
|
|
32
36
|
if decl == nil || decl.Members == nil {
|
|
@@ -41,8 +45,10 @@ func (noEmptyInterface) Check(ctx *Context, node *shimast.Node) {
|
|
|
41
45
|
// would have inferred anyway.
|
|
42
46
|
type noInferrableTypes struct{}
|
|
43
47
|
|
|
44
|
-
func (noInferrableTypes) Name() string
|
|
45
|
-
func (noInferrableTypes) Visits() []shimast.Kind
|
|
48
|
+
func (noInferrableTypes) Name() string { return "no-inferrable-types" }
|
|
49
|
+
func (noInferrableTypes) Visits() []shimast.Kind {
|
|
50
|
+
return []shimast.Kind{shimast.KindVariableDeclaration, shimast.KindParameter, shimast.KindPropertyDeclaration}
|
|
51
|
+
}
|
|
46
52
|
func (noInferrableTypes) Check(ctx *Context, node *shimast.Node) {
|
|
47
53
|
var typeNode, init *shimast.Node
|
|
48
54
|
switch node.Kind {
|
|
@@ -114,8 +120,8 @@ func isUnaryNumeric(node *shimast.Node) bool {
|
|
|
114
120
|
// exist for legacy reasons; modern TS uses ES modules.
|
|
115
121
|
type noNamespace struct{}
|
|
116
122
|
|
|
117
|
-
func (noNamespace) Name() string
|
|
118
|
-
func (noNamespace) Visits() []shimast.Kind
|
|
123
|
+
func (noNamespace) Name() string { return "no-namespace" }
|
|
124
|
+
func (noNamespace) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindModuleDeclaration} }
|
|
119
125
|
func (noNamespace) Check(ctx *Context, node *shimast.Node) {
|
|
120
126
|
decl := node.AsModuleDeclaration()
|
|
121
127
|
if decl == nil || decl.Name() == nil {
|
|
@@ -133,8 +139,8 @@ func (noNamespace) Check(ctx *Context, node *shimast.Node) {
|
|
|
133
139
|
// arrow functions or `.bind(this)` instead.
|
|
134
140
|
type noThisAlias struct{}
|
|
135
141
|
|
|
136
|
-
func (noThisAlias) Name() string
|
|
137
|
-
func (noThisAlias) Visits() []shimast.Kind
|
|
142
|
+
func (noThisAlias) Name() string { return "no-this-alias" }
|
|
143
|
+
func (noThisAlias) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindVariableDeclaration} }
|
|
138
144
|
func (noThisAlias) Check(ctx *Context, node *shimast.Node) {
|
|
139
145
|
decl := node.AsVariableDeclaration()
|
|
140
146
|
if decl == nil || decl.Initializer == nil {
|
|
@@ -148,8 +154,10 @@ func (noThisAlias) Check(ctx *Context, node *shimast.Node) {
|
|
|
148
154
|
// prefer-as-const: `as 'foo'` / `as 1` should be `as const`.
|
|
149
155
|
type preferAsConst struct{}
|
|
150
156
|
|
|
151
|
-
func (preferAsConst) Name() string
|
|
152
|
-
func (preferAsConst) Visits() []shimast.Kind
|
|
157
|
+
func (preferAsConst) Name() string { return "prefer-as-const" }
|
|
158
|
+
func (preferAsConst) Visits() []shimast.Kind {
|
|
159
|
+
return []shimast.Kind{shimast.KindAsExpression, shimast.KindTypeAssertionExpression}
|
|
160
|
+
}
|
|
153
161
|
func (preferAsConst) Check(ctx *Context, node *shimast.Node) {
|
|
154
162
|
var expr, typeNode *shimast.Node
|
|
155
163
|
switch node.Kind {
|
|
@@ -198,8 +206,10 @@ func literalsMatchSourceText(file *shimast.SourceFile, lhs, rhs *shimast.Node) b
|
|
|
198
206
|
// ES `import` instead.
|
|
199
207
|
type noRequireImports struct{}
|
|
200
208
|
|
|
201
|
-
func (noRequireImports) Name() string
|
|
202
|
-
func (noRequireImports) Visits() []shimast.Kind
|
|
209
|
+
func (noRequireImports) Name() string { return "no-require-imports" }
|
|
210
|
+
func (noRequireImports) Visits() []shimast.Kind {
|
|
211
|
+
return []shimast.Kind{shimast.KindCallExpression, shimast.KindImportEqualsDeclaration}
|
|
212
|
+
}
|
|
203
213
|
func (noRequireImports) Check(ctx *Context, node *shimast.Node) {
|
|
204
214
|
switch node.Kind {
|
|
205
215
|
case shimast.KindCallExpression:
|
|
@@ -221,8 +231,8 @@ func (noRequireImports) Check(ctx *Context, node *shimast.Node) {
|
|
|
221
231
|
// silence the type checker. Default mode flags every variant.
|
|
222
232
|
type banTsComment struct{}
|
|
223
233
|
|
|
224
|
-
func (banTsComment) Name() string
|
|
225
|
-
func (banTsComment) Visits() []shimast.Kind
|
|
234
|
+
func (banTsComment) Name() string { return "ban-ts-comment" }
|
|
235
|
+
func (banTsComment) Visits() []shimast.Kind { return []shimast.Kind{shimast.KindSourceFile} }
|
|
226
236
|
func (banTsComment) Check(ctx *Context, node *shimast.Node) {
|
|
227
237
|
if ctx.File == nil {
|
|
228
238
|
return
|