@flint.fyi/ts 0.14.6 → 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} +22 -14
- 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 +1 -0
- package/lib/plugin.d.ts +79 -50
- package/lib/plugin.js +15 -0
- 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 +3 -2
- package/lib/rules/forDirections.test.d.ts +1 -0
- package/lib/rules/forDirections.test.js +1 -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 -91
- 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 -25
- 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 -125
- package/src/rules/forDirections.ts +0 -174
- 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
|
@@ -21,29 +21,30 @@ export default typescriptLanguage.createRule({
|
|
|
21
21
|
setup(context) {
|
|
22
22
|
return {
|
|
23
23
|
visitors: {
|
|
24
|
-
NewExpression: (node) => {
|
|
24
|
+
NewExpression: (node, { sourceFile, typeChecker }) => {
|
|
25
25
|
if (!ts.isIdentifier(node.expression)) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
const name = node.expression.text;
|
|
29
29
|
if (!["BigInt", "Symbol"].includes(name) ||
|
|
30
|
-
!isGlobalDeclaration(node.expression,
|
|
30
|
+
!isGlobalDeclaration(node.expression, typeChecker)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
context.report({
|
|
34
34
|
data: { name },
|
|
35
35
|
fix: {
|
|
36
36
|
range: {
|
|
37
|
-
begin: node.getStart(
|
|
38
|
-
end: node.expression.getStart(
|
|
37
|
+
begin: node.getStart(sourceFile),
|
|
38
|
+
end: node.expression.getStart(sourceFile),
|
|
39
39
|
},
|
|
40
40
|
text: "",
|
|
41
41
|
},
|
|
42
42
|
message: "noNewNonConstructor",
|
|
43
|
-
range: getTSNodeRange(node.getChildAt(0,
|
|
43
|
+
range: getTSNodeRange(node.getChildAt(0, sourceFile), sourceFile),
|
|
44
44
|
});
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
|
+
//# sourceMappingURL=newNativeNonConstructors.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { TypeScriptFileServices } from "../language.js";
|
|
1
2
|
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
3
|
readonly description: "Reports non-octal decimal escape sequences (\\8 and \\9) in string literals.";
|
|
3
4
|
readonly id: "nonOctalDecimalEscapes";
|
|
4
5
|
readonly preset: "logical";
|
|
5
|
-
}, import("../nodes.js").TSNodesByName,
|
|
6
|
+
}, import("../nodes.js").TSNodesByName, TypeScriptFileServices, "unexpectedEscape", undefined>;
|
|
6
7
|
export default _default;
|
|
8
|
+
//# sourceMappingURL=nonOctalDecimalEscapes.d.ts.map
|
|
@@ -21,8 +21,8 @@ export default typescriptLanguage.createRule({
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
setup(context) {
|
|
24
|
-
function checkNode(node) {
|
|
25
|
-
const text = node.getText(
|
|
24
|
+
function checkNode(node, { sourceFile }) {
|
|
25
|
+
const text = node.getText(sourceFile);
|
|
26
26
|
const matches = [...text.matchAll(nonOctalDecimalEscapePattern)];
|
|
27
27
|
for (const match of matches) {
|
|
28
28
|
// Ignore escapes where the backslash itself is escaped (e.g. "\\\\8" -> literal "\\8").
|
|
@@ -37,7 +37,7 @@ export default typescriptLanguage.createRule({
|
|
|
37
37
|
if (backslashesBefore % 2 === 1) {
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
|
-
const start = node.getStart(
|
|
40
|
+
const start = node.getStart(sourceFile) + matchIndex;
|
|
41
41
|
context.report({
|
|
42
42
|
message: "unexpectedEscape",
|
|
43
43
|
range: {
|
|
@@ -55,3 +55,4 @@ export default typescriptLanguage.createRule({
|
|
|
55
55
|
};
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
|
+
//# sourceMappingURL=nonOctalDecimalEscapes.js.map
|
|
@@ -2,5 +2,6 @@ declare const _default: import("@flint.fyi/core").Rule<{
|
|
|
2
2
|
readonly description: "Reports parseInt calls with binary, hexadecimal, or octal strings that can be replaced with numeric literals.";
|
|
3
3
|
readonly id: "numericLiteralParsing";
|
|
4
4
|
readonly preset: "stylistic";
|
|
5
|
-
}, import("../nodes.js").TSNodesByName, import("../language.js").
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptFileServices, "preferLiteral", undefined>;
|
|
6
6
|
export default _default;
|
|
7
|
+
//# sourceMappingURL=numericLiteralParsing.d.ts.map
|
|
@@ -51,7 +51,7 @@ export default typescriptLanguage.createRule({
|
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
53
|
setup(context) {
|
|
54
|
-
function checkParseIntCall(node) {
|
|
54
|
+
function checkParseIntCall(node, sourceFile) {
|
|
55
55
|
if (node.arguments.length !== 2) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -69,16 +69,16 @@ export default typescriptLanguage.createRule({
|
|
|
69
69
|
radix: String(radixValue),
|
|
70
70
|
},
|
|
71
71
|
message: "preferLiteral",
|
|
72
|
-
range: getTSNodeRange(node,
|
|
72
|
+
range: getTSNodeRange(node, sourceFile),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
return {
|
|
76
76
|
visitors: {
|
|
77
|
-
CallExpression: (node) => {
|
|
77
|
+
CallExpression: (node, { sourceFile, typeChecker }) => {
|
|
78
78
|
if (ts.isIdentifier(node.expression)) {
|
|
79
79
|
if (node.expression.text === "parseInt" &&
|
|
80
|
-
isGlobalDeclaration(node.expression,
|
|
81
|
-
checkParseIntCall(node);
|
|
80
|
+
isGlobalDeclaration(node.expression, typeChecker)) {
|
|
81
|
+
checkParseIntCall(node, sourceFile);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
@@ -86,8 +86,8 @@ export default typescriptLanguage.createRule({
|
|
|
86
86
|
node.expression.expression.text === "Number" &&
|
|
87
87
|
ts.isIdentifier(node.expression.name) &&
|
|
88
88
|
node.expression.name.text === "parseInt" &&
|
|
89
|
-
isGlobalDeclaration(node.expression.expression,
|
|
90
|
-
checkParseIntCall(node);
|
|
89
|
+
isGlobalDeclaration(node.expression.expression, typeChecker)) {
|
|
90
|
+
checkParseIntCall(node, sourceFile);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
},
|
|
@@ -95,3 +95,4 @@ export default typescriptLanguage.createRule({
|
|
|
95
95
|
};
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
|
+
//# sourceMappingURL=numericLiteralParsing.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Prefer `{}` object literal notation or `Object.create` instead of calling or constructing `Object`.";
|
|
3
|
+
readonly id: "objectCalls";
|
|
4
|
+
readonly preset: "stylistic";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptFileServices, "preferObjectLiteral", undefined>;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=objectCalls.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
3
|
+
import { typescriptLanguage } from "../language.js";
|
|
4
|
+
import { isGlobalDeclarationOfName } from "../utils/isGlobalDeclarationOfName.js";
|
|
5
|
+
export default typescriptLanguage.createRule({
|
|
6
|
+
about: {
|
|
7
|
+
description: "Prefer `{}` object literal notation or `Object.create` instead of calling or constructing `Object`.",
|
|
8
|
+
id: "objectCalls",
|
|
9
|
+
preset: "stylistic",
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
preferObjectLiteral: {
|
|
13
|
+
primary: "Prefer directly using `{}` instead of calling or constructing `Object`.",
|
|
14
|
+
secondary: [
|
|
15
|
+
"Calling or constructing Object with `Object()` or `new Object()` is unnecessarily verbose and less idiomatic than using object literal syntax.",
|
|
16
|
+
"`{}` object literal notation is the preferred and more concise way to create plain objects.",
|
|
17
|
+
"For creating objects without a prototype, use `Object.create(null)`.",
|
|
18
|
+
],
|
|
19
|
+
suggestions: [
|
|
20
|
+
"Replace `Object()` or `new Object()` with `{}` to create an empty object.",
|
|
21
|
+
"Use `Object.create(null)` when you need an object without a prototype.",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
setup(context) {
|
|
26
|
+
function checkNode(node) {
|
|
27
|
+
if (!ts.isIdentifier(node.expression) ||
|
|
28
|
+
!isGlobalDeclarationOfName(node.expression, "Object", context.typeChecker)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const reportNode = node.kind === ts.SyntaxKind.NewExpression
|
|
32
|
+
? node.getChildAt(0, context.sourceFile)
|
|
33
|
+
: node.expression;
|
|
34
|
+
context.report({
|
|
35
|
+
message: "preferObjectLiteral",
|
|
36
|
+
range: getTSNodeRange(reportNode, context.sourceFile),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
visitors: {
|
|
41
|
+
CallExpression: checkNode,
|
|
42
|
+
NewExpression: checkNode,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=objectCalls.js.map
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import rule from "./objectCalls.js";
|
|
2
|
+
import { ruleTester } from "./ruleTester.js";
|
|
3
|
+
ruleTester.describe(rule, {
|
|
4
|
+
invalid: [
|
|
5
|
+
{
|
|
6
|
+
code: `
|
|
7
|
+
const value = new Object();
|
|
8
|
+
`,
|
|
9
|
+
snapshot: `
|
|
10
|
+
const value = new Object();
|
|
11
|
+
~~~
|
|
12
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
13
|
+
`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: `
|
|
17
|
+
const empty = new Object();
|
|
18
|
+
const filled = new Object({ key: "value" });
|
|
19
|
+
`,
|
|
20
|
+
snapshot: `
|
|
21
|
+
const empty = new Object();
|
|
22
|
+
~~~
|
|
23
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
24
|
+
const filled = new Object({ key: "value" });
|
|
25
|
+
~~~
|
|
26
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: `
|
|
31
|
+
function createObject() {
|
|
32
|
+
return new Object();
|
|
33
|
+
}
|
|
34
|
+
`,
|
|
35
|
+
snapshot: `
|
|
36
|
+
function createObject() {
|
|
37
|
+
return new Object();
|
|
38
|
+
~~~
|
|
39
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
40
|
+
}
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
code: `
|
|
45
|
+
const config = condition ? new Object() : { default: true };
|
|
46
|
+
`,
|
|
47
|
+
snapshot: `
|
|
48
|
+
const config = condition ? new Object() : { default: true };
|
|
49
|
+
~~~
|
|
50
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: `
|
|
55
|
+
const array = [new Object(), new Object()];
|
|
56
|
+
`,
|
|
57
|
+
snapshot: `
|
|
58
|
+
const array = [new Object(), new Object()];
|
|
59
|
+
~~~
|
|
60
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
61
|
+
~~~
|
|
62
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
63
|
+
`,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: `
|
|
67
|
+
const nested = { inner: new Object() };
|
|
68
|
+
`,
|
|
69
|
+
snapshot: `
|
|
70
|
+
const nested = { inner: new Object() };
|
|
71
|
+
~~~
|
|
72
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
73
|
+
`,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
code: `
|
|
77
|
+
processData(new Object());
|
|
78
|
+
`,
|
|
79
|
+
snapshot: `
|
|
80
|
+
processData(new Object());
|
|
81
|
+
~~~
|
|
82
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
83
|
+
`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
code: `
|
|
87
|
+
const value = Object();
|
|
88
|
+
`,
|
|
89
|
+
snapshot: `
|
|
90
|
+
const value = Object();
|
|
91
|
+
~~~~~~
|
|
92
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
93
|
+
`,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
code: `
|
|
97
|
+
const filled = Object({ key: "value" });
|
|
98
|
+
`,
|
|
99
|
+
snapshot: `
|
|
100
|
+
const filled = Object({ key: "value" });
|
|
101
|
+
~~~~~~
|
|
102
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
103
|
+
`,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
code: `
|
|
107
|
+
function createObject() {
|
|
108
|
+
return Object();
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
snapshot: `
|
|
112
|
+
function createObject() {
|
|
113
|
+
return Object();
|
|
114
|
+
~~~~~~
|
|
115
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
116
|
+
}
|
|
117
|
+
`,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
code: `
|
|
121
|
+
const config = condition ? Object() : { default: true };
|
|
122
|
+
`,
|
|
123
|
+
snapshot: `
|
|
124
|
+
const config = condition ? Object() : { default: true };
|
|
125
|
+
~~~~~~
|
|
126
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
127
|
+
`,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
code: `
|
|
131
|
+
const array = [Object(), Object()];
|
|
132
|
+
`,
|
|
133
|
+
snapshot: `
|
|
134
|
+
const array = [Object(), Object()];
|
|
135
|
+
~~~~~~
|
|
136
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
137
|
+
~~~~~~
|
|
138
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
139
|
+
`,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
code: `
|
|
143
|
+
processData(Object());
|
|
144
|
+
`,
|
|
145
|
+
snapshot: `
|
|
146
|
+
processData(Object());
|
|
147
|
+
~~~~~~
|
|
148
|
+
Prefer directly using \`{}\` instead of calling or constructing \`Object\`.
|
|
149
|
+
`,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
valid: [
|
|
153
|
+
`const value = {};`,
|
|
154
|
+
`const filled = { key: "value" };`,
|
|
155
|
+
`const proto = Object.create(null);`,
|
|
156
|
+
`const inherited = Object.create(prototype);`,
|
|
157
|
+
`const assigned = Object.assign({}, source);`,
|
|
158
|
+
`const entries = Object.entries(data);`,
|
|
159
|
+
`const keys = Object.keys(data);`,
|
|
160
|
+
`const values = Object.values(data);`,
|
|
161
|
+
`function createEmpty() { return {}; }`,
|
|
162
|
+
`const array = [{}, { key: "value" }];`,
|
|
163
|
+
`const nested = { inner: {} };`,
|
|
164
|
+
`processData({});`,
|
|
165
|
+
`
|
|
166
|
+
class Object {}
|
|
167
|
+
new Object();
|
|
168
|
+
export {}
|
|
169
|
+
`,
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
//# sourceMappingURL=objectCalls.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() for checking own properties.";
|
|
3
|
+
readonly id: "objectHasOwns";
|
|
4
|
+
readonly preset: "stylistic";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptFileServices, "preferHasOwn", undefined>;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=objectHasOwns.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { getTSNodeRange } from "../getTSNodeRange.js";
|
|
3
|
+
import { typescriptLanguage } from "../language.js";
|
|
4
|
+
import { isGlobalDeclarationOfName } from "../utils/isGlobalDeclarationOfName.js";
|
|
5
|
+
export default typescriptLanguage.createRule({
|
|
6
|
+
about: {
|
|
7
|
+
description: "Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() for checking own properties.",
|
|
8
|
+
id: "objectHasOwns",
|
|
9
|
+
preset: "stylistic",
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
preferHasOwn: {
|
|
13
|
+
primary: "`hasOwnProperty()` calls can fail on objects without `Object.prototype` or with overridden properties.",
|
|
14
|
+
secondary: [
|
|
15
|
+
"`Object.hasOwn()` is a more modern and safer way to check if an object has its own property.",
|
|
16
|
+
"It avoids issues with objects that don't inherit from `Object.prototype` or have a modified hasOwnProperty property.",
|
|
17
|
+
"`Object.hasOwn()` was introduced in ES2022 and is more concise than the hasOwnProperty alternatives.",
|
|
18
|
+
],
|
|
19
|
+
suggestions: [
|
|
20
|
+
"Use the safer, more modern `Object.hasOwn(obj, key)`.",
|
|
21
|
+
"Use an alternative key check such as the `in` operator.",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
setup(context) {
|
|
26
|
+
function isObjectPrototypeHasOwnProperty(node, typeChecker) {
|
|
27
|
+
return (ts.isPropertyAccessExpression(node) &&
|
|
28
|
+
ts.isIdentifier(node.name) &&
|
|
29
|
+
node.name.text === "prototype" &&
|
|
30
|
+
ts.isIdentifier(node.expression) &&
|
|
31
|
+
isGlobalDeclarationOfName(node.expression, "Object", typeChecker));
|
|
32
|
+
}
|
|
33
|
+
function isObjectLiteralHasOwnProperty(node) {
|
|
34
|
+
return ts.isObjectLiteralExpression(node) && node.properties.length === 0;
|
|
35
|
+
}
|
|
36
|
+
function isHasOwnProperty(node, typeChecker) {
|
|
37
|
+
if (!ts.isPropertyAccessExpression(node) ||
|
|
38
|
+
!ts.isIdentifier(node.name) ||
|
|
39
|
+
node.name.text !== "hasOwnProperty") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return (isObjectPrototypeHasOwnProperty(node.expression, typeChecker) ||
|
|
43
|
+
isObjectLiteralHasOwnProperty(node.expression));
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
visitors: {
|
|
47
|
+
CallExpression: (node, { sourceFile, typeChecker }) => {
|
|
48
|
+
if (!ts.isPropertyAccessExpression(node.expression) ||
|
|
49
|
+
!ts.isIdentifier(node.expression.name)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (node.expression.name.text === "call" &&
|
|
53
|
+
node.arguments.length >= 2 &&
|
|
54
|
+
isHasOwnProperty(node.expression.expression, typeChecker)) {
|
|
55
|
+
context.report({
|
|
56
|
+
message: "preferHasOwn",
|
|
57
|
+
range: getTSNodeRange(node, sourceFile),
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (node.expression.name.text === "hasOwnProperty" &&
|
|
62
|
+
node.arguments.length >= 1 &&
|
|
63
|
+
!isHasOwnProperty(node.expression, typeChecker)) {
|
|
64
|
+
context.report({
|
|
65
|
+
message: "preferHasOwn",
|
|
66
|
+
range: getTSNodeRange(node, sourceFile),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=objectHasOwns.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import rule from "./objectHasOwns.js";
|
|
2
|
+
import { ruleTester } from "./ruleTester.js";
|
|
3
|
+
ruleTester.describe(rule, {
|
|
4
|
+
invalid: [
|
|
5
|
+
{
|
|
6
|
+
code: `
|
|
7
|
+
const hasKey = obj.hasOwnProperty("key");
|
|
8
|
+
`,
|
|
9
|
+
snapshot: `
|
|
10
|
+
const hasKey = obj.hasOwnProperty("key");
|
|
11
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
12
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
13
|
+
`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: `
|
|
17
|
+
if (obj.hasOwnProperty("prop")) {
|
|
18
|
+
console.log("Has property");
|
|
19
|
+
}
|
|
20
|
+
`,
|
|
21
|
+
snapshot: `
|
|
22
|
+
if (obj.hasOwnProperty("prop")) {
|
|
23
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
24
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
25
|
+
console.log("Has property");
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: `
|
|
31
|
+
const result = Object.prototype.hasOwnProperty.call(obj, "key");
|
|
32
|
+
`,
|
|
33
|
+
snapshot: `
|
|
34
|
+
const result = Object.prototype.hasOwnProperty.call(obj, "key");
|
|
35
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
36
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
37
|
+
`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
code: `
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(obj, "prop")) {
|
|
42
|
+
console.log("Has property");
|
|
43
|
+
}
|
|
44
|
+
`,
|
|
45
|
+
snapshot: `
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(obj, "prop")) {
|
|
47
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
48
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
49
|
+
console.log("Has property");
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: `
|
|
55
|
+
const hasKey = {}.hasOwnProperty.call(obj, "key");
|
|
56
|
+
`,
|
|
57
|
+
snapshot: `
|
|
58
|
+
const hasKey = {}.hasOwnProperty.call(obj, "key");
|
|
59
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
60
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
61
|
+
`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
code: `
|
|
65
|
+
if ({}.hasOwnProperty.call(obj, "prop")) {
|
|
66
|
+
console.log("Has property");
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
snapshot: `
|
|
70
|
+
if ({}.hasOwnProperty.call(obj, "prop")) {
|
|
71
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
72
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
73
|
+
console.log("Has property");
|
|
74
|
+
}
|
|
75
|
+
`,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
code: `
|
|
79
|
+
const value = someObj.hasOwnProperty(key);
|
|
80
|
+
`,
|
|
81
|
+
snapshot: `
|
|
82
|
+
const value = someObj.hasOwnProperty(key);
|
|
83
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
84
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
85
|
+
`,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
code: `
|
|
89
|
+
function check(obj: object, key: string) {
|
|
90
|
+
return obj.hasOwnProperty(key);
|
|
91
|
+
}
|
|
92
|
+
`,
|
|
93
|
+
snapshot: `
|
|
94
|
+
function check(obj: object, key: string) {
|
|
95
|
+
return obj.hasOwnProperty(key);
|
|
96
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
|
97
|
+
\`hasOwnProperty()\` calls can fail on objects without \`Object.prototype\` or with overridden properties.
|
|
98
|
+
}
|
|
99
|
+
`,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
valid: [
|
|
103
|
+
`const hasKey = Object.hasOwn(obj, "key");`,
|
|
104
|
+
`if (Object.hasOwn(obj, "prop")) { console.log("Has property"); }`,
|
|
105
|
+
`const result = Object.hasOwn(obj, key);`,
|
|
106
|
+
`function check(obj: object, key: string) { return Object.hasOwn(obj, key); }`,
|
|
107
|
+
`const descriptor = Object.getOwnPropertyDescriptor(obj, "key");`,
|
|
108
|
+
`const keys = Object.getOwnPropertyNames(obj);`,
|
|
109
|
+
`const symbols = Object.getOwnPropertySymbols(obj);`,
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=objectHasOwns.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
+
readonly description: "Reports unnecessary duplicate keys that override previous values.";
|
|
3
|
+
readonly id: "objectKeyDuplicates";
|
|
4
|
+
readonly preset: "untyped";
|
|
5
|
+
}, import("../nodes.js").TSNodesByName, import("../language.js").TypeScriptFileServices, "duplicateKey", undefined>;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=objectKeyDuplicates.d.ts.map
|