@flint.fyi/ts 0.14.5 → 0.15.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.
- package/lib/collectReferencedFilePaths.d.ts +1 -0
- package/lib/collectReferencedFilePaths.js +3 -2
- package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +14 -0
- package/lib/{formatDiagnostic.js → convertTypeScriptDiagnosticToLanguageFileDiagnostic.js} +23 -15
- package/lib/createTypeScriptFileFromProgram.d.ts +4 -1
- package/lib/createTypeScriptFileFromProgram.js +25 -30
- package/lib/createTypeScriptFileFromProjectService.d.ts +3 -6
- package/lib/createTypeScriptFileFromProjectService.js +5 -11
- package/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +8 -0
- package/lib/directives/parseDirectivesFromTypeScriptFile.js +12 -4
- package/lib/directives/parseDirectivesFromTypeScriptFile.test.d.ts +1 -0
- package/lib/directives/parseDirectivesFromTypeScriptFile.test.js +1 -0
- package/lib/getFirstEnumValues.d.ts +1 -0
- package/lib/getFirstEnumValues.js +1 -0
- package/lib/getFirstEnumValues.test.d.ts +1 -0
- package/lib/getFirstEnumValues.test.js +1 -0
- package/lib/getTSNodeRange.d.ts +1 -0
- package/lib/getTSNodeRange.js +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -0
- package/lib/language.d.ts +3 -2
- package/lib/language.js +7 -52
- package/lib/nodes.d.ts +1 -0
- package/lib/nodes.js +1 -0
- package/lib/normalizeRange.d.ts +1 -0
- package/lib/normalizeRange.js +4 -6
- package/lib/plugin.d.ts +79 -50
- package/lib/plugin.js +16 -1
- package/lib/prepareTypeScriptBasedLanguage.d.ts +11 -0
- package/lib/prepareTypeScriptBasedLanguage.js +59 -0
- package/lib/prepareTypeScriptFile.d.ts +9 -4
- package/lib/prepareTypeScriptFile.js +8 -2
- package/lib/rules/anyReturns.d.ts +2 -1
- package/lib/rules/anyReturns.js +22 -22
- package/lib/rules/anyReturns.test.d.ts +1 -0
- package/lib/rules/anyReturns.test.js +1 -0
- package/lib/rules/asyncPromiseExecutors.d.ts +2 -1
- package/lib/rules/asyncPromiseExecutors.js +4 -3
- package/lib/rules/asyncPromiseExecutors.test.d.ts +1 -0
- package/lib/rules/asyncPromiseExecutors.test.js +1 -0
- package/lib/rules/caseDeclarations.d.ts +3 -1
- package/lib/rules/caseDeclarations.js +7 -6
- package/lib/rules/caseDeclarations.test.d.ts +1 -0
- package/lib/rules/caseDeclarations.test.js +1 -0
- package/lib/rules/caseDuplicates.d.ts +2 -1
- package/lib/rules/caseDuplicates.js +4 -3
- package/lib/rules/caseDuplicates.test.d.ts +1 -0
- package/lib/rules/caseDuplicates.test.js +1 -0
- package/lib/rules/chainedAssignments.d.ts +2 -1
- package/lib/rules/chainedAssignments.js +3 -2
- package/lib/rules/chainedAssignments.test.d.ts +1 -0
- package/lib/rules/chainedAssignments.test.js +1 -0
- package/lib/rules/classAssignments.d.ts +2 -1
- package/lib/rules/classAssignments.js +4 -3
- package/lib/rules/classAssignments.test.d.ts +1 -0
- package/lib/rules/classAssignments.test.js +1 -0
- package/lib/rules/consecutiveNonNullAssertions.d.ts +2 -1
- package/lib/rules/consecutiveNonNullAssertions.js +1 -0
- package/lib/rules/consecutiveNonNullAssertions.test.d.ts +1 -0
- package/lib/rules/consecutiveNonNullAssertions.test.js +1 -0
- package/lib/rules/constantAssignments.d.ts +2 -1
- package/lib/rules/constantAssignments.js +4 -3
- package/lib/rules/constantAssignments.test.d.ts +1 -0
- package/lib/rules/constantAssignments.test.js +1 -0
- package/lib/rules/constructorReturns.d.ts +2 -1
- package/lib/rules/constructorReturns.js +3 -2
- package/lib/rules/constructorReturns.test.d.ts +1 -0
- package/lib/rules/constructorReturns.test.js +1 -0
- package/lib/rules/debuggerStatements.d.ts +2 -1
- package/lib/rules/debuggerStatements.js +1 -0
- package/lib/rules/debuggerStatements.test.d.ts +1 -0
- package/lib/rules/debuggerStatements.test.js +1 -0
- package/lib/rules/defaultCaseLast.d.ts +2 -1
- package/lib/rules/defaultCaseLast.js +4 -3
- package/lib/rules/defaultCaseLast.test.d.ts +1 -0
- package/lib/rules/defaultCaseLast.test.js +1 -0
- package/lib/rules/duplicateArguments.d.ts +3 -1
- package/lib/rules/duplicateArguments.js +3 -2
- package/lib/rules/duplicateArguments.test.d.ts +1 -0
- package/lib/rules/duplicateArguments.test.js +1 -0
- package/lib/rules/elseIfDuplicates.d.ts +2 -1
- package/lib/rules/elseIfDuplicates.js +6 -5
- package/lib/rules/elseIfDuplicates.test.d.ts +1 -0
- package/lib/rules/elseIfDuplicates.test.js +1 -0
- package/lib/rules/emptyBlocks.d.ts +2 -1
- package/lib/rules/emptyBlocks.js +12 -10
- package/lib/rules/emptyBlocks.test.d.ts +1 -0
- package/lib/rules/emptyBlocks.test.js +1 -0
- package/lib/rules/emptyDestructures.d.ts +3 -1
- package/lib/rules/emptyDestructures.js +3 -2
- package/lib/rules/emptyDestructures.test.d.ts +1 -0
- package/lib/rules/emptyDestructures.test.js +1 -0
- package/lib/rules/emptyStaticBlocks.d.ts +2 -1
- package/lib/rules/emptyStaticBlocks.js +5 -4
- package/lib/rules/emptyStaticBlocks.test.d.ts +1 -0
- package/lib/rules/emptyStaticBlocks.test.js +1 -0
- package/lib/rules/exceptionAssignments.d.ts +2 -1
- package/lib/rules/exceptionAssignments.js +4 -3
- package/lib/rules/exceptionAssignments.test.d.ts +1 -0
- package/lib/rules/exceptionAssignments.test.js +1 -0
- package/lib/rules/finallyStatementSafety.d.ts +7 -0
- package/lib/rules/finallyStatementSafety.js +71 -0
- package/lib/rules/finallyStatementSafety.test.d.ts +2 -0
- package/lib/rules/finallyStatementSafety.test.js +307 -0
- package/lib/rules/forDirections.d.ts +2 -1
- package/lib/rules/forDirections.js +18 -10
- package/lib/rules/forDirections.test.d.ts +1 -0
- package/lib/rules/forDirections.test.js +26 -0
- package/lib/rules/forInArrays.d.ts +2 -1
- package/lib/rules/forInArrays.js +8 -7
- package/lib/rules/forInArrays.test.d.ts +1 -0
- package/lib/rules/forInArrays.test.js +1 -0
- package/lib/rules/functionAssignments.d.ts +2 -1
- package/lib/rules/functionAssignments.js +4 -3
- package/lib/rules/functionAssignments.test.d.ts +1 -0
- package/lib/rules/functionAssignments.test.js +1 -0
- package/lib/rules/functionCurryingRedundancy.d.ts +7 -0
- package/lib/rules/functionCurryingRedundancy.js +77 -0
- package/lib/rules/functionCurryingRedundancy.test.d.ts +2 -0
- package/lib/rules/functionCurryingRedundancy.test.js +172 -0
- package/lib/rules/functionNewCalls.d.ts +3 -1
- package/lib/rules/functionNewCalls.js +7 -6
- package/lib/rules/functionNewCalls.test.d.ts +1 -0
- package/lib/rules/functionNewCalls.test.js +1 -0
- package/lib/rules/generatorFunctionYields.d.ts +3 -1
- package/lib/rules/generatorFunctionYields.js +3 -2
- package/lib/rules/generatorFunctionYields.test.d.ts +1 -0
- package/lib/rules/generatorFunctionYields.test.js +1 -0
- package/lib/rules/globalAssignments.d.ts +2 -1
- package/lib/rules/globalAssignments.js +10 -9
- package/lib/rules/globalAssignments.test.d.ts +1 -0
- package/lib/rules/globalAssignments.test.js +1 -0
- package/lib/rules/globalObjectCalls.d.ts +3 -1
- package/lib/rules/globalObjectCalls.js +5 -4
- package/lib/rules/globalObjectCalls.test.d.ts +1 -0
- package/lib/rules/globalObjectCalls.test.js +1 -0
- package/lib/rules/namespaceDeclarations.d.ts +2 -1
- package/lib/rules/namespaceDeclarations.js +7 -6
- package/lib/rules/namespaceDeclarations.test.d.ts +1 -0
- package/lib/rules/namespaceDeclarations.test.js +1 -0
- package/lib/rules/negativeZeroComparisons.d.ts +2 -1
- package/lib/rules/negativeZeroComparisons.js +8 -7
- package/lib/rules/negativeZeroComparisons.test.d.ts +1 -0
- package/lib/rules/negativeZeroComparisons.test.js +1 -0
- package/lib/rules/newExpressions.d.ts +2 -1
- package/lib/rules/newExpressions.js +3 -2
- package/lib/rules/newExpressions.test.d.ts +1 -0
- package/lib/rules/newExpressions.test.js +1 -0
- package/lib/rules/newNativeNonConstructors.d.ts +2 -1
- package/lib/rules/newNativeNonConstructors.js +6 -5
- package/lib/rules/newNativeNonConstructors.test.d.ts +1 -0
- package/lib/rules/newNativeNonConstructors.test.js +1 -0
- package/lib/rules/nonOctalDecimalEscapes.d.ts +3 -1
- package/lib/rules/nonOctalDecimalEscapes.js +4 -3
- package/lib/rules/nonOctalDecimalEscapes.test.d.ts +1 -0
- package/lib/rules/nonOctalDecimalEscapes.test.js +1 -0
- package/lib/rules/numericLiteralParsing.d.ts +2 -1
- package/lib/rules/numericLiteralParsing.js +8 -7
- package/lib/rules/numericLiteralParsing.test.d.ts +1 -0
- package/lib/rules/numericLiteralParsing.test.js +1 -0
- package/lib/rules/objectCalls.d.ts +7 -0
- package/lib/rules/objectCalls.js +47 -0
- package/lib/rules/objectCalls.test.d.ts +2 -0
- package/lib/rules/objectCalls.test.js +172 -0
- package/lib/rules/objectHasOwns.d.ts +7 -0
- package/lib/rules/objectHasOwns.js +74 -0
- package/lib/rules/objectHasOwns.test.d.ts +2 -0
- package/lib/rules/objectHasOwns.test.js +112 -0
- package/lib/rules/objectKeyDuplicates.d.ts +7 -0
- package/lib/rules/objectKeyDuplicates.js +91 -0
- package/lib/rules/objectKeyDuplicates.test.d.ts +2 -0
- package/lib/rules/objectKeyDuplicates.test.js +180 -0
- package/lib/rules/objectProto.d.ts +2 -1
- package/lib/rules/objectProto.js +5 -4
- package/lib/rules/objectProto.test.d.ts +1 -0
- package/lib/rules/objectProto.test.js +1 -0
- package/lib/rules/objectPrototypeBuiltIns.d.ts +7 -0
- package/lib/rules/objectPrototypeBuiltIns.js +65 -0
- package/lib/rules/objectPrototypeBuiltIns.test.d.ts +2 -0
- package/lib/rules/objectPrototypeBuiltIns.test.js +146 -0
- package/lib/rules/octalEscapes.d.ts +2 -1
- package/lib/rules/octalEscapes.js +13 -8
- package/lib/rules/octalEscapes.test.d.ts +1 -0
- package/lib/rules/octalEscapes.test.js +1 -0
- package/lib/rules/octalNumbers.d.ts +2 -1
- package/lib/rules/octalNumbers.js +4 -3
- package/lib/rules/octalNumbers.test.d.ts +1 -0
- package/lib/rules/octalNumbers.test.js +1 -0
- package/lib/rules/returnAssignments.d.ts +2 -1
- package/lib/rules/returnAssignments.js +7 -6
- package/lib/rules/returnAssignments.test.d.ts +1 -0
- package/lib/rules/returnAssignments.test.js +1 -0
- package/lib/rules/ruleTester.d.ts +1 -0
- package/lib/rules/ruleTester.js +6 -1
- package/lib/rules/selfAssignments.d.ts +2 -1
- package/lib/rules/selfAssignments.js +4 -3
- package/lib/rules/selfAssignments.test.d.ts +1 -0
- package/lib/rules/selfAssignments.test.js +1 -0
- package/lib/rules/selfComparisons.d.ts +2 -1
- package/lib/rules/selfComparisons.js +4 -3
- package/lib/rules/selfComparisons.test.d.ts +1 -0
- package/lib/rules/selfComparisons.test.js +1 -0
- package/lib/rules/sequences.d.ts +2 -1
- package/lib/rules/sequences.js +3 -2
- package/lib/rules/sequences.test.d.ts +1 -0
- package/lib/rules/sequences.test.js +1 -0
- package/lib/rules/shadowedRestrictedNames.d.ts +2 -1
- package/lib/rules/shadowedRestrictedNames.js +24 -23
- package/lib/rules/shadowedRestrictedNames.test.d.ts +1 -0
- package/lib/rules/shadowedRestrictedNames.test.js +1 -0
- package/lib/rules/sparseArrays.d.ts +2 -1
- package/lib/rules/sparseArrays.js +5 -4
- package/lib/rules/sparseArrays.test.d.ts +1 -0
- package/lib/rules/sparseArrays.test.js +1 -0
- package/lib/rules/symbolDescriptions.d.ts +2 -1
- package/lib/rules/symbolDescriptions.js +3 -2
- package/lib/rules/symbolDescriptions.test.d.ts +1 -0
- package/lib/rules/symbolDescriptions.test.js +1 -0
- package/lib/rules/typeofComparisons.d.ts +2 -1
- package/lib/rules/typeofComparisons.js +5 -4
- package/lib/rules/typeofComparisons.test.d.ts +1 -0
- package/lib/rules/typeofComparisons.test.js +1 -0
- package/lib/rules/unassignedVariables.d.ts +2 -1
- package/lib/rules/unassignedVariables.js +4 -3
- package/lib/rules/unassignedVariables.test.d.ts +1 -0
- package/lib/rules/unassignedVariables.test.js +1 -0
- package/lib/rules/undefinedVariables.d.ts +2 -1
- package/lib/rules/undefinedVariables.js +5 -4
- package/lib/rules/undefinedVariables.test.d.ts +1 -0
- package/lib/rules/undefinedVariables.test.js +1 -0
- package/lib/rules/unicodeBOMs.d.ts +2 -1
- package/lib/rules/unicodeBOMs.js +27 -20
- package/lib/rules/unicodeBOMs.test.d.ts +1 -0
- package/lib/rules/unicodeBOMs.test.js +1 -0
- package/lib/rules/unnecessaryBlocks.d.ts +2 -1
- package/lib/rules/unnecessaryBlocks.js +4 -3
- package/lib/rules/unnecessaryBlocks.test.d.ts +1 -0
- package/lib/rules/unnecessaryBlocks.test.js +1 -0
- package/lib/rules/unnecessaryCatches.d.ts +2 -1
- package/lib/rules/unnecessaryCatches.js +4 -3
- package/lib/rules/unnecessaryCatches.test.d.ts +1 -0
- package/lib/rules/unnecessaryCatches.test.js +1 -0
- package/lib/rules/unnecessaryConcatenation.d.ts +2 -1
- package/lib/rules/unnecessaryConcatenation.js +3 -2
- package/lib/rules/unnecessaryConcatenation.test.d.ts +1 -0
- package/lib/rules/unnecessaryConcatenation.test.js +1 -0
- package/lib/rules/unsafeNegations.d.ts +2 -1
- package/lib/rules/unsafeNegations.js +3 -2
- package/lib/rules/unsafeNegations.test.d.ts +1 -0
- package/lib/rules/unsafeNegations.test.js +1 -0
- package/lib/rules/utils/discriminateAnyType.d.ts +1 -0
- package/lib/rules/utils/discriminateAnyType.js +1 -0
- package/lib/rules/utils/getConstrainedType.d.ts +1 -0
- package/lib/rules/utils/getConstrainedType.js +1 -0
- package/lib/rules/utils/getThisExpression.d.ts +1 -0
- package/lib/rules/utils/getThisExpression.js +1 -0
- package/lib/rules/utils/isTypeRecursive.d.ts +1 -0
- package/lib/rules/utils/isTypeRecursive.js +1 -0
- package/lib/rules/utils/isUnsafeAssignment.d.ts +1 -0
- package/lib/rules/utils/isUnsafeAssignment.js +1 -0
- package/lib/rules/utils/operators.d.ts +1 -0
- package/lib/rules/utils/operators.js +1 -0
- package/lib/rules/variableDeletions.d.ts +2 -1
- package/lib/rules/variableDeletions.js +3 -2
- package/lib/rules/variableDeletions.test.d.ts +1 -0
- package/lib/rules/variableDeletions.test.js +1 -0
- package/lib/rules/voidOperator.d.ts +2 -1
- package/lib/rules/voidOperator.js +3 -2
- package/lib/rules/voidOperator.test.d.ts +1 -0
- package/lib/rules/voidOperator.test.js +1 -0
- package/lib/rules/withStatements.d.ts +7 -0
- package/lib/rules/withStatements.js +37 -0
- package/lib/rules/withStatements.test.d.ts +2 -0
- package/lib/rules/withStatements.test.js +27 -0
- package/lib/utils/declarationIncludesGlobal.d.ts +1 -0
- package/lib/utils/declarationIncludesGlobal.js +1 -0
- package/lib/utils/declarationsIncludeGlobal.d.ts +1 -0
- package/lib/utils/declarationsIncludeGlobal.js +1 -0
- package/lib/utils/getDeclarationsIfGlobal.d.ts +1 -0
- package/lib/utils/getDeclarationsIfGlobal.js +1 -0
- package/lib/utils/getModifyingReferences.d.ts +1 -0
- package/lib/utils/getModifyingReferences.js +1 -0
- package/lib/utils/hasSameTokens.d.ts +1 -0
- package/lib/utils/hasSameTokens.js +1 -0
- package/lib/utils/isFunction.d.ts +3 -0
- package/lib/utils/isFunction.js +6 -0
- package/lib/utils/isGlobalDeclaration.d.ts +1 -0
- package/lib/utils/isGlobalDeclaration.js +1 -0
- package/lib/utils/isGlobalDeclarationOfName.d.ts +1 -0
- package/lib/utils/isGlobalDeclarationOfName.js +1 -0
- package/lib/utils/isGlobalVariable.d.ts +1 -0
- package/lib/utils/isGlobalVariable.js +1 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +1 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.js +1 -0
- package/lib/utils/unwrapParenthesizedExpression.d.ts +1 -0
- package/lib/utils/unwrapParenthesizedExpression.js +1 -0
- package/package.json +17 -7
- package/CHANGELOG.md +0 -82
- package/lib/formatDiagnostic.d.ts +0 -10
- package/src/collectReferencedFilePaths.ts +0 -37
- package/src/createTypeScriptFileFromProgram.ts +0 -86
- package/src/createTypeScriptFileFromProjectService.ts +0 -31
- package/src/directives/parseDirectivesFromTypeScriptFile.test.ts +0 -108
- package/src/directives/parseDirectivesFromTypeScriptFile.ts +0 -31
- package/src/formatDiagnostic.ts +0 -166
- package/src/getFirstEnumValues.test.ts +0 -51
- package/src/getFirstEnumValues.ts +0 -59
- package/src/getTSNodeRange.ts +0 -13
- package/src/index.ts +0 -7
- package/src/language.ts +0 -122
- package/src/nodes.ts +0 -146
- package/src/normalizeRange.ts +0 -30
- package/src/plugin.ts +0 -111
- package/src/prepareTypeScriptFile.ts +0 -14
- package/src/rules/anyReturns.test.ts +0 -649
- package/src/rules/anyReturns.ts +0 -263
- package/src/rules/asyncPromiseExecutors.test.ts +0 -72
- package/src/rules/asyncPromiseExecutors.ts +0 -61
- package/src/rules/caseDeclarations.test.ts +0 -228
- package/src/rules/caseDeclarations.ts +0 -70
- package/src/rules/caseDuplicates.test.ts +0 -308
- package/src/rules/caseDuplicates.ts +0 -57
- package/src/rules/chainedAssignments.test.ts +0 -263
- package/src/rules/chainedAssignments.ts +0 -58
- package/src/rules/classAssignments.test.ts +0 -157
- package/src/rules/classAssignments.ts +0 -50
- package/src/rules/consecutiveNonNullAssertions.test.ts +0 -33
- package/src/rules/consecutiveNonNullAssertions.ts +0 -46
- package/src/rules/constantAssignments.test.ts +0 -222
- package/src/rules/constantAssignments.ts +0 -78
- package/src/rules/constructorReturns.test.ts +0 -97
- package/src/rules/constructorReturns.ts +0 -59
- package/src/rules/debuggerStatements.test.ts +0 -81
- package/src/rules/debuggerStatements.ts +0 -45
- package/src/rules/defaultCaseLast.test.ts +0 -196
- package/src/rules/defaultCaseLast.ts +0 -54
- package/src/rules/duplicateArguments.test.ts +0 -140
- package/src/rules/duplicateArguments.ts +0 -58
- package/src/rules/elseIfDuplicates.test.ts +0 -177
- package/src/rules/elseIfDuplicates.ts +0 -69
- package/src/rules/emptyBlocks.test.ts +0 -136
- package/src/rules/emptyBlocks.ts +0 -73
- package/src/rules/emptyDestructures.test.ts +0 -187
- package/src/rules/emptyDestructures.ts +0 -48
- package/src/rules/emptyStaticBlocks.test.ts +0 -168
- package/src/rules/emptyStaticBlocks.ts +0 -60
- package/src/rules/exceptionAssignments.test.ts +0 -265
- package/src/rules/exceptionAssignments.ts +0 -77
- package/src/rules/forDirections.test.ts +0 -100
- package/src/rules/forDirections.ts +0 -163
- package/src/rules/forInArrays.test.ts +0 -25
- package/src/rules/forInArrays.ts +0 -70
- package/src/rules/functionAssignments.test.ts +0 -210
- package/src/rules/functionAssignments.ts +0 -51
- package/src/rules/functionNewCalls.test.ts +0 -116
- package/src/rules/functionNewCalls.ts +0 -75
- package/src/rules/generatorFunctionYields.test.ts +0 -152
- package/src/rules/generatorFunctionYields.ts +0 -71
- package/src/rules/globalAssignments.test.ts +0 -216
- package/src/rules/globalAssignments.ts +0 -67
- package/src/rules/globalObjectCalls.test.ts +0 -94
- package/src/rules/globalObjectCalls.ts +0 -52
- package/src/rules/namespaceDeclarations.test.ts +0 -41
- package/src/rules/namespaceDeclarations.ts +0 -74
- package/src/rules/negativeZeroComparisons.test.ts +0 -210
- package/src/rules/negativeZeroComparisons.ts +0 -87
- package/src/rules/newExpressions.test.ts +0 -80
- package/src/rules/newExpressions.ts +0 -67
- package/src/rules/newNativeNonConstructors.test.ts +0 -95
- package/src/rules/newNativeNonConstructors.ts +0 -59
- package/src/rules/nonOctalDecimalEscapes.test.ts +0 -70
- package/src/rules/nonOctalDecimalEscapes.ts +0 -70
- package/src/rules/numericLiteralParsing.test.ts +0 -100
- package/src/rules/numericLiteralParsing.ts +0 -116
- package/src/rules/objectProto.test.ts +0 -97
- package/src/rules/objectProto.ts +0 -62
- package/src/rules/octalEscapes.test.ts +0 -214
- package/src/rules/octalEscapes.ts +0 -85
- package/src/rules/octalNumbers.test.ts +0 -246
- package/src/rules/octalNumbers.ts +0 -75
- package/src/rules/returnAssignments.test.ts +0 -186
- package/src/rules/returnAssignments.ts +0 -57
- package/src/rules/ruleTester.ts +0 -4
- package/src/rules/selfAssignments.test.ts +0 -67
- package/src/rules/selfAssignments.ts +0 -50
- package/src/rules/selfComparisons.test.ts +0 -298
- package/src/rules/selfComparisons.ts +0 -45
- package/src/rules/sequences.test.ts +0 -49
- package/src/rules/sequences.ts +0 -37
- package/src/rules/shadowedRestrictedNames.test.ts +0 -148
- package/src/rules/shadowedRestrictedNames.ts +0 -105
- package/src/rules/sparseArrays.test.ts +0 -111
- package/src/rules/sparseArrays.ts +0 -61
- package/src/rules/symbolDescriptions.test.ts +0 -90
- package/src/rules/symbolDescriptions.ts +0 -47
- package/src/rules/typeofComparisons.test.ts +0 -86
- package/src/rules/typeofComparisons.ts +0 -88
- package/src/rules/unassignedVariables.test.ts +0 -73
- package/src/rules/unassignedVariables.ts +0 -69
- package/src/rules/undefinedVariables.test.ts +0 -81
- package/src/rules/undefinedVariables.ts +0 -97
- package/src/rules/unicodeBOMs.test.ts +0 -67
- package/src/rules/unicodeBOMs.ts +0 -44
- package/src/rules/unnecessaryBlocks.test.ts +0 -148
- package/src/rules/unnecessaryBlocks.ts +0 -89
- package/src/rules/unnecessaryCatches.test.ts +0 -211
- package/src/rules/unnecessaryCatches.ts +0 -84
- package/src/rules/unnecessaryConcatenation.test.ts +0 -88
- package/src/rules/unnecessaryConcatenation.ts +0 -44
- package/src/rules/unsafeNegations.test.ts +0 -64
- package/src/rules/unsafeNegations.ts +0 -59
- package/src/rules/utils/discriminateAnyType.ts +0 -66
- package/src/rules/utils/getConstrainedType.ts +0 -9
- package/src/rules/utils/getThisExpression.ts +0 -24
- package/src/rules/utils/isTypeRecursive.ts +0 -10
- package/src/rules/utils/isUnsafeAssignment.ts +0 -113
- package/src/rules/utils/operators.ts +0 -39
- package/src/rules/variableDeletions.test.ts +0 -76
- package/src/rules/variableDeletions.ts +0 -43
- package/src/rules/voidOperator.test.ts +0 -99
- package/src/rules/voidOperator.ts +0 -38
- package/src/utils/declarationIncludesGlobal.ts +0 -9
- package/src/utils/declarationsIncludeGlobal.ts +0 -7
- package/src/utils/getDeclarationsIfGlobal.ts +0 -14
- package/src/utils/getModifyingReferences.ts +0 -58
- package/src/utils/hasSameTokens.ts +0 -45
- package/src/utils/isGlobalDeclaration.ts +0 -10
- package/src/utils/isGlobalDeclarationOfName.ts +0 -56
- package/src/utils/isGlobalVariable.ts +0 -30
- package/src/utils/unwrapParentParenthesizedExpressions.ts +0 -7
- package/src/utils/unwrapParenthesizedExpression.ts +0 -9
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
4
|
-
import { typescriptLanguage } from "../language.js";
|
|
5
|
-
|
|
6
|
-
function getConditionDirection(condition: ts.Expression, counterName: string) {
|
|
7
|
-
if (!ts.isBinaryExpression(condition)) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const leftName = getCounterName(condition.left);
|
|
12
|
-
const rightName = getCounterName(condition.right);
|
|
13
|
-
|
|
14
|
-
const isCounterLeft = leftName === counterName;
|
|
15
|
-
const isCounterRight = rightName === counterName;
|
|
16
|
-
|
|
17
|
-
if (!isCounterLeft && !isCounterRight) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { operatorToken } = condition;
|
|
22
|
-
|
|
23
|
-
if (isCounterLeft) {
|
|
24
|
-
if (
|
|
25
|
-
operatorToken.kind === ts.SyntaxKind.LessThanToken ||
|
|
26
|
-
operatorToken.kind === ts.SyntaxKind.LessThanEqualsToken
|
|
27
|
-
) {
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
if (
|
|
31
|
-
operatorToken.kind === ts.SyntaxKind.GreaterThanToken ||
|
|
32
|
-
operatorToken.kind === ts.SyntaxKind.GreaterThanEqualsToken
|
|
33
|
-
) {
|
|
34
|
-
return -1;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
if (
|
|
38
|
-
operatorToken.kind === ts.SyntaxKind.LessThanToken ||
|
|
39
|
-
operatorToken.kind === ts.SyntaxKind.LessThanEqualsToken
|
|
40
|
-
) {
|
|
41
|
-
return -1;
|
|
42
|
-
}
|
|
43
|
-
if (
|
|
44
|
-
operatorToken.kind === ts.SyntaxKind.GreaterThanToken ||
|
|
45
|
-
operatorToken.kind === ts.SyntaxKind.GreaterThanEqualsToken
|
|
46
|
-
) {
|
|
47
|
-
return 1;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getCounterName(node: ts.Expression) {
|
|
55
|
-
return ts.isIdentifier(node) ? node.text : undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getUpdateDirection(update: ts.Expression) {
|
|
59
|
-
if (
|
|
60
|
-
ts.isPostfixUnaryExpression(update) ||
|
|
61
|
-
ts.isPrefixUnaryExpression(update)
|
|
62
|
-
) {
|
|
63
|
-
switch (update.operator) {
|
|
64
|
-
case ts.SyntaxKind.MinusMinusToken:
|
|
65
|
-
return -1;
|
|
66
|
-
case ts.SyntaxKind.PlusPlusToken:
|
|
67
|
-
return 1;
|
|
68
|
-
default:
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (ts.isBinaryExpression(update)) {
|
|
74
|
-
const { operatorToken, right } = update;
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
operatorToken.kind === ts.SyntaxKind.PlusEqualsToken ||
|
|
78
|
-
operatorToken.kind === ts.SyntaxKind.MinusEqualsToken
|
|
79
|
-
) {
|
|
80
|
-
if (ts.isNumericLiteral(right)) {
|
|
81
|
-
const value = Number(right.text);
|
|
82
|
-
if (operatorToken.kind === ts.SyntaxKind.PlusEqualsToken) {
|
|
83
|
-
return value > 0 ? 1 : value < 0 ? -1 : 0;
|
|
84
|
-
}
|
|
85
|
-
return value > 0 ? -1 : value < 0 ? 1 : 0;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
ts.isPrefixUnaryExpression(right) &&
|
|
90
|
-
right.operator === ts.SyntaxKind.MinusToken &&
|
|
91
|
-
ts.isNumericLiteral(right.operand)
|
|
92
|
-
) {
|
|
93
|
-
const value = Number(right.operand.text);
|
|
94
|
-
if (operatorToken.kind === ts.SyntaxKind.PlusEqualsToken) {
|
|
95
|
-
return value > 0 ? -1 : 1;
|
|
96
|
-
}
|
|
97
|
-
return value > 0 ? 1 : -1;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default typescriptLanguage.createRule({
|
|
106
|
-
about: {
|
|
107
|
-
description:
|
|
108
|
-
"Reports for loops with counter variables that move in the wrong direction.",
|
|
109
|
-
id: "forDirections",
|
|
110
|
-
preset: "stylistic",
|
|
111
|
-
},
|
|
112
|
-
messages: {
|
|
113
|
-
wrongDirection: {
|
|
114
|
-
primary:
|
|
115
|
-
"The update moves the counter in the wrong direction for this loop condition.",
|
|
116
|
-
secondary: [
|
|
117
|
-
"A for loop with a counter that moves in the wrong direction relative to its stop condition will run infinitely or never execute.",
|
|
118
|
-
"When the counter increases but the condition expects it to decrease (or vice versa), the loop logic is incorrect.",
|
|
119
|
-
],
|
|
120
|
-
suggestions: [
|
|
121
|
-
"Verify the loop counter update direction matches the condition.",
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
setup(context) {
|
|
126
|
-
return {
|
|
127
|
-
visitors: {
|
|
128
|
-
ForStatement: (node) => {
|
|
129
|
-
if (
|
|
130
|
-
!node.condition ||
|
|
131
|
-
!node.incrementor ||
|
|
132
|
-
!node.initializer ||
|
|
133
|
-
!ts.isVariableDeclarationList(node.initializer)
|
|
134
|
-
) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const declaration = node.initializer.declarations.at(0);
|
|
139
|
-
if (!declaration || !ts.isIdentifier(declaration.name)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const updateDirection = getUpdateDirection(node.incrementor);
|
|
144
|
-
if (!updateDirection) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const conditionDirection = getConditionDirection(
|
|
149
|
-
node.condition,
|
|
150
|
-
declaration.name.text,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (updateDirection !== conditionDirection) {
|
|
154
|
-
context.report({
|
|
155
|
-
message: "wrongDirection",
|
|
156
|
-
range: getTSNodeRange(node.incrementor, context.sourceFile),
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import rule from "./forInArrays.js";
|
|
2
|
-
import { ruleTester } from "./ruleTester.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
declare const array: string[];
|
|
9
|
-
for (const i in array) {}
|
|
10
|
-
`,
|
|
11
|
-
snapshot: `
|
|
12
|
-
declare const array: string[];
|
|
13
|
-
for (const i in array) {}
|
|
14
|
-
~~~~~~~~~~~~~~~~~~~~~~
|
|
15
|
-
For-in loops over arrays have surprising behavior that often leads to bugs.
|
|
16
|
-
`,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
valid: [
|
|
20
|
-
`
|
|
21
|
-
declare const array: string[];
|
|
22
|
-
for (const i of array) {}
|
|
23
|
-
`,
|
|
24
|
-
],
|
|
25
|
-
});
|
package/src/rules/forInArrays.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as tsutils from "ts-api-utils";
|
|
2
|
-
import * as ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { typescriptLanguage } from "../language.js";
|
|
5
|
-
import { getConstrainedTypeAtLocation } from "./utils/getConstrainedType.js";
|
|
6
|
-
import { isTypeRecursive } from "./utils/isTypeRecursive.js";
|
|
7
|
-
|
|
8
|
-
export default typescriptLanguage.createRule({
|
|
9
|
-
about: {
|
|
10
|
-
description: "Reports iterating over an array with a for-in loop.",
|
|
11
|
-
id: "forInArrays",
|
|
12
|
-
preset: "logical",
|
|
13
|
-
},
|
|
14
|
-
messages: {
|
|
15
|
-
forIn: {
|
|
16
|
-
primary:
|
|
17
|
-
"For-in loops over arrays have surprising behavior that often leads to bugs.",
|
|
18
|
-
secondary: [
|
|
19
|
-
"A for-in loop (`for (const i in o)`) iterates over all enumerable properties of an object, including those that are not array indices.",
|
|
20
|
-
"This can lead to unexpected behavior when used with arrays, as it may include properties that are not part of the array's numeric indices.",
|
|
21
|
-
"It also returns the index key (`i`) as a string, which is not the expected numeric type for array indices.",
|
|
22
|
-
],
|
|
23
|
-
suggestions: [
|
|
24
|
-
"Use a construct more suited for arrays, such as a for-of loop (`for (const i of o)`).",
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
setup(context) {
|
|
29
|
-
function hasNumberLikeLength(type: ts.Type): boolean {
|
|
30
|
-
const lengthProperty = type.getProperty("length");
|
|
31
|
-
|
|
32
|
-
if (lengthProperty == null) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return tsutils.isTypeFlagSet(
|
|
37
|
-
context.typeChecker.getTypeOfSymbol(lengthProperty),
|
|
38
|
-
ts.TypeFlags.NumberLike,
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isArrayLike(type: ts.Type): boolean {
|
|
43
|
-
return isTypeRecursive(
|
|
44
|
-
type,
|
|
45
|
-
(t) => t.getNumberIndexType() != null && hasNumberLikeLength(t),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
visitors: {
|
|
51
|
-
ForInStatement: (node) => {
|
|
52
|
-
const type = getConstrainedTypeAtLocation(
|
|
53
|
-
node.expression,
|
|
54
|
-
context.typeChecker,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
if (isArrayLike(type)) {
|
|
58
|
-
context.report({
|
|
59
|
-
message: "forIn",
|
|
60
|
-
range: {
|
|
61
|
-
begin: node.getStart(),
|
|
62
|
-
end: node.statement.getStart() - 1,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import rule from "./functionAssignments.js";
|
|
2
|
-
import { ruleTester } from "./ruleTester.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
function myFunction() {}
|
|
9
|
-
myFunction = function() {};
|
|
10
|
-
`,
|
|
11
|
-
snapshot: `
|
|
12
|
-
function myFunction() {}
|
|
13
|
-
myFunction = function() {};
|
|
14
|
-
~~~~~~~~~~
|
|
15
|
-
Variables declared with function declarations should not be reassigned.
|
|
16
|
-
`,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
code: `
|
|
20
|
-
function myFunction() {}
|
|
21
|
-
myFunction = 123;
|
|
22
|
-
`,
|
|
23
|
-
snapshot: `
|
|
24
|
-
function myFunction() {}
|
|
25
|
-
myFunction = 123;
|
|
26
|
-
~~~~~~~~~~
|
|
27
|
-
Variables declared with function declarations should not be reassigned.
|
|
28
|
-
`,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
code: `
|
|
32
|
-
function myFunction() {}
|
|
33
|
-
myFunction += 1;
|
|
34
|
-
`,
|
|
35
|
-
snapshot: `
|
|
36
|
-
function myFunction() {}
|
|
37
|
-
myFunction += 1;
|
|
38
|
-
~~~~~~~~~~
|
|
39
|
-
Variables declared with function declarations should not be reassigned.
|
|
40
|
-
`,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
code: `
|
|
44
|
-
function myFunction() {}
|
|
45
|
-
myFunction++;
|
|
46
|
-
`,
|
|
47
|
-
snapshot: `
|
|
48
|
-
function myFunction() {}
|
|
49
|
-
myFunction++;
|
|
50
|
-
~~~~~~~~~~
|
|
51
|
-
Variables declared with function declarations should not be reassigned.
|
|
52
|
-
`,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
code: `
|
|
56
|
-
function myFunction() {}
|
|
57
|
-
++myFunction;
|
|
58
|
-
`,
|
|
59
|
-
snapshot: `
|
|
60
|
-
function myFunction() {}
|
|
61
|
-
++myFunction;
|
|
62
|
-
~~~~~~~~~~
|
|
63
|
-
Variables declared with function declarations should not be reassigned.
|
|
64
|
-
`,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
code: `
|
|
68
|
-
function myFunction() {
|
|
69
|
-
return 42;
|
|
70
|
-
}
|
|
71
|
-
myFunction = () => 100;
|
|
72
|
-
`,
|
|
73
|
-
snapshot: `
|
|
74
|
-
function myFunction() {
|
|
75
|
-
return 42;
|
|
76
|
-
}
|
|
77
|
-
myFunction = () => 100;
|
|
78
|
-
~~~~~~~~~~
|
|
79
|
-
Variables declared with function declarations should not be reassigned.
|
|
80
|
-
`,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
code: `
|
|
84
|
-
function outer() {
|
|
85
|
-
function inner() {}
|
|
86
|
-
inner = function() {};
|
|
87
|
-
}
|
|
88
|
-
`,
|
|
89
|
-
snapshot: `
|
|
90
|
-
function outer() {
|
|
91
|
-
function inner() {}
|
|
92
|
-
inner = function() {};
|
|
93
|
-
~~~~~
|
|
94
|
-
Variables declared with function declarations should not be reassigned.
|
|
95
|
-
}
|
|
96
|
-
`,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
code: `
|
|
100
|
-
function myFunction() {}
|
|
101
|
-
if (condition) {
|
|
102
|
-
myFunction = null;
|
|
103
|
-
}
|
|
104
|
-
`,
|
|
105
|
-
snapshot: `
|
|
106
|
-
function myFunction() {}
|
|
107
|
-
if (condition) {
|
|
108
|
-
myFunction = null;
|
|
109
|
-
~~~~~~~~~~
|
|
110
|
-
Variables declared with function declarations should not be reassigned.
|
|
111
|
-
}
|
|
112
|
-
`,
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
code: `
|
|
116
|
-
function getValue() {
|
|
117
|
-
return 1;
|
|
118
|
-
}
|
|
119
|
-
getValue ??= function() { return 0; };
|
|
120
|
-
`,
|
|
121
|
-
snapshot: `
|
|
122
|
-
function getValue() {
|
|
123
|
-
return 1;
|
|
124
|
-
}
|
|
125
|
-
getValue ??= function() { return 0; };
|
|
126
|
-
~~~~~~~~
|
|
127
|
-
Variables declared with function declarations should not be reassigned.
|
|
128
|
-
`,
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
code: `
|
|
132
|
-
function getValue() {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
getValue &&= false;
|
|
136
|
-
`,
|
|
137
|
-
snapshot: `
|
|
138
|
-
function getValue() {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
getValue &&= false;
|
|
142
|
-
~~~~~~~~
|
|
143
|
-
Variables declared with function declarations should not be reassigned.
|
|
144
|
-
`,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
code: `
|
|
148
|
-
function getValue() {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
getValue ||= () => true;
|
|
152
|
-
`,
|
|
153
|
-
snapshot: `
|
|
154
|
-
function getValue() {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
getValue ||= () => true;
|
|
158
|
-
~~~~~~~~
|
|
159
|
-
Variables declared with function declarations should not be reassigned.
|
|
160
|
-
`,
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
code: `
|
|
164
|
-
function calculate(value: number): number {
|
|
165
|
-
return value * 2;
|
|
166
|
-
}
|
|
167
|
-
calculate = (value: number) => value * 3;
|
|
168
|
-
`,
|
|
169
|
-
snapshot: `
|
|
170
|
-
function calculate(value: number): number {
|
|
171
|
-
return value * 2;
|
|
172
|
-
}
|
|
173
|
-
calculate = (value: number) => value * 3;
|
|
174
|
-
~~~~~~~~~
|
|
175
|
-
Variables declared with function declarations should not be reassigned.
|
|
176
|
-
`,
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
valid: [
|
|
180
|
-
`function myFunction() { return 42; }`,
|
|
181
|
-
`function myFunction() {} const result = myFunction();`,
|
|
182
|
-
`const myFunction = function() {}; myFunction = () => {};`,
|
|
183
|
-
`const myFunction = () => {}; myFunction = function() {};`,
|
|
184
|
-
`let myFunction = function() {}; myFunction = () => {};`,
|
|
185
|
-
`function outer() { const inner = function() {}; inner = () => {}; }`,
|
|
186
|
-
`
|
|
187
|
-
function outer() {
|
|
188
|
-
const myFunction = "shadowed variable";
|
|
189
|
-
myFunction = "reassigning shadowed variable is ok";
|
|
190
|
-
}
|
|
191
|
-
`,
|
|
192
|
-
`
|
|
193
|
-
let myFunction = "outer variable";
|
|
194
|
-
function scope() {
|
|
195
|
-
function myFunction() {}
|
|
196
|
-
console.log(myFunction);
|
|
197
|
-
}
|
|
198
|
-
myFunction = "reassigning outer is ok";
|
|
199
|
-
`,
|
|
200
|
-
`function myFunction() {} const copy = myFunction;`,
|
|
201
|
-
`function myFunction() {} if (condition) { callWith(myFunction); }`,
|
|
202
|
-
`
|
|
203
|
-
function myFunction() {
|
|
204
|
-
return function nested() {
|
|
205
|
-
return 42;
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
`,
|
|
209
|
-
],
|
|
210
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { typescriptLanguage } from "../language.js";
|
|
2
|
-
import { getModifyingReferences } from "../utils/getModifyingReferences.js";
|
|
3
|
-
|
|
4
|
-
export default typescriptLanguage.createRule({
|
|
5
|
-
about: {
|
|
6
|
-
description:
|
|
7
|
-
"Reports reassigning variables declared with function declarations.",
|
|
8
|
-
id: "functionAssignments",
|
|
9
|
-
preset: "untyped",
|
|
10
|
-
},
|
|
11
|
-
messages: {
|
|
12
|
-
noFunctionAssignment: {
|
|
13
|
-
primary:
|
|
14
|
-
"Variables declared with function declarations should not be reassigned.",
|
|
15
|
-
secondary: [
|
|
16
|
-
"Reassigning a function declaration can make code harder to understand and maintain.",
|
|
17
|
-
"Function declarations are hoisted to the top of their scope, and reassigning them can lead to unexpected behavior.",
|
|
18
|
-
],
|
|
19
|
-
suggestions: [
|
|
20
|
-
"Use a function expression or const variable instead if you need to reassign the function.",
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
setup(context) {
|
|
25
|
-
return {
|
|
26
|
-
visitors: {
|
|
27
|
-
FunctionDeclaration: (node) => {
|
|
28
|
-
if (!node.name) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const modifyingReferences = getModifyingReferences(
|
|
33
|
-
node.name,
|
|
34
|
-
context.sourceFile,
|
|
35
|
-
context.typeChecker,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
for (const reference of modifyingReferences) {
|
|
39
|
-
context.report({
|
|
40
|
-
message: "noFunctionAssignment",
|
|
41
|
-
range: {
|
|
42
|
-
begin: reference.getStart(context.sourceFile),
|
|
43
|
-
end: reference.getEnd(),
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import rule from "./functionNewCalls.js";
|
|
2
|
-
import { ruleTester } from "./ruleTester.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
const fn = new Function("a", "b", "return a + b");
|
|
9
|
-
`,
|
|
10
|
-
snapshot: `
|
|
11
|
-
const fn = new Function("a", "b", "return a + b");
|
|
12
|
-
~~~~~~~~
|
|
13
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
14
|
-
`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
code: `
|
|
18
|
-
const fn = Function("a", "return a");
|
|
19
|
-
`,
|
|
20
|
-
snapshot: `
|
|
21
|
-
const fn = Function("a", "return a");
|
|
22
|
-
~~~~~~~~
|
|
23
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
24
|
-
`,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
code: `
|
|
28
|
-
const fn = new Function("return 1");
|
|
29
|
-
`,
|
|
30
|
-
snapshot: `
|
|
31
|
-
const fn = new Function("return 1");
|
|
32
|
-
~~~~~~~~
|
|
33
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
34
|
-
`,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
code: `
|
|
38
|
-
const fn = Function();
|
|
39
|
-
`,
|
|
40
|
-
snapshot: `
|
|
41
|
-
const fn = Function();
|
|
42
|
-
~~~~~~~~
|
|
43
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
44
|
-
`,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
code: `
|
|
48
|
-
const fn = new globalThis.Function("return 1");
|
|
49
|
-
`,
|
|
50
|
-
snapshot: `
|
|
51
|
-
const fn = new globalThis.Function("return 1");
|
|
52
|
-
~~~~~~~~~~~~~~~~~~~
|
|
53
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
code: `
|
|
58
|
-
const fn = globalThis.Function("return 1");
|
|
59
|
-
`,
|
|
60
|
-
snapshot: `
|
|
61
|
-
const fn = globalThis.Function("return 1");
|
|
62
|
-
~~~~~~~~~~~~~~~~~~~
|
|
63
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
64
|
-
`,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
code: `
|
|
68
|
-
const fn = new window.Function("return 1");
|
|
69
|
-
`,
|
|
70
|
-
snapshot: `
|
|
71
|
-
const fn = new window.Function("return 1");
|
|
72
|
-
~~~~~~~~~~~~~~~
|
|
73
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
74
|
-
`,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
code: `
|
|
78
|
-
const fn = window.Function("return 1");
|
|
79
|
-
`,
|
|
80
|
-
snapshot: `
|
|
81
|
-
const fn = window.Function("return 1");
|
|
82
|
-
~~~~~~~~~~~~~~~
|
|
83
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
84
|
-
`,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
code: `
|
|
88
|
-
const result = new Function("a", "b", "return a + b")(1, 2);
|
|
89
|
-
`,
|
|
90
|
-
snapshot: `
|
|
91
|
-
const result = new Function("a", "b", "return a + b")(1, 2);
|
|
92
|
-
~~~~~~~~
|
|
93
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
94
|
-
`,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
code: `
|
|
98
|
-
const CustomFunction = Function;
|
|
99
|
-
const fn = new CustomFunction();
|
|
100
|
-
`,
|
|
101
|
-
snapshot: `
|
|
102
|
-
const CustomFunction = Function;
|
|
103
|
-
const fn = new CustomFunction();
|
|
104
|
-
~~~~~~~~~~~~~~
|
|
105
|
-
Dynamically creating functions with the Function constructor is insecure and slow.
|
|
106
|
-
`,
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
valid: [
|
|
110
|
-
`const fn = function(a, b) { return a + b; };`,
|
|
111
|
-
`const fn = (a, b) => a + b;`,
|
|
112
|
-
`function add(a, b) { return a + b; }`,
|
|
113
|
-
`class MyFunction {}`,
|
|
114
|
-
`const fn = new MyFunction();`,
|
|
115
|
-
],
|
|
116
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
4
|
-
import { typescriptLanguage } from "../language.js";
|
|
5
|
-
import { isGlobalDeclaration } from "../utils/isGlobalDeclaration.js";
|
|
6
|
-
import { isGlobalDeclarationOfName } from "../utils/isGlobalDeclarationOfName.js";
|
|
7
|
-
|
|
8
|
-
export default typescriptLanguage.createRule({
|
|
9
|
-
about: {
|
|
10
|
-
description:
|
|
11
|
-
"Reports using the Function constructor to create functions from strings.",
|
|
12
|
-
id: "functionNewCalls",
|
|
13
|
-
preset: "logical",
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
noFunctionConstructor: {
|
|
17
|
-
primary:
|
|
18
|
-
"Dynamically creating functions with the Function constructor is insecure and slow.",
|
|
19
|
-
secondary: [
|
|
20
|
-
"Using the `Function` constructor to create functions from strings is similar to `eval()` and introduces security risks and performance issues.",
|
|
21
|
-
"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.",
|
|
22
|
-
],
|
|
23
|
-
suggestions: [
|
|
24
|
-
"Define functions using function declarations (`function name() {}`) or arrow functions (`() => {}`) instead.",
|
|
25
|
-
"If dynamic code generation is truly necessary, consider safer alternatives like passing functions as parameters or using a more constrained domain-specific approach.",
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
setup(context) {
|
|
30
|
-
function checkNode(node: ts.CallExpression | ts.NewExpression) {
|
|
31
|
-
if (isFunctionConstructor(node)) {
|
|
32
|
-
context.report({
|
|
33
|
-
message: "noFunctionConstructor",
|
|
34
|
-
range: getTSNodeRange(node.expression, context.sourceFile),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isFunctionConstructor(node: ts.CallExpression | ts.NewExpression) {
|
|
40
|
-
if (ts.isIdentifier(node.expression)) {
|
|
41
|
-
if (
|
|
42
|
-
isGlobalDeclarationOfName(
|
|
43
|
-
node.expression,
|
|
44
|
-
"Function",
|
|
45
|
-
context.typeChecker,
|
|
46
|
-
)
|
|
47
|
-
) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
} else if (
|
|
51
|
-
ts.isPropertyAccessExpression(node.expression) &&
|
|
52
|
-
isGlobalDeclaration(node.expression, context.typeChecker)
|
|
53
|
-
) {
|
|
54
|
-
const propertyName = node.expression.name.text;
|
|
55
|
-
if (propertyName !== "Function") {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const object = node.expression.expression;
|
|
60
|
-
if (ts.isIdentifier(object)) {
|
|
61
|
-
return object.text === "globalThis" || object.text === "window";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
visitors: {
|
|
70
|
-
CallExpression: checkNode,
|
|
71
|
-
NewExpression: checkNode,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
});
|