@flint.fyi/ts 0.14.2 → 0.14.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/CHANGELOG.md +17 -0
- package/lib/createTypeScriptFileFromProgram.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/language.d.ts +1 -0
- package/lib/nodes.d.ts +1 -0
- package/lib/plugin.d.ts +165 -1
- package/lib/plugin.js +82 -0
- package/lib/rules/anyReturns.d.ts +6 -0
- package/lib/rules/anyReturns.js +187 -0
- package/lib/rules/anyReturns.test.d.ts +1 -0
- package/lib/rules/anyReturns.test.js +647 -0
- package/lib/rules/asyncPromiseExecutors.d.ts +6 -0
- package/lib/rules/asyncPromiseExecutors.js +51 -0
- package/lib/rules/asyncPromiseExecutors.test.d.ts +1 -0
- package/lib/rules/asyncPromiseExecutors.test.js +71 -0
- package/lib/rules/caseDeclarations.d.ts +6 -0
- package/lib/rules/caseDeclarations.js +53 -0
- package/lib/rules/caseDeclarations.test.d.ts +1 -0
- package/lib/rules/caseDeclarations.test.js +227 -0
- package/lib/rules/caseDuplicates.d.ts +6 -0
- package/lib/rules/caseDuplicates.js +49 -0
- package/lib/rules/caseDuplicates.test.d.ts +1 -0
- package/lib/rules/caseDuplicates.test.js +307 -0
- package/lib/rules/chainedAssignments.d.ts +6 -0
- package/lib/rules/chainedAssignments.js +48 -0
- package/lib/rules/chainedAssignments.test.d.ts +1 -0
- package/lib/rules/chainedAssignments.test.js +238 -0
- package/lib/rules/classAssignments.d.ts +6 -0
- package/lib/rules/classAssignments.js +42 -0
- package/lib/rules/classAssignments.test.d.ts +1 -0
- package/lib/rules/classAssignments.test.js +156 -0
- package/lib/rules/constantAssignments.d.ts +6 -0
- package/lib/rules/constantAssignments.js +61 -0
- package/lib/rules/constantAssignments.test.d.ts +1 -0
- package/lib/rules/constantAssignments.test.js +221 -0
- package/lib/rules/constructorReturns.d.ts +6 -0
- package/lib/rules/constructorReturns.js +52 -0
- package/lib/rules/constructorReturns.test.d.ts +1 -0
- package/lib/rules/constructorReturns.test.js +96 -0
- package/lib/rules/defaultCaseLast.d.ts +6 -0
- package/lib/rules/defaultCaseLast.js +43 -0
- package/lib/rules/defaultCaseLast.test.d.ts +1 -0
- package/lib/rules/defaultCaseLast.test.js +195 -0
- package/lib/rules/duplicateArguments.d.ts +6 -0
- package/lib/rules/duplicateArguments.js +51 -0
- package/lib/rules/duplicateArguments.test.d.ts +1 -0
- package/lib/rules/duplicateArguments.test.js +139 -0
- package/lib/rules/elseIfDuplicates.d.ts +6 -0
- package/lib/rules/elseIfDuplicates.js +53 -0
- package/lib/rules/elseIfDuplicates.test.d.ts +1 -0
- package/lib/rules/elseIfDuplicates.test.js +176 -0
- package/lib/rules/emptyDestructures.d.ts +6 -0
- package/lib/rules/emptyDestructures.js +40 -0
- package/lib/rules/emptyDestructures.test.d.ts +1 -0
- package/lib/rules/emptyDestructures.test.js +186 -0
- package/lib/rules/emptyStaticBlocks.d.ts +6 -0
- package/lib/rules/emptyStaticBlocks.js +54 -0
- package/lib/rules/emptyStaticBlocks.test.d.ts +1 -0
- package/lib/rules/emptyStaticBlocks.test.js +167 -0
- package/lib/rules/exceptionAssignments.d.ts +6 -0
- package/lib/rules/exceptionAssignments.js +61 -0
- package/lib/rules/exceptionAssignments.test.d.ts +1 -0
- package/lib/rules/exceptionAssignments.test.js +264 -0
- package/lib/rules/forDirections.d.ts +6 -0
- package/lib/rules/forDirections.js +124 -0
- package/lib/rules/forDirections.test.d.ts +1 -0
- package/lib/rules/forDirections.test.js +99 -0
- package/lib/rules/functionAssignments.d.ts +6 -0
- package/lib/rules/functionAssignments.js +42 -0
- package/lib/rules/functionAssignments.test.d.ts +1 -0
- package/lib/rules/functionAssignments.test.js +209 -0
- package/lib/rules/functionNewCalls.d.ts +6 -0
- package/lib/rules/functionNewCalls.js +60 -0
- package/lib/rules/functionNewCalls.test.d.ts +1 -0
- package/lib/rules/functionNewCalls.test.js +115 -0
- package/lib/rules/generatorFunctionYields.d.ts +6 -0
- package/lib/rules/generatorFunctionYields.js +57 -0
- package/lib/rules/generatorFunctionYields.test.d.ts +1 -0
- package/lib/rules/generatorFunctionYields.test.js +151 -0
- package/lib/rules/globalAssignments.d.ts +6 -0
- package/lib/rules/globalAssignments.js +59 -0
- package/lib/rules/globalAssignments.test.d.ts +1 -0
- package/lib/rules/globalAssignments.test.js +215 -0
- package/lib/rules/globalObjectCalls.d.ts +6 -0
- package/lib/rules/globalObjectCalls.js +43 -0
- package/lib/rules/globalObjectCalls.test.d.ts +1 -0
- package/lib/rules/globalObjectCalls.test.js +93 -0
- package/lib/rules/negativeZeroComparisons.d.ts +6 -0
- package/lib/rules/negativeZeroComparisons.js +65 -0
- package/lib/rules/negativeZeroComparisons.test.d.ts +1 -0
- package/lib/rules/negativeZeroComparisons.test.js +209 -0
- package/lib/rules/newExpressions.d.ts +6 -0
- package/lib/rules/newExpressions.js +54 -0
- package/lib/rules/newExpressions.test.d.ts +1 -0
- package/lib/rules/newExpressions.test.js +79 -0
- package/lib/rules/newNativeNonConstructors.d.ts +6 -0
- package/lib/rules/newNativeNonConstructors.js +49 -0
- package/lib/rules/newNativeNonConstructors.test.d.ts +1 -0
- package/lib/rules/newNativeNonConstructors.test.js +94 -0
- package/lib/rules/nonOctalDecimalEscapes.d.ts +6 -0
- package/lib/rules/nonOctalDecimalEscapes.js +57 -0
- package/lib/rules/nonOctalDecimalEscapes.test.d.ts +1 -0
- package/lib/rules/nonOctalDecimalEscapes.test.js +69 -0
- package/lib/rules/numericLiteralParsing.d.ts +6 -0
- package/lib/rules/numericLiteralParsing.js +97 -0
- package/lib/rules/numericLiteralParsing.test.d.ts +1 -0
- package/lib/rules/numericLiteralParsing.test.js +99 -0
- package/lib/rules/objectProto.d.ts +6 -0
- package/lib/rules/objectProto.js +54 -0
- package/lib/rules/objectProto.test.d.ts +1 -0
- package/lib/rules/objectProto.test.js +96 -0
- package/lib/rules/octalNumbers.d.ts +6 -0
- package/lib/rules/octalNumbers.js +68 -0
- package/lib/rules/octalNumbers.test.d.ts +1 -0
- package/lib/rules/octalNumbers.test.js +245 -0
- package/lib/rules/returnAssignments.d.ts +6 -0
- package/lib/rules/returnAssignments.js +50 -0
- package/lib/rules/returnAssignments.test.d.ts +1 -0
- package/lib/rules/returnAssignments.test.js +185 -0
- package/lib/rules/selfAssignments.d.ts +6 -0
- package/lib/rules/selfAssignments.js +44 -0
- package/lib/rules/selfAssignments.test.d.ts +1 -0
- package/lib/rules/selfAssignments.test.js +66 -0
- package/lib/rules/selfComparisons.d.ts +6 -0
- package/lib/rules/selfComparisons.js +41 -0
- package/lib/rules/selfComparisons.test.d.ts +1 -0
- package/lib/rules/selfComparisons.test.js +297 -0
- package/lib/rules/sequences.d.ts +6 -0
- package/lib/rules/sequences.js +34 -0
- package/lib/rules/sequences.test.d.ts +1 -0
- package/lib/rules/sequences.test.js +48 -0
- package/lib/rules/sparseArrays.d.ts +6 -0
- package/lib/rules/sparseArrays.js +54 -0
- package/lib/rules/sparseArrays.test.d.ts +1 -0
- package/lib/rules/sparseArrays.test.js +110 -0
- package/lib/rules/symbolDescriptions.d.ts +6 -0
- package/lib/rules/symbolDescriptions.js +41 -0
- package/lib/rules/symbolDescriptions.test.d.ts +1 -0
- package/lib/rules/symbolDescriptions.test.js +89 -0
- package/lib/rules/typeofComparisons.d.ts +6 -0
- package/lib/rules/typeofComparisons.js +78 -0
- package/lib/rules/typeofComparisons.test.d.ts +1 -0
- package/lib/rules/typeofComparisons.test.js +85 -0
- package/lib/rules/unassignedVariables.d.ts +6 -0
- package/lib/rules/unassignedVariables.js +55 -0
- package/lib/rules/unassignedVariables.test.d.ts +1 -0
- package/lib/rules/unassignedVariables.test.js +72 -0
- package/lib/rules/undefinedVariables.d.ts +6 -0
- package/lib/rules/undefinedVariables.js +76 -0
- package/lib/rules/undefinedVariables.test.d.ts +1 -0
- package/lib/rules/undefinedVariables.test.js +80 -0
- package/lib/rules/unicodeBOMs.d.ts +6 -0
- package/lib/rules/unicodeBOMs.js +41 -0
- package/lib/rules/unicodeBOMs.test.d.ts +1 -0
- package/lib/rules/unicodeBOMs.test.js +65 -0
- package/lib/rules/unnecessaryCatches.d.ts +6 -0
- package/lib/rules/unnecessaryCatches.js +68 -0
- package/lib/rules/unnecessaryCatches.test.d.ts +1 -0
- package/lib/rules/unnecessaryCatches.test.js +210 -0
- package/lib/rules/unsafeNegations.d.ts +6 -0
- package/lib/rules/unsafeNegations.js +50 -0
- package/lib/rules/unsafeNegations.test.d.ts +1 -0
- package/lib/rules/unsafeNegations.test.js +63 -0
- package/lib/rules/utils/discriminateAnyType.d.ts +12 -0
- package/lib/rules/utils/discriminateAnyType.js +41 -0
- package/lib/rules/utils/getThisExpression.d.ts +2 -0
- package/lib/rules/utils/getThisExpression.js +23 -0
- package/lib/rules/utils/isUnsafeAssignment.d.ts +13 -0
- package/lib/rules/utils/isUnsafeAssignment.js +76 -0
- package/lib/rules/utils/operators.d.ts +4 -0
- package/lib/rules/utils/operators.js +36 -0
- package/lib/rules/variableDeletions.d.ts +6 -0
- package/lib/rules/variableDeletions.js +39 -0
- package/lib/rules/variableDeletions.test.d.ts +1 -0
- package/lib/rules/variableDeletions.test.js +75 -0
- package/lib/rules/voidOperator.d.ts +6 -0
- package/lib/rules/voidOperator.js +36 -0
- package/lib/rules/voidOperator.test.d.ts +1 -0
- package/lib/rules/voidOperator.test.js +98 -0
- package/lib/utils/declarationIncludesGlobal.d.ts +2 -0
- package/lib/utils/declarationIncludesGlobal.js +5 -0
- package/lib/utils/declarationsIncludeGlobal.d.ts +2 -0
- package/lib/utils/declarationsIncludeGlobal.js +4 -0
- package/lib/utils/getModifyingReferences.d.ts +8 -0
- package/lib/utils/getModifyingReferences.js +42 -0
- package/lib/utils/hasSameTokens.d.ts +2 -0
- package/lib/utils/hasSameTokens.js +30 -0
- package/lib/utils/isGlobalDeclaration.d.ts +2 -0
- package/lib/utils/isGlobalDeclaration.js +5 -0
- package/lib/utils/isGlobalDeclarationOfName.d.ts +5 -0
- package/lib/utils/isGlobalDeclarationOfName.js +31 -0
- package/lib/utils/isGlobalVariable.d.ts +8 -0
- package/lib/utils/isGlobalVariable.js +21 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +2 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.js +6 -0
- package/lib/utils/unwrapParenthesizedExpression.d.ts +2 -0
- package/lib/utils/unwrapParenthesizedExpression.js +6 -0
- package/package.json +1 -1
- package/src/createTypeScriptFileFromProgram.ts +1 -0
- package/src/index.ts +1 -0
- package/src/language.ts +1 -0
- package/src/nodes.ts +1 -0
- package/src/plugin.ts +82 -0
- package/src/rules/anyReturns.test.ts +649 -0
- package/src/rules/anyReturns.ts +263 -0
- package/src/rules/asyncPromiseExecutors.test.ts +72 -0
- package/src/rules/asyncPromiseExecutors.ts +61 -0
- package/src/rules/caseDeclarations.test.ts +228 -0
- package/src/rules/caseDeclarations.ts +70 -0
- package/src/rules/caseDuplicates.test.ts +308 -0
- package/src/rules/caseDuplicates.ts +57 -0
- package/src/rules/chainedAssignments.test.ts +239 -0
- package/src/rules/chainedAssignments.ts +55 -0
- package/src/rules/classAssignments.test.ts +157 -0
- package/src/rules/classAssignments.ts +50 -0
- package/src/rules/constantAssignments.test.ts +222 -0
- package/src/rules/constantAssignments.ts +78 -0
- package/src/rules/constructorReturns.test.ts +97 -0
- package/src/rules/constructorReturns.ts +59 -0
- package/src/rules/defaultCaseLast.test.ts +196 -0
- package/src/rules/defaultCaseLast.ts +54 -0
- package/src/rules/duplicateArguments.test.ts +140 -0
- package/src/rules/duplicateArguments.ts +58 -0
- package/src/rules/elseIfDuplicates.test.ts +177 -0
- package/src/rules/elseIfDuplicates.ts +69 -0
- package/src/rules/emptyDestructures.test.ts +187 -0
- package/src/rules/emptyDestructures.ts +48 -0
- package/src/rules/emptyStaticBlocks.test.ts +168 -0
- package/src/rules/emptyStaticBlocks.ts +60 -0
- package/src/rules/exceptionAssignments.test.ts +265 -0
- package/src/rules/exceptionAssignments.ts +77 -0
- package/src/rules/forDirections.test.ts +100 -0
- package/src/rules/forDirections.ts +163 -0
- package/src/rules/functionAssignments.test.ts +210 -0
- package/src/rules/functionAssignments.ts +51 -0
- package/src/rules/functionNewCalls.test.ts +116 -0
- package/src/rules/functionNewCalls.ts +75 -0
- package/src/rules/generatorFunctionYields.test.ts +152 -0
- package/src/rules/generatorFunctionYields.ts +71 -0
- package/src/rules/globalAssignments.test.ts +216 -0
- package/src/rules/globalAssignments.ts +67 -0
- package/src/rules/globalObjectCalls.test.ts +94 -0
- package/src/rules/globalObjectCalls.ts +52 -0
- package/src/rules/negativeZeroComparisons.test.ts +210 -0
- package/src/rules/negativeZeroComparisons.ts +87 -0
- package/src/rules/newExpressions.test.ts +80 -0
- package/src/rules/newExpressions.ts +67 -0
- package/src/rules/newNativeNonConstructors.test.ts +95 -0
- package/src/rules/newNativeNonConstructors.ts +59 -0
- package/src/rules/nonOctalDecimalEscapes.test.ts +70 -0
- package/src/rules/nonOctalDecimalEscapes.ts +70 -0
- package/src/rules/numericLiteralParsing.test.ts +100 -0
- package/src/rules/numericLiteralParsing.ts +116 -0
- package/src/rules/objectProto.test.ts +97 -0
- package/src/rules/objectProto.ts +62 -0
- package/src/rules/octalNumbers.test.ts +246 -0
- package/src/rules/octalNumbers.ts +75 -0
- package/src/rules/returnAssignments.test.ts +186 -0
- package/src/rules/returnAssignments.ts +57 -0
- package/src/rules/selfAssignments.test.ts +67 -0
- package/src/rules/selfAssignments.ts +50 -0
- package/src/rules/selfComparisons.test.ts +298 -0
- package/src/rules/selfComparisons.ts +45 -0
- package/src/rules/sequences.test.ts +49 -0
- package/src/rules/sequences.ts +37 -0
- package/src/rules/sparseArrays.test.ts +111 -0
- package/src/rules/sparseArrays.ts +61 -0
- package/src/rules/symbolDescriptions.test.ts +90 -0
- package/src/rules/symbolDescriptions.ts +47 -0
- package/src/rules/typeofComparisons.test.ts +86 -0
- package/src/rules/typeofComparisons.ts +88 -0
- package/src/rules/unassignedVariables.test.ts +73 -0
- package/src/rules/unassignedVariables.ts +69 -0
- package/src/rules/undefinedVariables.test.ts +81 -0
- package/src/rules/undefinedVariables.ts +97 -0
- package/src/rules/unicodeBOMs.test.ts +66 -0
- package/src/rules/unicodeBOMs.ts +44 -0
- package/src/rules/unnecessaryCatches.test.ts +211 -0
- package/src/rules/unnecessaryCatches.ts +84 -0
- package/src/rules/unsafeNegations.test.ts +64 -0
- package/src/rules/unsafeNegations.ts +59 -0
- package/src/rules/utils/discriminateAnyType.ts +66 -0
- package/src/rules/utils/getThisExpression.ts +24 -0
- package/src/rules/utils/isUnsafeAssignment.ts +113 -0
- package/src/rules/utils/operators.ts +39 -0
- package/src/rules/variableDeletions.test.ts +76 -0
- package/src/rules/variableDeletions.ts +43 -0
- package/src/rules/voidOperator.test.ts +99 -0
- package/src/rules/voidOperator.ts +38 -0
- package/src/utils/declarationIncludesGlobal.ts +9 -0
- package/src/utils/declarationsIncludeGlobal.ts +7 -0
- package/src/utils/getModifyingReferences.ts +58 -0
- package/src/utils/hasSameTokens.ts +45 -0
- package/src/utils/isGlobalDeclaration.ts +12 -0
- package/src/utils/isGlobalDeclarationOfName.ts +51 -0
- package/src/utils/isGlobalVariable.ts +30 -0
- package/src/utils/unwrapParentParenthesizedExpressions.ts +7 -0
- package/src/utils/unwrapParenthesizedExpression.ts +9 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import rule from "./functionAssignments.js";
|
|
2
|
+
import { ruleTester } from "./ruleTester.js";
|
|
3
|
+
ruleTester.describe(rule, {
|
|
4
|
+
invalid: [
|
|
5
|
+
{
|
|
6
|
+
code: `
|
|
7
|
+
function myFunction() {}
|
|
8
|
+
myFunction = function() {};
|
|
9
|
+
`,
|
|
10
|
+
snapshot: `
|
|
11
|
+
function myFunction() {}
|
|
12
|
+
myFunction = function() {};
|
|
13
|
+
~~~~~~~~~~
|
|
14
|
+
Variables declared with function declarations should not be reassigned.
|
|
15
|
+
`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
code: `
|
|
19
|
+
function myFunction() {}
|
|
20
|
+
myFunction = 123;
|
|
21
|
+
`,
|
|
22
|
+
snapshot: `
|
|
23
|
+
function myFunction() {}
|
|
24
|
+
myFunction = 123;
|
|
25
|
+
~~~~~~~~~~
|
|
26
|
+
Variables declared with function declarations should not be reassigned.
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: `
|
|
31
|
+
function myFunction() {}
|
|
32
|
+
myFunction += 1;
|
|
33
|
+
`,
|
|
34
|
+
snapshot: `
|
|
35
|
+
function myFunction() {}
|
|
36
|
+
myFunction += 1;
|
|
37
|
+
~~~~~~~~~~
|
|
38
|
+
Variables declared with function declarations should not be reassigned.
|
|
39
|
+
`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: `
|
|
43
|
+
function myFunction() {}
|
|
44
|
+
myFunction++;
|
|
45
|
+
`,
|
|
46
|
+
snapshot: `
|
|
47
|
+
function myFunction() {}
|
|
48
|
+
myFunction++;
|
|
49
|
+
~~~~~~~~~~
|
|
50
|
+
Variables declared with function declarations should not be reassigned.
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: `
|
|
55
|
+
function myFunction() {}
|
|
56
|
+
++myFunction;
|
|
57
|
+
`,
|
|
58
|
+
snapshot: `
|
|
59
|
+
function myFunction() {}
|
|
60
|
+
++myFunction;
|
|
61
|
+
~~~~~~~~~~
|
|
62
|
+
Variables declared with function declarations should not be reassigned.
|
|
63
|
+
`,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: `
|
|
67
|
+
function myFunction() {
|
|
68
|
+
return 42;
|
|
69
|
+
}
|
|
70
|
+
myFunction = () => 100;
|
|
71
|
+
`,
|
|
72
|
+
snapshot: `
|
|
73
|
+
function myFunction() {
|
|
74
|
+
return 42;
|
|
75
|
+
}
|
|
76
|
+
myFunction = () => 100;
|
|
77
|
+
~~~~~~~~~~
|
|
78
|
+
Variables declared with function declarations should not be reassigned.
|
|
79
|
+
`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
code: `
|
|
83
|
+
function outer() {
|
|
84
|
+
function inner() {}
|
|
85
|
+
inner = function() {};
|
|
86
|
+
}
|
|
87
|
+
`,
|
|
88
|
+
snapshot: `
|
|
89
|
+
function outer() {
|
|
90
|
+
function inner() {}
|
|
91
|
+
inner = function() {};
|
|
92
|
+
~~~~~
|
|
93
|
+
Variables declared with function declarations should not be reassigned.
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
code: `
|
|
99
|
+
function myFunction() {}
|
|
100
|
+
if (condition) {
|
|
101
|
+
myFunction = null;
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
snapshot: `
|
|
105
|
+
function myFunction() {}
|
|
106
|
+
if (condition) {
|
|
107
|
+
myFunction = null;
|
|
108
|
+
~~~~~~~~~~
|
|
109
|
+
Variables declared with function declarations should not be reassigned.
|
|
110
|
+
}
|
|
111
|
+
`,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
code: `
|
|
115
|
+
function getValue() {
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
getValue ??= function() { return 0; };
|
|
119
|
+
`,
|
|
120
|
+
snapshot: `
|
|
121
|
+
function getValue() {
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
getValue ??= function() { return 0; };
|
|
125
|
+
~~~~~~~~
|
|
126
|
+
Variables declared with function declarations should not be reassigned.
|
|
127
|
+
`,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
code: `
|
|
131
|
+
function getValue() {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
getValue &&= false;
|
|
135
|
+
`,
|
|
136
|
+
snapshot: `
|
|
137
|
+
function getValue() {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
getValue &&= false;
|
|
141
|
+
~~~~~~~~
|
|
142
|
+
Variables declared with function declarations should not be reassigned.
|
|
143
|
+
`,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
code: `
|
|
147
|
+
function getValue() {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
getValue ||= () => true;
|
|
151
|
+
`,
|
|
152
|
+
snapshot: `
|
|
153
|
+
function getValue() {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
getValue ||= () => true;
|
|
157
|
+
~~~~~~~~
|
|
158
|
+
Variables declared with function declarations should not be reassigned.
|
|
159
|
+
`,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
code: `
|
|
163
|
+
function calculate(value: number): number {
|
|
164
|
+
return value * 2;
|
|
165
|
+
}
|
|
166
|
+
calculate = (value: number) => value * 3;
|
|
167
|
+
`,
|
|
168
|
+
snapshot: `
|
|
169
|
+
function calculate(value: number): number {
|
|
170
|
+
return value * 2;
|
|
171
|
+
}
|
|
172
|
+
calculate = (value: number) => value * 3;
|
|
173
|
+
~~~~~~~~~
|
|
174
|
+
Variables declared with function declarations should not be reassigned.
|
|
175
|
+
`,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
valid: [
|
|
179
|
+
`function myFunction() { return 42; }`,
|
|
180
|
+
`function myFunction() {} const result = myFunction();`,
|
|
181
|
+
`const myFunction = function() {}; myFunction = () => {};`,
|
|
182
|
+
`const myFunction = () => {}; myFunction = function() {};`,
|
|
183
|
+
`let myFunction = function() {}; myFunction = () => {};`,
|
|
184
|
+
`function outer() { const inner = function() {}; inner = () => {}; }`,
|
|
185
|
+
`
|
|
186
|
+
function outer() {
|
|
187
|
+
const myFunction = "shadowed variable";
|
|
188
|
+
myFunction = "reassigning shadowed variable is ok";
|
|
189
|
+
}
|
|
190
|
+
`,
|
|
191
|
+
`
|
|
192
|
+
let myFunction = "outer variable";
|
|
193
|
+
function scope() {
|
|
194
|
+
function myFunction() {}
|
|
195
|
+
console.log(myFunction);
|
|
196
|
+
}
|
|
197
|
+
myFunction = "reassigning outer is ok";
|
|
198
|
+
`,
|
|
199
|
+
`function myFunction() {} const copy = myFunction;`,
|
|
200
|
+
`function myFunction() {} if (condition) { callWith(myFunction); }`,
|
|
201
|
+
`
|
|
202
|
+
function myFunction() {
|
|
203
|
+
return function nested() {
|
|
204
|
+
return 42;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
`,
|
|
208
|
+
],
|
|
209
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Reports using the Function constructor to create functions from strings.";
|
|
3
|
+
readonly id: "functionNewCalls";
|
|
4
|
+
readonly preset: "logical";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "noFunctionConstructor", undefined>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
3
|
+
import { typescriptLanguage } from "../language.js";
|
|
4
|
+
import { isGlobalDeclaration } from "../utils/isGlobalDeclaration.js";
|
|
5
|
+
import { isGlobalDeclarationOfName } from "../utils/isGlobalDeclarationOfName.js";
|
|
6
|
+
export default typescriptLanguage.createRule({
|
|
7
|
+
about: {
|
|
8
|
+
description: "Reports using the Function constructor to create functions from strings.",
|
|
9
|
+
id: "functionNewCalls",
|
|
10
|
+
preset: "logical",
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
noFunctionConstructor: {
|
|
14
|
+
primary: "Dynamically creating functions with the Function constructor is insecure and slow.",
|
|
15
|
+
secondary: [
|
|
16
|
+
"Using the `Function` constructor to create functions from strings is similar to `eval()` and introduces security risks and performance issues.",
|
|
17
|
+
"Code passed to the Function constructor is executed in the global scope, making it harder to optimize and potentially allowing arbitrary code execution if user input is involved.",
|
|
18
|
+
],
|
|
19
|
+
suggestions: [
|
|
20
|
+
"Define functions using function declarations (`function name() {}`) or arrow functions (`() => {}`) instead.",
|
|
21
|
+
"If dynamic code generation is truly necessary, consider safer alternatives like passing functions as parameters or using a more constrained domain-specific approach.",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
setup(context) {
|
|
26
|
+
function checkNode(node) {
|
|
27
|
+
if (isFunctionConstructor(node)) {
|
|
28
|
+
context.report({
|
|
29
|
+
message: "noFunctionConstructor",
|
|
30
|
+
range: getTSNodeRange(node.expression, context.sourceFile),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function isFunctionConstructor(node) {
|
|
35
|
+
if (ts.isIdentifier(node.expression)) {
|
|
36
|
+
if (isGlobalDeclarationOfName(node.expression, "Function", context.typeChecker)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (ts.isPropertyAccessExpression(node.expression) &&
|
|
41
|
+
isGlobalDeclaration(node.expression, context.typeChecker)) {
|
|
42
|
+
const propertyName = node.expression.name.text;
|
|
43
|
+
if (propertyName !== "Function") {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const object = node.expression.expression;
|
|
47
|
+
if (ts.isIdentifier(object)) {
|
|
48
|
+
return object.text === "globalThis" || object.text === "window";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
visitors: {
|
|
55
|
+
CallExpression: checkNode,
|
|
56
|
+
NewExpression: checkNode,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import rule from "./functionNewCalls.js";
|
|
2
|
+
import { ruleTester } from "./ruleTester.js";
|
|
3
|
+
ruleTester.describe(rule, {
|
|
4
|
+
invalid: [
|
|
5
|
+
{
|
|
6
|
+
code: `
|
|
7
|
+
const fn = new Function("a", "b", "return a + b");
|
|
8
|
+
`,
|
|
9
|
+
snapshot: `
|
|
10
|
+
const fn = new Function("a", "b", "return a + b");
|
|
11
|
+
~~~~~~~~
|
|
12
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
13
|
+
`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: `
|
|
17
|
+
const fn = Function("a", "return a");
|
|
18
|
+
`,
|
|
19
|
+
snapshot: `
|
|
20
|
+
const fn = Function("a", "return a");
|
|
21
|
+
~~~~~~~~
|
|
22
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
23
|
+
`,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
code: `
|
|
27
|
+
const fn = new Function("return 1");
|
|
28
|
+
`,
|
|
29
|
+
snapshot: `
|
|
30
|
+
const fn = new Function("return 1");
|
|
31
|
+
~~~~~~~~
|
|
32
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
33
|
+
`,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: `
|
|
37
|
+
const fn = Function();
|
|
38
|
+
`,
|
|
39
|
+
snapshot: `
|
|
40
|
+
const fn = Function();
|
|
41
|
+
~~~~~~~~
|
|
42
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
43
|
+
`,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: `
|
|
47
|
+
const fn = new globalThis.Function("return 1");
|
|
48
|
+
`,
|
|
49
|
+
snapshot: `
|
|
50
|
+
const fn = new globalThis.Function("return 1");
|
|
51
|
+
~~~~~~~~~~~~~~~~~~~
|
|
52
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
53
|
+
`,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
code: `
|
|
57
|
+
const fn = globalThis.Function("return 1");
|
|
58
|
+
`,
|
|
59
|
+
snapshot: `
|
|
60
|
+
const fn = globalThis.Function("return 1");
|
|
61
|
+
~~~~~~~~~~~~~~~~~~~
|
|
62
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
63
|
+
`,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: `
|
|
67
|
+
const fn = new window.Function("return 1");
|
|
68
|
+
`,
|
|
69
|
+
snapshot: `
|
|
70
|
+
const fn = new window.Function("return 1");
|
|
71
|
+
~~~~~~~~~~~~~~~
|
|
72
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
73
|
+
`,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
code: `
|
|
77
|
+
const fn = window.Function("return 1");
|
|
78
|
+
`,
|
|
79
|
+
snapshot: `
|
|
80
|
+
const fn = window.Function("return 1");
|
|
81
|
+
~~~~~~~~~~~~~~~
|
|
82
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
83
|
+
`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
code: `
|
|
87
|
+
const result = new Function("a", "b", "return a + b")(1, 2);
|
|
88
|
+
`,
|
|
89
|
+
snapshot: `
|
|
90
|
+
const result = new Function("a", "b", "return a + b")(1, 2);
|
|
91
|
+
~~~~~~~~
|
|
92
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
93
|
+
`,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
code: `
|
|
97
|
+
const CustomFunction = Function;
|
|
98
|
+
const fn = new CustomFunction();
|
|
99
|
+
`,
|
|
100
|
+
snapshot: `
|
|
101
|
+
const CustomFunction = Function;
|
|
102
|
+
const fn = new CustomFunction();
|
|
103
|
+
~~~~~~~~~~~~~~
|
|
104
|
+
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
105
|
+
`,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
valid: [
|
|
109
|
+
`const fn = function(a, b) { return a + b; };`,
|
|
110
|
+
`const fn = (a, b) => a + b;`,
|
|
111
|
+
`function add(a, b) { return a + b; }`,
|
|
112
|
+
`class MyFunction {}`,
|
|
113
|
+
`const fn = new MyFunction();`,
|
|
114
|
+
],
|
|
115
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Reports generator functions that do not yield values.";
|
|
3
|
+
readonly id: "generatorFunctionYields";
|
|
4
|
+
readonly preset: "logical";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "missingYield", undefined>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as tsutils from "ts-api-utils";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import { typescriptLanguage } from "../language.js";
|
|
4
|
+
export default typescriptLanguage.createRule({
|
|
5
|
+
about: {
|
|
6
|
+
description: "Reports generator functions that do not yield values.",
|
|
7
|
+
id: "generatorFunctionYields",
|
|
8
|
+
preset: "logical",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
missingYield: {
|
|
12
|
+
primary: "Generator functions must contain at least one yield expression to produce values.",
|
|
13
|
+
secondary: [
|
|
14
|
+
"Generator functions use the `function*` syntax to create iterators that can produce multiple values over time.",
|
|
15
|
+
"Without a yield expression, the generator will not produce any values and behaves like an empty iterator.",
|
|
16
|
+
"This is likely unintentional and indicates incomplete implementation or a misunderstanding of generator functions.",
|
|
17
|
+
],
|
|
18
|
+
suggestions: [
|
|
19
|
+
"Add a `yield` expression to produce values from the generator.",
|
|
20
|
+
"If the function should not be a generator, remove the asterisk (`*`) from the function declaration.",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
setup(context) {
|
|
25
|
+
return {
|
|
26
|
+
visitors: {
|
|
27
|
+
FunctionDeclaration: checkFunction,
|
|
28
|
+
FunctionExpression: checkFunction,
|
|
29
|
+
MethodDeclaration: checkFunction,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
function checkFunction(node) {
|
|
33
|
+
if (!node.asteriskToken || !node.body || blockContainsYield(node.body)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
context.report({
|
|
37
|
+
message: "missingYield",
|
|
38
|
+
range: {
|
|
39
|
+
begin: node.asteriskToken.getStart(context.sourceFile),
|
|
40
|
+
end: node.asteriskToken.getEnd(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
function blockContainsYield(block) {
|
|
47
|
+
function checkForYield(node) {
|
|
48
|
+
if (ts.isYieldExpression(node)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (tsutils.isFunctionScopeBoundary(node)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return ts.forEachChild(node, checkForYield);
|
|
55
|
+
}
|
|
56
|
+
return ts.forEachChild(block, checkForYield);
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import rule from "./generatorFunctionYields.js";
|
|
2
|
+
import { ruleTester } from "./ruleTester.js";
|
|
3
|
+
ruleTester.describe(rule, {
|
|
4
|
+
invalid: [
|
|
5
|
+
{
|
|
6
|
+
code: `
|
|
7
|
+
function* emptyGenerator() {
|
|
8
|
+
console.log("No yield here");
|
|
9
|
+
}
|
|
10
|
+
`,
|
|
11
|
+
snapshot: `
|
|
12
|
+
function* emptyGenerator() {
|
|
13
|
+
~
|
|
14
|
+
Generator functions must contain at least one yield expression to produce values.
|
|
15
|
+
console.log("No yield here");
|
|
16
|
+
}
|
|
17
|
+
`,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
code: `
|
|
21
|
+
const generator = function* () {
|
|
22
|
+
return 42;
|
|
23
|
+
};
|
|
24
|
+
`,
|
|
25
|
+
snapshot: `
|
|
26
|
+
const generator = function* () {
|
|
27
|
+
~
|
|
28
|
+
Generator functions must contain at least one yield expression to produce values.
|
|
29
|
+
return 42;
|
|
30
|
+
};
|
|
31
|
+
`,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
code: `
|
|
35
|
+
class MyClass {
|
|
36
|
+
*generatorMethod() {
|
|
37
|
+
this.doSomething();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`,
|
|
41
|
+
snapshot: `
|
|
42
|
+
class MyClass {
|
|
43
|
+
*generatorMethod() {
|
|
44
|
+
~
|
|
45
|
+
Generator functions must contain at least one yield expression to produce values.
|
|
46
|
+
this.doSomething();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: `
|
|
53
|
+
function* generatorWithNestedFunction() {
|
|
54
|
+
function inner() {
|
|
55
|
+
yield 42;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
`,
|
|
59
|
+
snapshot: `
|
|
60
|
+
function* generatorWithNestedFunction() {
|
|
61
|
+
~
|
|
62
|
+
Generator functions must contain at least one yield expression to produce values.
|
|
63
|
+
function inner() {
|
|
64
|
+
yield 42;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
code: `
|
|
71
|
+
function* generatorWithNestedGeneratorFunction() {
|
|
72
|
+
function* inner() {
|
|
73
|
+
yield 42;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`,
|
|
77
|
+
snapshot: `
|
|
78
|
+
function* generatorWithNestedGeneratorFunction() {
|
|
79
|
+
~
|
|
80
|
+
Generator functions must contain at least one yield expression to produce values.
|
|
81
|
+
function* inner() {
|
|
82
|
+
yield 42;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
valid: [
|
|
89
|
+
`
|
|
90
|
+
function* validGenerator() {
|
|
91
|
+
yield 1;
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
`
|
|
95
|
+
function* validGeneratorMultiple() {
|
|
96
|
+
yield 1;
|
|
97
|
+
yield 2;
|
|
98
|
+
yield 3;
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
`
|
|
102
|
+
const generator = function* () {
|
|
103
|
+
yield 42;
|
|
104
|
+
};
|
|
105
|
+
`,
|
|
106
|
+
`
|
|
107
|
+
class MyClass {
|
|
108
|
+
*generatorMethod() {
|
|
109
|
+
yield this.value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`,
|
|
113
|
+
`
|
|
114
|
+
function* conditionalYield(condition: boolean) {
|
|
115
|
+
if (condition) {
|
|
116
|
+
yield 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`,
|
|
120
|
+
`
|
|
121
|
+
function* yieldInLoop() {
|
|
122
|
+
for (let i = 0; i < 10; i++) {
|
|
123
|
+
yield i;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
`,
|
|
127
|
+
`
|
|
128
|
+
function* yieldDelegate() {
|
|
129
|
+
yield* [1, 2, 3];
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
`
|
|
133
|
+
function regularFunction() {
|
|
134
|
+
return 42;
|
|
135
|
+
}
|
|
136
|
+
`,
|
|
137
|
+
`
|
|
138
|
+
const arrow = () => {
|
|
139
|
+
return 42;
|
|
140
|
+
};
|
|
141
|
+
`,
|
|
142
|
+
`
|
|
143
|
+
function* generatorWithNestedGenerator() {
|
|
144
|
+
yield 1;
|
|
145
|
+
function* inner() {
|
|
146
|
+
yield 2;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
`,
|
|
150
|
+
],
|
|
151
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Reports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc.";
|
|
3
|
+
readonly id: "globalAssignments";
|
|
4
|
+
readonly preset: "untyped";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptServices, "noGlobalAssign", undefined>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as tsutils from "ts-api-utils";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
4
|
+
import { typescriptLanguage } from "../language.js";
|
|
5
|
+
import { isGlobalVariable } from "../utils/isGlobalVariable.js";
|
|
6
|
+
export default typescriptLanguage.createRule({
|
|
7
|
+
about: {
|
|
8
|
+
description: "Reports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc.",
|
|
9
|
+
id: "globalAssignments",
|
|
10
|
+
preset: "untyped",
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
noGlobalAssign: {
|
|
14
|
+
primary: "Read-only global variables should not be reassigned or modified.",
|
|
15
|
+
secondary: [
|
|
16
|
+
"Global variables like undefined, NaN, Infinity, and built-in objects like Object and Array are read-only and should not be modified.",
|
|
17
|
+
"Attempting to reassign these globals can lead to confusing behavior and potential bugs in your code.",
|
|
18
|
+
"In strict mode, reassigning these globals will throw a TypeError at runtime.",
|
|
19
|
+
],
|
|
20
|
+
suggestions: [
|
|
21
|
+
"Use a different variable name instead of shadowing or reassigning globals.",
|
|
22
|
+
"If you need a similar name, consider using a more specific name that doesn't conflict with global variables.",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
setup(context) {
|
|
27
|
+
return {
|
|
28
|
+
visitors: {
|
|
29
|
+
BinaryExpression: (node) => {
|
|
30
|
+
if (tsutils.isAssignmentKind(node.operatorToken.kind) &&
|
|
31
|
+
isGlobalVariable(node.left, context.typeChecker)) {
|
|
32
|
+
context.report({
|
|
33
|
+
message: "noGlobalAssign",
|
|
34
|
+
range: getTSNodeRange(node.left, context.sourceFile),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
PostfixUnaryExpression: (node) => {
|
|
39
|
+
if (isGlobalVariable(node.operand, context.typeChecker)) {
|
|
40
|
+
context.report({
|
|
41
|
+
message: "noGlobalAssign",
|
|
42
|
+
range: getTSNodeRange(node.operand, context.sourceFile),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
PrefixUnaryExpression: (node) => {
|
|
47
|
+
if ((node.operator === ts.SyntaxKind.PlusPlusToken ||
|
|
48
|
+
node.operator === ts.SyntaxKind.MinusMinusToken) &&
|
|
49
|
+
isGlobalVariable(node.operand, context.typeChecker)) {
|
|
50
|
+
context.report({
|
|
51
|
+
message: "noGlobalAssign",
|
|
52
|
+
range: getTSNodeRange(node.operand, context.sourceFile),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|