@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,86 +0,0 @@
|
|
|
1
|
-
import { ruleTester } from "./ruleTester.js";
|
|
2
|
-
import rule from "./typeofComparisons.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
if (typeof value === "") {
|
|
9
|
-
process();
|
|
10
|
-
}
|
|
11
|
-
`,
|
|
12
|
-
snapshot: `
|
|
13
|
-
if (typeof value === "") {
|
|
14
|
-
~~
|
|
15
|
-
This string literal is not one that the typeof operator will ever produce.
|
|
16
|
-
process();
|
|
17
|
-
}
|
|
18
|
-
`,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
code: `
|
|
22
|
-
if (typeof data != "invalid") {
|
|
23
|
-
reject();
|
|
24
|
-
}
|
|
25
|
-
`,
|
|
26
|
-
snapshot: `
|
|
27
|
-
if (typeof data != "invalid") {
|
|
28
|
-
~~~~~~~~~
|
|
29
|
-
This string literal is not one that the typeof operator will ever produce.
|
|
30
|
-
reject();
|
|
31
|
-
}
|
|
32
|
-
`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
code: `
|
|
36
|
-
if ("invalid" === typeof flag) {
|
|
37
|
-
toggle();
|
|
38
|
-
}
|
|
39
|
-
`,
|
|
40
|
-
snapshot: `
|
|
41
|
-
if ("invalid" === typeof flag) {
|
|
42
|
-
~~~~~~~~~
|
|
43
|
-
This string literal is not one that the typeof operator will ever produce.
|
|
44
|
-
toggle();
|
|
45
|
-
}
|
|
46
|
-
`,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
code: `
|
|
50
|
-
if (typeof value === "String") {
|
|
51
|
-
process();
|
|
52
|
-
}
|
|
53
|
-
`,
|
|
54
|
-
snapshot: `
|
|
55
|
-
if (typeof value === "String") {
|
|
56
|
-
~~~~~~~~
|
|
57
|
-
This string literal is not one that the typeof operator will ever produce.
|
|
58
|
-
process();
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
code: `
|
|
64
|
-
const isValid = typeof input !== "array";
|
|
65
|
-
`,
|
|
66
|
-
snapshot: `
|
|
67
|
-
const isValid = typeof input !== "array";
|
|
68
|
-
~~~~~~~
|
|
69
|
-
This string literal is not one that the typeof operator will ever produce.
|
|
70
|
-
`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
valid: [
|
|
74
|
-
`if (typeof value === "string") { process(); }`,
|
|
75
|
-
`if (typeof variable == "undefined") { handle(); }`,
|
|
76
|
-
`if (typeof data != "number") { reject(); }`,
|
|
77
|
-
`if (typeof callback !== "function") { throw new Error("Invalid callback"); }`,
|
|
78
|
-
`if (typeof flag === "boolean") { toggle(); }`,
|
|
79
|
-
`if (typeof value === "object") { parse(); }`,
|
|
80
|
-
`if (typeof value === "symbol") { handle(); }`,
|
|
81
|
-
`if (typeof value === "bigint") { compute(); }`,
|
|
82
|
-
`if (typeof value === other) { process(); }`,
|
|
83
|
-
`if (typeof value === typeof other) { compare(); }`,
|
|
84
|
-
`const type = typeof value;`,
|
|
85
|
-
],
|
|
86
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
4
|
-
import { typescriptLanguage } from "../language.js";
|
|
5
|
-
|
|
6
|
-
const validTypeofValues = new Set([
|
|
7
|
-
"bigint",
|
|
8
|
-
"boolean",
|
|
9
|
-
"function",
|
|
10
|
-
"number",
|
|
11
|
-
"object",
|
|
12
|
-
"string",
|
|
13
|
-
"symbol",
|
|
14
|
-
"undefined",
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
// TODO: Reuse a shared getStaticValue-style utility?
|
|
18
|
-
function getStringValue(node: ts.Expression) {
|
|
19
|
-
return ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)
|
|
20
|
-
? node.text
|
|
21
|
-
: undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getTypeofOperand(node: ts.Expression) {
|
|
25
|
-
return ts.isTypeOfExpression(node) && node.expression;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default typescriptLanguage.createRule({
|
|
29
|
-
about: {
|
|
30
|
-
description:
|
|
31
|
-
"Reports typeof expressions that compare impossible string literals.",
|
|
32
|
-
id: "typeofComparisons",
|
|
33
|
-
preset: "untyped",
|
|
34
|
-
},
|
|
35
|
-
messages: {
|
|
36
|
-
invalidValue: {
|
|
37
|
-
primary:
|
|
38
|
-
"This string literal is not one that the typeof operator will ever produce.",
|
|
39
|
-
secondary: [
|
|
40
|
-
"The typeof operator returns one of a specific set of string values.",
|
|
41
|
-
"Comparing typeof to an invalid string is usually a typo and will never match.",
|
|
42
|
-
'The only valid values are: "bigint", "boolean", "function", "number", "object", "string", "symbol", and "undefined".',
|
|
43
|
-
],
|
|
44
|
-
suggestions: [
|
|
45
|
-
"Check for typos and use one of the valid typeof return values.",
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
setup(context) {
|
|
50
|
-
function checkComparison(node: ts.BinaryExpression) {
|
|
51
|
-
const leftTypeofOperand = getTypeofOperand(node.left);
|
|
52
|
-
const rightTypeofOperand = getTypeofOperand(node.right);
|
|
53
|
-
|
|
54
|
-
let comparisonValue: ts.Expression | undefined;
|
|
55
|
-
if (leftTypeofOperand) {
|
|
56
|
-
comparisonValue = node.right;
|
|
57
|
-
} else if (rightTypeofOperand) {
|
|
58
|
-
comparisonValue = node.left;
|
|
59
|
-
} else {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const stringValue = getStringValue(comparisonValue);
|
|
64
|
-
if (stringValue != null && !validTypeofValues.has(stringValue)) {
|
|
65
|
-
context.report({
|
|
66
|
-
message: "invalidValue",
|
|
67
|
-
range: getTSNodeRange(comparisonValue, context.sourceFile),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
visitors: {
|
|
74
|
-
BinaryExpression: (node) => {
|
|
75
|
-
if (
|
|
76
|
-
node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken ||
|
|
77
|
-
node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
78
|
-
node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken ||
|
|
79
|
-
node.operatorToken.kind ===
|
|
80
|
-
ts.SyntaxKind.ExclamationEqualsEqualsToken
|
|
81
|
-
) {
|
|
82
|
-
checkComparison(node);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ruleTester } from "./ruleTester.js";
|
|
2
|
-
import rule from "./unassignedVariables.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
let value;
|
|
9
|
-
`,
|
|
10
|
-
snapshot: `
|
|
11
|
-
let value;
|
|
12
|
-
~~~~~
|
|
13
|
-
Variable 'value' is declared but never assigned a value.
|
|
14
|
-
`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
code: `
|
|
18
|
-
var variable;
|
|
19
|
-
console.log(variable);
|
|
20
|
-
`,
|
|
21
|
-
snapshot: `
|
|
22
|
-
var variable;
|
|
23
|
-
~~~~~~~~
|
|
24
|
-
Variable 'variable' is declared but never assigned a value.
|
|
25
|
-
console.log(variable);
|
|
26
|
-
`,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
code: `
|
|
30
|
-
let unassigned: number;
|
|
31
|
-
console.log(unassigned);
|
|
32
|
-
`,
|
|
33
|
-
snapshot: `
|
|
34
|
-
let unassigned: number;
|
|
35
|
-
~~~~~~~~~~
|
|
36
|
-
Variable 'unassigned' is declared but never assigned a value.
|
|
37
|
-
console.log(unassigned);
|
|
38
|
-
`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
code: `
|
|
42
|
-
function example() {
|
|
43
|
-
let local;
|
|
44
|
-
return local;
|
|
45
|
-
}
|
|
46
|
-
`,
|
|
47
|
-
snapshot: `
|
|
48
|
-
function example() {
|
|
49
|
-
let local;
|
|
50
|
-
~~~~~
|
|
51
|
-
Variable 'local' is declared but never assigned a value.
|
|
52
|
-
return local;
|
|
53
|
-
}
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
valid: [
|
|
58
|
-
`let assigned = 5;`,
|
|
59
|
-
`const constant = 10;`,
|
|
60
|
-
`var variable = "hello";`,
|
|
61
|
-
`let value: number = 42;`,
|
|
62
|
-
`let x; x = 5;`,
|
|
63
|
-
`let y; y = 10; console.log(y);`,
|
|
64
|
-
`var z; z += 1;`,
|
|
65
|
-
`let counter; counter++;`,
|
|
66
|
-
`let value; value--;`,
|
|
67
|
-
`for (let index = 0; index < 10; index++) {}`,
|
|
68
|
-
`for (let item; item < 10; item++) {}`,
|
|
69
|
-
`let result; result ||= "default";`,
|
|
70
|
-
`let data; data &&= "value";`,
|
|
71
|
-
`let nullish; nullish ??= "fallback";`,
|
|
72
|
-
],
|
|
73
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { typescriptLanguage } from "../language.js";
|
|
4
|
-
import { getModifyingReferences } from "../utils/getModifyingReferences.js";
|
|
5
|
-
|
|
6
|
-
export default typescriptLanguage.createRule({
|
|
7
|
-
about: {
|
|
8
|
-
description:
|
|
9
|
-
"Reports variables that are declared but never assigned a value.",
|
|
10
|
-
id: "unassignedVariables",
|
|
11
|
-
preset: "untyped",
|
|
12
|
-
},
|
|
13
|
-
messages: {
|
|
14
|
-
noUnassigned: {
|
|
15
|
-
primary: "Variable '{{ name }}' is declared but never assigned a value.",
|
|
16
|
-
secondary: [
|
|
17
|
-
"Declaring a variable without ever assigning it a value means it will always be `undefined`.",
|
|
18
|
-
"This is often a mistake, such as forgetting to initialize the variable or assign to it later.",
|
|
19
|
-
],
|
|
20
|
-
suggestions: [
|
|
21
|
-
"Assign a value to the variable, either at declaration or before it is used.",
|
|
22
|
-
"If the variable is meant to be `undefined`, consider making that explicit for clarity.",
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
setup(context) {
|
|
27
|
-
function hasAssignments(
|
|
28
|
-
identifier: ts.Identifier,
|
|
29
|
-
sourceFile: ts.SourceFile,
|
|
30
|
-
typeChecker: ts.TypeChecker,
|
|
31
|
-
): boolean {
|
|
32
|
-
// TODO (#400): Switch to scope analysis
|
|
33
|
-
return !!getModifyingReferences(identifier, sourceFile, typeChecker)
|
|
34
|
-
.length;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
visitors: {
|
|
39
|
-
VariableDeclaration: (node) => {
|
|
40
|
-
if (node.initializer || !ts.isIdentifier(node.name)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
ts.isVariableDeclarationList(node.parent) &&
|
|
46
|
-
!!(node.parent.flags & ts.NodeFlags.Const)
|
|
47
|
-
) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
!hasAssignments(node.name, context.sourceFile, context.typeChecker)
|
|
53
|
-
) {
|
|
54
|
-
context.report({
|
|
55
|
-
data: {
|
|
56
|
-
name: node.name.text,
|
|
57
|
-
},
|
|
58
|
-
message: "noUnassigned",
|
|
59
|
-
range: {
|
|
60
|
-
begin: node.name.getStart(context.sourceFile),
|
|
61
|
-
end: node.name.getEnd(),
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { ruleTester } from "./ruleTester.js";
|
|
2
|
-
import rule from "./undefinedVariables.js";
|
|
3
|
-
|
|
4
|
-
ruleTester.describe(rule, {
|
|
5
|
-
invalid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
console.log(undefinedVar);
|
|
9
|
-
`,
|
|
10
|
-
snapshot: `
|
|
11
|
-
console.log(undefinedVar);
|
|
12
|
-
~~~~~~~~~~~~
|
|
13
|
-
Variable 'undefinedVar' is used but was never defined.
|
|
14
|
-
`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
code: `
|
|
18
|
-
function test() {
|
|
19
|
-
return notDefined;
|
|
20
|
-
}
|
|
21
|
-
`,
|
|
22
|
-
snapshot: `
|
|
23
|
-
function test() {
|
|
24
|
-
return notDefined;
|
|
25
|
-
~~~~~~~~~~
|
|
26
|
-
Variable 'notDefined' is used but was never defined.
|
|
27
|
-
}
|
|
28
|
-
`,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
code: `
|
|
32
|
-
const value = unknownVariable;
|
|
33
|
-
`,
|
|
34
|
-
snapshot: `
|
|
35
|
-
const value = unknownVariable;
|
|
36
|
-
~~~~~~~~~~~~~~~
|
|
37
|
-
Variable 'unknownVariable' is used but was never defined.
|
|
38
|
-
`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
code: `
|
|
42
|
-
if (condition) {
|
|
43
|
-
doSomething();
|
|
44
|
-
}
|
|
45
|
-
`,
|
|
46
|
-
snapshot: `
|
|
47
|
-
if (condition) {
|
|
48
|
-
~~~~~~~~~
|
|
49
|
-
Variable 'condition' is used but was never defined.
|
|
50
|
-
doSomething();
|
|
51
|
-
~~~~~~~~~~~
|
|
52
|
-
Variable 'doSomething' is used but was never defined.
|
|
53
|
-
}
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
code: `
|
|
58
|
-
const result = first + second;
|
|
59
|
-
`,
|
|
60
|
-
snapshot: `
|
|
61
|
-
const result = first + second;
|
|
62
|
-
~~~~~
|
|
63
|
-
Variable 'first' is used but was never defined.
|
|
64
|
-
~~~~~~
|
|
65
|
-
Variable 'second' is used but was never defined.
|
|
66
|
-
`,
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
valid: [
|
|
70
|
-
`const value = 5; console.log(value);`,
|
|
71
|
-
`function test(parameter: number) { return parameter; }`,
|
|
72
|
-
`let count = 0; count++;`,
|
|
73
|
-
`const obj = { prop: 1 }; console.log(obj.prop);`,
|
|
74
|
-
`typeof undefinedVar === "undefined"`,
|
|
75
|
-
`const obj = {}; const { prop } = obj;`,
|
|
76
|
-
`function fn() { return 1; } fn();`,
|
|
77
|
-
`class MyClass {} const instance = new MyClass();`,
|
|
78
|
-
`import { value } from "module"; console.log(value);`,
|
|
79
|
-
`const array = [1, 2, 3]; array.forEach(item => console.log(item));`,
|
|
80
|
-
],
|
|
81
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { typescriptLanguage } from "../language.js";
|
|
4
|
-
|
|
5
|
-
export default typescriptLanguage.createRule({
|
|
6
|
-
about: {
|
|
7
|
-
description: "Reports using variables that are not defined.",
|
|
8
|
-
id: "undefinedVariables",
|
|
9
|
-
preset: "untyped",
|
|
10
|
-
},
|
|
11
|
-
messages: {
|
|
12
|
-
undefinedVariable: {
|
|
13
|
-
primary: "Variable '{{ name }}' is used but was never defined.",
|
|
14
|
-
secondary: [
|
|
15
|
-
"Variables must be declared before they can be used.",
|
|
16
|
-
"Using undefined variables will cause a ReferenceError at runtime.",
|
|
17
|
-
],
|
|
18
|
-
suggestions: [
|
|
19
|
-
"Declare the variable before using it, or check if the variable name is spelled correctly.",
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
setup(context) {
|
|
24
|
-
return {
|
|
25
|
-
visitors: {
|
|
26
|
-
Identifier: (node) => {
|
|
27
|
-
if (
|
|
28
|
-
ts.isVariableDeclaration(node.parent) &&
|
|
29
|
-
node.parent.name === node
|
|
30
|
-
) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (ts.isParameter(node.parent) && node.parent.name === node) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
(ts.isFunctionDeclaration(node.parent) ||
|
|
40
|
-
ts.isClassDeclaration(node.parent) ||
|
|
41
|
-
ts.isInterfaceDeclaration(node.parent) ||
|
|
42
|
-
ts.isTypeAliasDeclaration(node.parent) ||
|
|
43
|
-
ts.isEnumDeclaration(node.parent) ||
|
|
44
|
-
ts.isModuleDeclaration(node.parent)) &&
|
|
45
|
-
node.parent.name === node
|
|
46
|
-
) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
ts.isImportSpecifier(node.parent) ||
|
|
52
|
-
ts.isImportClause(node.parent) ||
|
|
53
|
-
ts.isNamespaceImport(node.parent)
|
|
54
|
-
) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
ts.isPropertyAccessExpression(node.parent) &&
|
|
60
|
-
node.parent.name === node
|
|
61
|
-
) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
ts.isPropertyAssignment(node.parent) &&
|
|
67
|
-
node.parent.name === node
|
|
68
|
-
) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
ts.isTypeOfExpression(node.parent) &&
|
|
74
|
-
node.parent.expression === node
|
|
75
|
-
) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// TODO: This rule is untyped, so it should use scope analysis
|
|
80
|
-
// https://github.com/JoshuaKGoldberg/flint/issues/400
|
|
81
|
-
if (!context.typeChecker.getSymbolAtLocation(node)) {
|
|
82
|
-
context.report({
|
|
83
|
-
data: {
|
|
84
|
-
name: node.text,
|
|
85
|
-
},
|
|
86
|
-
message: "undefinedVariable",
|
|
87
|
-
range: {
|
|
88
|
-
begin: node.getStart(context.sourceFile),
|
|
89
|
-
end: node.getEnd(),
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// flint-disable-file invalidCodeLines -- This rule checks the first character of code files.
|
|
2
|
-
import { ruleTester } from "./ruleTester.js";
|
|
3
|
-
import rule from "./unicodeBOMs.js";
|
|
4
|
-
|
|
5
|
-
ruleTester.describe(rule, {
|
|
6
|
-
invalid: [
|
|
7
|
-
{
|
|
8
|
-
code: `\uFEFFconst value = 1;
|
|
9
|
-
`,
|
|
10
|
-
snapshot: `\uFEFFconst value = 1;
|
|
11
|
-
~
|
|
12
|
-
This Unicode Byte Order Mark (BOM) is unnecessary and can cause issues with some tools.
|
|
13
|
-
`,
|
|
14
|
-
suggestions: [
|
|
15
|
-
{
|
|
16
|
-
id: "removeBOM",
|
|
17
|
-
updated: `const value = 1;
|
|
18
|
-
`,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
code: `\uFEFF// Comment
|
|
24
|
-
const value = 1;
|
|
25
|
-
`,
|
|
26
|
-
snapshot: `\uFEFF// Comment
|
|
27
|
-
~
|
|
28
|
-
This Unicode Byte Order Mark (BOM) is unnecessary and can cause issues with some tools.
|
|
29
|
-
const value = 1;
|
|
30
|
-
`,
|
|
31
|
-
suggestions: [
|
|
32
|
-
{
|
|
33
|
-
id: "removeBOM",
|
|
34
|
-
updated: `// Comment
|
|
35
|
-
const value = 1;
|
|
36
|
-
`,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
code: `\uFEFF
|
|
42
|
-
const value = 1;
|
|
43
|
-
`,
|
|
44
|
-
snapshot: `\uFEFF
|
|
45
|
-
~
|
|
46
|
-
This Unicode Byte Order Mark (BOM) is unnecessary and can cause issues with some tools.
|
|
47
|
-
const value = 1;
|
|
48
|
-
`,
|
|
49
|
-
suggestions: [
|
|
50
|
-
{
|
|
51
|
-
id: "removeBOM",
|
|
52
|
-
updated: `
|
|
53
|
-
const value = 1;
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
valid: [
|
|
60
|
-
`const value = 1;`,
|
|
61
|
-
`// Comment at the start
|
|
62
|
-
const value = 1;`,
|
|
63
|
-
`
|
|
64
|
-
const value = 1;`,
|
|
65
|
-
`function test() { return 42; }`,
|
|
66
|
-
],
|
|
67
|
-
});
|
package/src/rules/unicodeBOMs.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { typescriptLanguage } from "../language.js";
|
|
2
|
-
|
|
3
|
-
export default typescriptLanguage.createRule({
|
|
4
|
-
about: {
|
|
5
|
-
description: "Reports files with Unicode Byte Order Marks (BOMs).",
|
|
6
|
-
id: "unicodeBOMs",
|
|
7
|
-
preset: "stylistic",
|
|
8
|
-
},
|
|
9
|
-
messages: {
|
|
10
|
-
noBOM: {
|
|
11
|
-
primary:
|
|
12
|
-
"This Unicode Byte Order Mark (BOM) is unnecessary and can cause issues with some tools.",
|
|
13
|
-
secondary: [
|
|
14
|
-
"The Unicode BOM is a special character (U+FEFF) that can appear at the start of a file to indicate its byte order and encoding.",
|
|
15
|
-
"While it can be useful in some contexts, it does not improve tooling portability and is not generally helpful for editors.",
|
|
16
|
-
],
|
|
17
|
-
suggestions: ["Remove the BOM from the beginning of the file."],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
setup(context) {
|
|
21
|
-
const text = context.sourceFile.getFullText();
|
|
22
|
-
if (text.charCodeAt(0) !== 0xfeff) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
context.report({
|
|
27
|
-
message: "noBOM",
|
|
28
|
-
range: {
|
|
29
|
-
begin: 0,
|
|
30
|
-
end: 1,
|
|
31
|
-
},
|
|
32
|
-
suggestions: [
|
|
33
|
-
{
|
|
34
|
-
id: "removeBOM",
|
|
35
|
-
range: {
|
|
36
|
-
begin: 0,
|
|
37
|
-
end: 1,
|
|
38
|
-
},
|
|
39
|
-
text: "",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
});
|