@flint.fyi/ts 0.20.0 → 0.22.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/plugin.d.ts → dist/index.d.mts} +360 -365
- package/dist/index.mjs +22467 -0
- package/package.json +10 -10
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/plugin.js +0 -621
- package/lib/rules/accessorPairGroups.d.ts +0 -10
- package/lib/rules/accessorPairGroups.js +0 -48
- package/lib/rules/accessorPairTypes.d.ts +0 -10
- package/lib/rules/accessorPairTypes.js +0 -72
- package/lib/rules/accessorThisRecursion.d.ts +0 -10
- package/lib/rules/accessorThisRecursion.js +0 -65
- package/lib/rules/anyArguments.d.ts +0 -10
- package/lib/rules/anyArguments.js +0 -234
- package/lib/rules/anyAssignments.d.ts +0 -10
- package/lib/rules/anyAssignments.js +0 -265
- package/lib/rules/anyCalls.d.ts +0 -10
- package/lib/rules/anyCalls.js +0 -68
- package/lib/rules/anyMemberAccess.d.ts +0 -10
- package/lib/rules/anyMemberAccess.js +0 -85
- package/lib/rules/anyReturns.d.ts +0 -10
- package/lib/rules/anyReturns.js +0 -102
- package/lib/rules/arguments.d.ts +0 -10
- package/lib/rules/arguments.js +0 -38
- package/lib/rules/arrayCallbackReturns.d.ts +0 -10
- package/lib/rules/arrayCallbackReturns.js +0 -73
- package/lib/rules/arrayConstructors.d.ts +0 -10
- package/lib/rules/arrayConstructors.js +0 -47
- package/lib/rules/arrayDeleteUnnecessaryCounts.d.ts +0 -10
- package/lib/rules/arrayDeleteUnnecessaryCounts.js +0 -54
- package/lib/rules/arrayElementDeletions.d.ts +0 -10
- package/lib/rules/arrayElementDeletions.js +0 -43
- package/lib/rules/arrayEmptyCallbackSlots.d.ts +0 -10
- package/lib/rules/arrayEmptyCallbackSlots.js +0 -45
- package/lib/rules/arrayExistenceChecksConsistency.d.ts +0 -10
- package/lib/rules/arrayExistenceChecksConsistency.js +0 -86
- package/lib/rules/arrayFilteredFinds.d.ts +0 -10
- package/lib/rules/arrayFilteredFinds.js +0 -80
- package/lib/rules/arrayFinds.d.ts +0 -10
- package/lib/rules/arrayFinds.js +0 -41
- package/lib/rules/arrayFlatMapMethods.d.ts +0 -10
- package/lib/rules/arrayFlatMapMethods.js +0 -47
- package/lib/rules/arrayFlatMethods.d.ts +0 -10
- package/lib/rules/arrayFlatMethods.js +0 -83
- package/lib/rules/arrayFlatUnnecessaryDepths.d.ts +0 -10
- package/lib/rules/arrayFlatUnnecessaryDepths.js +0 -33
- package/lib/rules/arrayIncludes.d.ts +0 -10
- package/lib/rules/arrayIncludes.js +0 -59
- package/lib/rules/arrayIncludesMethods.d.ts +0 -10
- package/lib/rules/arrayIncludesMethods.js +0 -37
- package/lib/rules/arrayIndexOfMethods.d.ts +0 -10
- package/lib/rules/arrayIndexOfMethods.js +0 -51
- package/lib/rules/arrayLoops.d.ts +0 -10
- package/lib/rules/arrayLoops.js +0 -36
- package/lib/rules/arrayMapIdentities.d.ts +0 -10
- package/lib/rules/arrayMapIdentities.js +0 -74
- package/lib/rules/arrayMutableReverses.d.ts +0 -10
- package/lib/rules/arrayMutableReverses.js +0 -39
- package/lib/rules/arrayMutableSorts.d.ts +0 -10
- package/lib/rules/arrayMutableSorts.js +0 -72
- package/lib/rules/arrayReduceTypeArguments.d.ts +0 -10
- package/lib/rules/arrayReduceTypeArguments.js +0 -64
- package/lib/rules/arraySliceUnnecessaryEnd.d.ts +0 -10
- package/lib/rules/arraySliceUnnecessaryEnd.js +0 -51
- package/lib/rules/arraySomeMethods.d.ts +0 -10
- package/lib/rules/arraySomeMethods.js +0 -77
- package/lib/rules/arrayTernarySpreadingConsistency.d.ts +0 -10
- package/lib/rules/arrayTernarySpreadingConsistency.js +0 -74
- package/lib/rules/arrayTypes.d.ts +0 -17
- package/lib/rules/arrayTypes.js +0 -111
- package/lib/rules/arrayUnnecessaryLengthChecks.d.ts +0 -10
- package/lib/rules/arrayUnnecessaryLengthChecks.js +0 -97
- package/lib/rules/asConstAssertions.d.ts +0 -10
- package/lib/rules/asConstAssertions.js +0 -57
- package/lib/rules/assignmentOperatorShorthands.d.ts +0 -10
- package/lib/rules/assignmentOperatorShorthands.js +0 -47
- package/lib/rules/asyncFunctionAwaits.d.ts +0 -10
- package/lib/rules/asyncFunctionAwaits.js +0 -55
- package/lib/rules/asyncPromiseExecutors.d.ts +0 -10
- package/lib/rules/asyncPromiseExecutors.js +0 -41
- package/lib/rules/asyncUnnecessaryPromiseWrappers.d.ts +0 -10
- package/lib/rules/asyncUnnecessaryPromiseWrappers.js +0 -52
- package/lib/rules/atAccesses.d.ts +0 -10
- package/lib/rules/atAccesses.js +0 -52
- package/lib/rules/builtinCoercions.d.ts +0 -10
- package/lib/rules/builtinCoercions.js +0 -117
- package/lib/rules/builtinConstructorNews.d.ts +0 -10
- package/lib/rules/builtinConstructorNews.js +0 -89
- package/lib/rules/caseDeclarations.d.ts +0 -10
- package/lib/rules/caseDeclarations.js +0 -40
- package/lib/rules/caseDuplicates.d.ts +0 -10
- package/lib/rules/caseDuplicates.js +0 -36
- package/lib/rules/caseFallthroughs.d.ts +0 -10
- package/lib/rules/caseFallthroughs.js +0 -76
- package/lib/rules/catchCallbackTypes.d.ts +0 -10
- package/lib/rules/catchCallbackTypes.js +0 -67
- package/lib/rules/caughtVariableNames.d.ts +0 -10
- package/lib/rules/caughtVariableNames.js +0 -40
- package/lib/rules/chainedAssignments.d.ts +0 -10
- package/lib/rules/chainedAssignments.js +0 -33
- package/lib/rules/charAtComparisons.d.ts +0 -10
- package/lib/rules/charAtComparisons.js +0 -58
- package/lib/rules/classAssignments.d.ts +0 -10
- package/lib/rules/classAssignments.js +0 -29
- package/lib/rules/classFieldDeclarations.d.ts +0 -10
- package/lib/rules/classFieldDeclarations.js +0 -40
- package/lib/rules/classLiteralProperties.d.ts +0 -10
- package/lib/rules/classLiteralProperties.js +0 -45
- package/lib/rules/classMemberDuplicates.d.ts +0 -10
- package/lib/rules/classMemberDuplicates.js +0 -71
- package/lib/rules/classMethodsThis.d.ts +0 -14
- package/lib/rules/classMethodsThis.js +0 -124
- package/lib/rules/combinedPushes.d.ts +0 -10
- package/lib/rules/combinedPushes.js +0 -56
- package/lib/rules/consecutiveNonNullAssertions.d.ts +0 -10
- package/lib/rules/consecutiveNonNullAssertions.js +0 -39
- package/lib/rules/consoleCalls.d.ts +0 -9
- package/lib/rules/consoleCalls.js +0 -28
- package/lib/rules/constantAssignments.d.ts +0 -10
- package/lib/rules/constantAssignments.js +0 -41
- package/lib/rules/constructorGenericCalls.d.ts +0 -16
- package/lib/rules/constructorGenericCalls.js +0 -138
- package/lib/rules/constructorReturns.d.ts +0 -10
- package/lib/rules/constructorReturns.js +0 -41
- package/lib/rules/constructorSupers.d.ts +0 -10
- package/lib/rules/constructorSupers.js +0 -77
- package/lib/rules/dateConstructorClones.d.ts +0 -10
- package/lib/rules/dateConstructorClones.js +0 -37
- package/lib/rules/dateNowTimestamps.d.ts +0 -10
- package/lib/rules/dateNowTimestamps.js +0 -57
- package/lib/rules/debuggerStatements.d.ts +0 -10
- package/lib/rules/debuggerStatements.js +0 -33
- package/lib/rules/defaultCaseLast.d.ts +0 -10
- package/lib/rules/defaultCaseLast.js +0 -36
- package/lib/rules/defaultParameterLast.d.ts +0 -10
- package/lib/rules/defaultParameterLast.js +0 -42
- package/lib/rules/deprecated.d.ts +0 -10
- package/lib/rules/deprecated.js +0 -243
- package/lib/rules/destructuringConsistency.d.ts +0 -10
- package/lib/rules/destructuringConsistency.js +0 -112
- package/lib/rules/duplicateArguments.d.ts +0 -10
- package/lib/rules/duplicateArguments.js +0 -45
- package/lib/rules/dynamicDeletes.d.ts +0 -10
- package/lib/rules/dynamicDeletes.js +0 -37
- package/lib/rules/elseIfDuplicates.d.ts +0 -10
- package/lib/rules/elseIfDuplicates.js +0 -38
- package/lib/rules/elseReturns.d.ts +0 -10
- package/lib/rules/elseReturns.js +0 -67
- package/lib/rules/emptyBlocks.d.ts +0 -10
- package/lib/rules/emptyBlocks.js +0 -56
- package/lib/rules/emptyDestructures.d.ts +0 -10
- package/lib/rules/emptyDestructures.js +0 -34
- package/lib/rules/emptyEnums.d.ts +0 -10
- package/lib/rules/emptyEnums.js +0 -30
- package/lib/rules/emptyExports.d.ts +0 -10
- package/lib/rules/emptyExports.js +0 -60
- package/lib/rules/emptyFiles.d.ts +0 -10
- package/lib/rules/emptyFiles.js +0 -44
- package/lib/rules/emptyFunctions.d.ts +0 -10
- package/lib/rules/emptyFunctions.js +0 -61
- package/lib/rules/emptyModuleAttributes.d.ts +0 -10
- package/lib/rules/emptyModuleAttributes.js +0 -35
- package/lib/rules/emptyObjectTypes.d.ts +0 -10
- package/lib/rules/emptyObjectTypes.js +0 -47
- package/lib/rules/emptyStaticBlocks.d.ts +0 -10
- package/lib/rules/emptyStaticBlocks.js +0 -42
- package/lib/rules/emptyTypeParameterLists.d.ts +0 -10
- package/lib/rules/emptyTypeParameterLists.js +0 -31
- package/lib/rules/enumInitializers.d.ts +0 -10
- package/lib/rules/enumInitializers.js +0 -54
- package/lib/rules/enumMemberLiterals.d.ts +0 -10
- package/lib/rules/enumMemberLiterals.js +0 -39
- package/lib/rules/enumValueConsistency.d.ts +0 -10
- package/lib/rules/enumValueConsistency.js +0 -56
- package/lib/rules/enumValueDuplicates.d.ts +0 -10
- package/lib/rules/enumValueDuplicates.js +0 -60
- package/lib/rules/equalityOperatorNegations.d.ts +0 -9
- package/lib/rules/equalityOperatorNegations.js +0 -60
- package/lib/rules/equalityOperators.d.ts +0 -10
- package/lib/rules/equalityOperators.js +0 -44
- package/lib/rules/errorMessages.d.ts +0 -10
- package/lib/rules/errorMessages.js +0 -60
- package/lib/rules/errorSubclassProperties.d.ts +0 -10
- package/lib/rules/errorSubclassProperties.js +0 -144
- package/lib/rules/errorUnnecessaryCaptureStackTraces.d.ts +0 -10
- package/lib/rules/errorUnnecessaryCaptureStackTraces.js +0 -55
- package/lib/rules/escapeSequenceCasing.d.ts +0 -10
- package/lib/rules/escapeSequenceCasing.js +0 -75
- package/lib/rules/evals.d.ts +0 -10
- package/lib/rules/evals.js +0 -31
- package/lib/rules/evolvingVariableTypes.d.ts +0 -10
- package/lib/rules/evolvingVariableTypes.js +0 -33
- package/lib/rules/exceptionAssignments.d.ts +0 -10
- package/lib/rules/exceptionAssignments.js +0 -39
- package/lib/rules/explicitAnys.d.ts +0 -10
- package/lib/rules/explicitAnys.js +0 -55
- package/lib/rules/exponentiationOperators.d.ts +0 -10
- package/lib/rules/exponentiationOperators.js +0 -34
- package/lib/rules/exportFromImports.d.ts +0 -10
- package/lib/rules/exportFromImports.js +0 -119
- package/lib/rules/exportMutables.d.ts +0 -10
- package/lib/rules/exportMutables.js +0 -33
- package/lib/rules/exportUniqueNames.d.ts +0 -10
- package/lib/rules/exportUniqueNames.js +0 -65
- package/lib/rules/extraneousClasses.d.ts +0 -16
- package/lib/rules/extraneousClasses.js +0 -111
- package/lib/rules/fetchMethodBodies.d.ts +0 -10
- package/lib/rules/fetchMethodBodies.js +0 -72
- package/lib/rules/finallyStatementSafety.d.ts +0 -10
- package/lib/rules/finallyStatementSafety.js +0 -47
- package/lib/rules/forDirections.d.ts +0 -10
- package/lib/rules/forDirections.js +0 -75
- package/lib/rules/forInArrays.d.ts +0 -10
- package/lib/rules/forInArrays.js +0 -46
- package/lib/rules/forInGuards.d.ts +0 -9
- package/lib/rules/forInGuards.js +0 -44
- package/lib/rules/functionApplySpreads.d.ts +0 -10
- package/lib/rules/functionApplySpreads.js +0 -63
- package/lib/rules/functionAssignments.d.ts +0 -10
- package/lib/rules/functionAssignments.js +0 -29
- package/lib/rules/functionCurryingRedundancy.d.ts +0 -10
- package/lib/rules/functionCurryingRedundancy.js +0 -53
- package/lib/rules/functionDeclarationStyles.d.ts +0 -16
- package/lib/rules/functionDeclarationStyles.js +0 -67
- package/lib/rules/functionNameMatches.d.ts +0 -10
- package/lib/rules/functionNameMatches.js +0 -74
- package/lib/rules/functionNewCalls.d.ts +0 -10
- package/lib/rules/functionNewCalls.js +0 -42
- package/lib/rules/generatorFunctionYields.d.ts +0 -10
- package/lib/rules/generatorFunctionYields.js +0 -50
- package/lib/rules/getterReturns.d.ts +0 -10
- package/lib/rules/getterReturns.js +0 -65
- package/lib/rules/globalAssignments.d.ts +0 -10
- package/lib/rules/globalAssignments.js +0 -47
- package/lib/rules/globalObjectCalls.d.ts +0 -10
- package/lib/rules/globalObjectCalls.js +0 -42
- package/lib/rules/globalThisAliases.d.ts +0 -10
- package/lib/rules/globalThisAliases.js +0 -47
- package/lib/rules/impliedEvals.d.ts +0 -10
- package/lib/rules/impliedEvals.js +0 -130
- package/lib/rules/importEmptyBlocks.d.ts +0 -10
- package/lib/rules/importEmptyBlocks.js +0 -53
- package/lib/rules/importTypeSideEffects.d.ts +0 -10
- package/lib/rules/importTypeSideEffects.js +0 -31
- package/lib/rules/indexedObjectTypes.d.ts +0 -16
- package/lib/rules/indexedObjectTypes.js +0 -83
- package/lib/rules/instanceOfArrays.d.ts +0 -10
- package/lib/rules/instanceOfArrays.js +0 -31
- package/lib/rules/irregularWhitespaces.d.ts +0 -16
- package/lib/rules/irregularWhitespaces.js +0 -97
- package/lib/rules/isNaNComparisons.d.ts +0 -10
- package/lib/rules/isNaNComparisons.js +0 -43
- package/lib/rules/literalConstructorWrappers.d.ts +0 -10
- package/lib/rules/literalConstructorWrappers.js +0 -64
- package/lib/rules/mathMethods.d.ts +0 -10
- package/lib/rules/mathMethods.js +0 -128
- package/lib/rules/meaninglessVoidOperators.d.ts +0 -10
- package/lib/rules/meaninglessVoidOperators.js +0 -39
- package/lib/rules/misleadingVoidExpressions.d.ts +0 -10
- package/lib/rules/misleadingVoidExpressions.js +0 -128
- package/lib/rules/moduleSpecifierLists.d.ts +0 -10
- package/lib/rules/moduleSpecifierLists.js +0 -92
- package/lib/rules/multilineAmbiguities.d.ts +0 -10
- package/lib/rules/multilineAmbiguities.js +0 -64
- package/lib/rules/namedDefaultExports.d.ts +0 -10
- package/lib/rules/namedDefaultExports.js +0 -60
- package/lib/rules/namespaceDeclarations.d.ts +0 -14
- package/lib/rules/namespaceDeclarations.js +0 -37
- package/lib/rules/namespaceImplicitAmbientImports.d.ts +0 -10
- package/lib/rules/namespaceImplicitAmbientImports.js +0 -40
- package/lib/rules/namespaceKeywords.d.ts +0 -10
- package/lib/rules/namespaceKeywords.js +0 -40
- package/lib/rules/nativeObjectExtensions.d.ts +0 -10
- package/lib/rules/nativeObjectExtensions.js +0 -114
- package/lib/rules/negativeIndexLengthMethods.d.ts +0 -10
- package/lib/rules/negativeIndexLengthMethods.js +0 -180
- package/lib/rules/negativeZeroComparisons.d.ts +0 -10
- package/lib/rules/negativeZeroComparisons.js +0 -48
- package/lib/rules/nestedStandaloneIfs.d.ts +0 -10
- package/lib/rules/nestedStandaloneIfs.js +0 -105
- package/lib/rules/newDefinitions.d.ts +0 -10
- package/lib/rules/newDefinitions.js +0 -84
- package/lib/rules/newExpressions.d.ts +0 -10
- package/lib/rules/newExpressions.js +0 -38
- package/lib/rules/newNativeNonConstructors.d.ts +0 -10
- package/lib/rules/newNativeNonConstructors.js +0 -39
- package/lib/rules/nonNullAssertedNullishCoalesces.d.ts +0 -10
- package/lib/rules/nonNullAssertedNullishCoalesces.js +0 -63
- package/lib/rules/nonNullAssertedOptionalChains.d.ts +0 -10
- package/lib/rules/nonNullAssertedOptionalChains.js +0 -69
- package/lib/rules/nonNullAssertionPlacement.d.ts +0 -10
- package/lib/rules/nonNullAssertionPlacement.js +0 -94
- package/lib/rules/nonNullableTypeAssertions.d.ts +0 -10
- package/lib/rules/nonNullableTypeAssertions.js +0 -78
- package/lib/rules/nonOctalDecimalEscapes.d.ts +0 -10
- package/lib/rules/nonOctalDecimalEscapes.js +0 -48
- package/lib/rules/nullishCheckStyle.d.ts +0 -21
- package/lib/rules/nullishCheckStyle.js +0 -144
- package/lib/rules/nullishCoalescingOperators.d.ts +0 -22
- package/lib/rules/nullishCoalescingOperators.js +0 -323
- package/lib/rules/numberMethodRanges.d.ts +0 -10
- package/lib/rules/numberMethodRanges.js +0 -74
- package/lib/rules/numberStaticMethods.d.ts +0 -10
- package/lib/rules/numberStaticMethods.js +0 -53
- package/lib/rules/numericErasingOperations.d.ts +0 -10
- package/lib/rules/numericErasingOperations.js +0 -46
- package/lib/rules/numericLiteralParsing.d.ts +0 -10
- package/lib/rules/numericLiteralParsing.js +0 -66
- package/lib/rules/numericPrecision.d.ts +0 -10
- package/lib/rules/numericPrecision.js +0 -102
- package/lib/rules/numericSeparatorGroups.d.ts +0 -10
- package/lib/rules/numericSeparatorGroups.js +0 -101
- package/lib/rules/objectAssignSpreads.d.ts +0 -10
- package/lib/rules/objectAssignSpreads.js +0 -53
- package/lib/rules/objectCalls.d.ts +0 -10
- package/lib/rules/objectCalls.js +0 -38
- package/lib/rules/objectEntriesMethods.d.ts +0 -10
- package/lib/rules/objectEntriesMethods.js +0 -82
- package/lib/rules/objectHasOwns.d.ts +0 -10
- package/lib/rules/objectHasOwns.js +0 -50
- package/lib/rules/objectKeyDuplicates.d.ts +0 -10
- package/lib/rules/objectKeyDuplicates.js +0 -63
- package/lib/rules/objectProto.d.ts +0 -10
- package/lib/rules/objectProto.js +0 -50
- package/lib/rules/objectPrototypeBuiltIns.d.ts +0 -10
- package/lib/rules/objectPrototypeBuiltIns.js +0 -54
- package/lib/rules/objectShorthand.d.ts +0 -10
- package/lib/rules/objectShorthand.js +0 -84
- package/lib/rules/objectSpreadUnnecessaryFallbacks.d.ts +0 -10
- package/lib/rules/objectSpreadUnnecessaryFallbacks.js +0 -43
- package/lib/rules/objectTypeDefinitions.d.ts +0 -10
- package/lib/rules/objectTypeDefinitions.js +0 -34
- package/lib/rules/octalEscapes.d.ts +0 -10
- package/lib/rules/octalEscapes.js +0 -58
- package/lib/rules/octalNumbers.d.ts +0 -10
- package/lib/rules/octalNumbers.js +0 -55
- package/lib/rules/operatorAssignmentShorthand.d.ts +0 -10
- package/lib/rules/operatorAssignmentShorthand.js +0 -77
- package/lib/rules/overloadSignaturesAdjacent.d.ts +0 -10
- package/lib/rules/overloadSignaturesAdjacent.js +0 -140
- package/lib/rules/parameterReassignments.d.ts +0 -10
- package/lib/rules/parameterReassignments.js +0 -45
- package/lib/rules/parseIntRadixes.d.ts +0 -10
- package/lib/rules/parseIntRadixes.js +0 -62
- package/lib/rules/propertyAccessNotation.d.ts +0 -13
- package/lib/rules/propertyAccessNotation.js +0 -119
- package/lib/rules/recursionOnlyArguments.d.ts +0 -10
- package/lib/rules/recursionOnlyArguments.js +0 -71
- package/lib/rules/redundantTypeConstituents.d.ts +0 -10
- package/lib/rules/redundantTypeConstituents.js +0 -277
- package/lib/rules/regexAllGlobalFlags.d.ts +0 -10
- package/lib/rules/regexAllGlobalFlags.js +0 -56
- package/lib/rules/regexAmbiguousInvalidity.d.ts +0 -10
- package/lib/rules/regexAmbiguousInvalidity.js +0 -297
- package/lib/rules/regexCharacterClassRanges.d.ts +0 -10
- package/lib/rules/regexCharacterClassRanges.js +0 -137
- package/lib/rules/regexCharacterClassSetOperations.d.ts +0 -10
- package/lib/rules/regexCharacterClassSetOperations.js +0 -81
- package/lib/rules/regexCharacterClasses.d.ts +0 -10
- package/lib/rules/regexCharacterClasses.js +0 -234
- package/lib/rules/regexConciseCharacterClassNegations.d.ts +0 -10
- package/lib/rules/regexConciseCharacterClassNegations.js +0 -52
- package/lib/rules/regexContradictoryAssertions.d.ts +0 -10
- package/lib/rules/regexContradictoryAssertions.js +0 -210
- package/lib/rules/regexControlCharacterEscapes.d.ts +0 -10
- package/lib/rules/regexControlCharacterEscapes.js +0 -130
- package/lib/rules/regexControlCharacters.d.ts +0 -10
- package/lib/rules/regexControlCharacters.js +0 -95
- package/lib/rules/regexDigitMatchers.d.ts +0 -10
- package/lib/rules/regexDigitMatchers.js +0 -180
- package/lib/rules/regexDollarEscapes.d.ts +0 -10
- package/lib/rules/regexDollarEscapes.js +0 -91
- package/lib/rules/regexDuplicateCharacterClassCharacters.d.ts +0 -10
- package/lib/rules/regexDuplicateCharacterClassCharacters.js +0 -128
- package/lib/rules/regexEmptyAlternatives.d.ts +0 -10
- package/lib/rules/regexEmptyAlternatives.js +0 -140
- package/lib/rules/regexEmptyCapturingGroups.d.ts +0 -10
- package/lib/rules/regexEmptyCapturingGroups.js +0 -67
- package/lib/rules/regexEmptyCharacterClasses.d.ts +0 -10
- package/lib/rules/regexEmptyCharacterClasses.js +0 -68
- package/lib/rules/regexEmptyGroups.d.ts +0 -10
- package/lib/rules/regexEmptyGroups.js +0 -66
- package/lib/rules/regexEmptyLazyQuantifiers.d.ts +0 -10
- package/lib/rules/regexEmptyLazyQuantifiers.js +0 -92
- package/lib/rules/regexEmptyLookaroundsAssertions.d.ts +0 -10
- package/lib/rules/regexEmptyLookaroundsAssertions.js +0 -68
- package/lib/rules/regexEmptyStringLiterals.d.ts +0 -10
- package/lib/rules/regexEmptyStringLiterals.js +0 -66
- package/lib/rules/regexEscapeBackspaces.d.ts +0 -10
- package/lib/rules/regexEscapeBackspaces.js +0 -69
- package/lib/rules/regexExecutors.d.ts +0 -10
- package/lib/rules/regexExecutors.js +0 -58
- package/lib/rules/regexGraphemeStringLiterals.d.ts +0 -10
- package/lib/rules/regexGraphemeStringLiterals.js +0 -51
- package/lib/rules/regexHexadecimalEscapes.d.ts +0 -10
- package/lib/rules/regexHexadecimalEscapes.js +0 -71
- package/lib/rules/regexIgnoreCaseFlags.d.ts +0 -10
- package/lib/rules/regexIgnoreCaseFlags.js +0 -145
- package/lib/rules/regexInvisibleCharacters.d.ts +0 -10
- package/lib/rules/regexInvisibleCharacters.js +0 -90
- package/lib/rules/regexLetterCasing.d.ts +0 -10
- package/lib/rules/regexLetterCasing.js +0 -186
- package/lib/rules/regexLiterals.d.ts +0 -10
- package/lib/rules/regexLiterals.js +0 -92
- package/lib/rules/regexLookaroundAssertions.d.ts +0 -10
- package/lib/rules/regexLookaroundAssertions.js +0 -163
- package/lib/rules/regexLookaroundQuantifierOptimizations.d.ts +0 -10
- package/lib/rules/regexLookaroundQuantifierOptimizations.js +0 -94
- package/lib/rules/regexMatchNotation.d.ts +0 -10
- package/lib/rules/regexMatchNotation.js +0 -139
- package/lib/rules/regexMisleadingCapturingGroups.d.ts +0 -10
- package/lib/rules/regexMisleadingCapturingGroups.js +0 -229
- package/lib/rules/regexMisleadingQuantifiers.d.ts +0 -10
- package/lib/rules/regexMisleadingQuantifiers.js +0 -78
- package/lib/rules/regexMisleadingUnicodeCharacters.d.ts +0 -10
- package/lib/rules/regexMisleadingUnicodeCharacters.js +0 -203
- package/lib/rules/regexNamedBackreferences.d.ts +0 -10
- package/lib/rules/regexNamedBackreferences.js +0 -48
- package/lib/rules/regexNamedCaptureGroups.d.ts +0 -9
- package/lib/rules/regexNamedCaptureGroups.js +0 -67
- package/lib/rules/regexNamedReplacements.d.ts +0 -10
- package/lib/rules/regexNamedReplacements.js +0 -93
- package/lib/rules/regexNonStandardFlags.d.ts +0 -10
- package/lib/rules/regexNonStandardFlags.js +0 -66
- package/lib/rules/regexObscureRanges.d.ts +0 -10
- package/lib/rules/regexObscureRanges.js +0 -93
- package/lib/rules/regexOctalEscapes.d.ts +0 -10
- package/lib/rules/regexOctalEscapes.js +0 -70
- package/lib/rules/regexPlusQuantifiers.d.ts +0 -10
- package/lib/rules/regexPlusQuantifiers.js +0 -68
- package/lib/rules/regexPredefinedAssertions.d.ts +0 -10
- package/lib/rules/regexPredefinedAssertions.js +0 -127
- package/lib/rules/regexQuestionQuantifiers.d.ts +0 -10
- package/lib/rules/regexQuestionQuantifiers.js +0 -104
- package/lib/rules/regexRepeatQuantifiers.d.ts +0 -10
- package/lib/rules/regexRepeatQuantifiers.js +0 -96
- package/lib/rules/regexResultArrayGroups.d.ts +0 -10
- package/lib/rules/regexResultArrayGroups.js +0 -187
- package/lib/rules/regexSetOperationOptimizations.d.ts +0 -10
- package/lib/rules/regexSetOperationOptimizations.js +0 -177
- package/lib/rules/regexStandaloneBackslashes.d.ts +0 -10
- package/lib/rules/regexStandaloneBackslashes.js +0 -59
- package/lib/rules/regexStarQuantifiers.d.ts +0 -10
- package/lib/rules/regexStarQuantifiers.js +0 -68
- package/lib/rules/regexSuperLinearBacktracking.d.ts +0 -10
- package/lib/rules/regexSuperLinearBacktracking.js +0 -98
- package/lib/rules/regexSuperLinearMoves.d.ts +0 -10
- package/lib/rules/regexSuperLinearMoves.js +0 -142
- package/lib/rules/regexTestMethods.d.ts +0 -10
- package/lib/rules/regexTestMethods.js +0 -83
- package/lib/rules/regexUnicodeCodepointEscapes.d.ts +0 -10
- package/lib/rules/regexUnicodeCodepointEscapes.js +0 -107
- package/lib/rules/regexUnicodeEscapes.d.ts +0 -9
- package/lib/rules/regexUnicodeEscapes.js +0 -97
- package/lib/rules/regexUnicodeFlag.d.ts +0 -9
- package/lib/rules/regexUnicodeFlag.js +0 -97
- package/lib/rules/regexUnicodeProperties.d.ts +0 -10
- package/lib/rules/regexUnicodeProperties.js +0 -133
- package/lib/rules/regexUnnecessaryAssertions.d.ts +0 -10
- package/lib/rules/regexUnnecessaryAssertions.js +0 -223
- package/lib/rules/regexUnnecessaryBackreferences.d.ts +0 -10
- package/lib/rules/regexUnnecessaryBackreferences.js +0 -125
- package/lib/rules/regexUnnecessaryCharacterClasses.d.ts +0 -10
- package/lib/rules/regexUnnecessaryCharacterClasses.js +0 -74
- package/lib/rules/regexUnnecessaryCharacterRanges.d.ts +0 -10
- package/lib/rules/regexUnnecessaryCharacterRanges.js +0 -108
- package/lib/rules/regexUnnecessaryDisjunctions.d.ts +0 -10
- package/lib/rules/regexUnnecessaryDisjunctions.js +0 -118
- package/lib/rules/regexUnnecessaryDollarReplacements.d.ts +0 -10
- package/lib/rules/regexUnnecessaryDollarReplacements.js +0 -144
- package/lib/rules/regexUnnecessaryEscapes.d.ts +0 -10
- package/lib/rules/regexUnnecessaryEscapes.js +0 -136
- package/lib/rules/regexUnnecessaryLookaroundAssertions.d.ts +0 -10
- package/lib/rules/regexUnnecessaryLookaroundAssertions.js +0 -80
- package/lib/rules/regexUnnecessaryNestedAssertions.d.ts +0 -10
- package/lib/rules/regexUnnecessaryNestedAssertions.js +0 -198
- package/lib/rules/regexUnnecessaryNestedQuantifiers.d.ts +0 -10
- package/lib/rules/regexUnnecessaryNestedQuantifiers.js +0 -93
- package/lib/rules/regexUnnecessaryNonCapturingGroups.d.ts +0 -10
- package/lib/rules/regexUnnecessaryNonCapturingGroups.js +0 -104
- package/lib/rules/regexUnnecessaryNumericQuantifiers.d.ts +0 -10
- package/lib/rules/regexUnnecessaryNumericQuantifiers.js +0 -69
- package/lib/rules/regexUnnecessaryOptionalAssertions.d.ts +0 -10
- package/lib/rules/regexUnnecessaryOptionalAssertions.js +0 -137
- package/lib/rules/regexUnnecessaryReferentialBackreferences.d.ts +0 -10
- package/lib/rules/regexUnnecessaryReferentialBackreferences.js +0 -123
- package/lib/rules/regexUnnecessarySetOperands.d.ts +0 -10
- package/lib/rules/regexUnnecessarySetOperands.js +0 -136
- package/lib/rules/regexUnusedCapturingGroups.d.ts +0 -10
- package/lib/rules/regexUnusedCapturingGroups.js +0 -69
- package/lib/rules/regexUnusedFlags.d.ts +0 -10
- package/lib/rules/regexUnusedFlags.js +0 -116
- package/lib/rules/regexUnusedLazyQuantifiers.d.ts +0 -10
- package/lib/rules/regexUnusedLazyQuantifiers.js +0 -63
- package/lib/rules/regexUnusedQuantifiers.d.ts +0 -10
- package/lib/rules/regexUnusedQuantifiers.js +0 -63
- package/lib/rules/regexValidity.d.ts +0 -10
- package/lib/rules/regexValidity.js +0 -146
- package/lib/rules/regexWordMatchers.d.ts +0 -10
- package/lib/rules/regexWordMatchers.js +0 -146
- package/lib/rules/regexZeroQuantifiers.d.ts +0 -10
- package/lib/rules/regexZeroQuantifiers.js +0 -60
- package/lib/rules/requireImports.d.ts +0 -10
- package/lib/rules/requireImports.js +0 -48
- package/lib/rules/responseJsonMethods.d.ts +0 -10
- package/lib/rules/responseJsonMethods.js +0 -51
- package/lib/rules/restrictedIdentifiers.d.ts +0 -13
- package/lib/rules/restrictedIdentifiers.js +0 -41
- package/lib/rules/restrictedImports.d.ts +0 -27
- package/lib/rules/restrictedImports.js +0 -166
- package/lib/rules/returnAssignments.d.ts +0 -10
- package/lib/rules/returnAssignments.js +0 -38
- package/lib/rules/returnThisTypes.d.ts +0 -10
- package/lib/rules/returnThisTypes.js +0 -94
- package/lib/rules/ruleCreator.d.ts +0 -3
- package/lib/rules/ruleCreator.js +0 -17
- package/lib/rules/selfAssignments.d.ts +0 -10
- package/lib/rules/selfAssignments.js +0 -29
- package/lib/rules/sequences.d.ts +0 -10
- package/lib/rules/sequences.js +0 -28
- package/lib/rules/setSizeLengthChecks.d.ts +0 -10
- package/lib/rules/setSizeLengthChecks.js +0 -48
- package/lib/rules/setterReturns.d.ts +0 -10
- package/lib/rules/setterReturns.js +0 -41
- package/lib/rules/shadowedRestrictedNames.d.ts +0 -10
- package/lib/rules/shadowedRestrictedNames.js +0 -68
- package/lib/rules/singleVariableDeclarations.d.ts +0 -10
- package/lib/rules/singleVariableDeclarations.js +0 -36
- package/lib/rules/sizeComparisonOperators.d.ts +0 -16
- package/lib/rules/sizeComparisonOperators.js +0 -148
- package/lib/rules/sparseArrays.d.ts +0 -10
- package/lib/rules/sparseArrays.js +0 -43
- package/lib/rules/staticMemberOnlyClasses.d.ts +0 -10
- package/lib/rules/staticMemberOnlyClasses.js +0 -77
- package/lib/rules/stringCaseMismatches.d.ts +0 -10
- package/lib/rules/stringCaseMismatches.js +0 -58
- package/lib/rules/stringCodePoints.d.ts +0 -10
- package/lib/rules/stringCodePoints.js +0 -50
- package/lib/rules/stringSliceMethods.d.ts +0 -10
- package/lib/rules/stringSliceMethods.js +0 -47
- package/lib/rules/stringStartsEndsWith.d.ts +0 -10
- package/lib/rules/stringStartsEndsWith.js +0 -79
- package/lib/rules/structuredCloneMethods.d.ts +0 -10
- package/lib/rules/structuredCloneMethods.js +0 -39
- package/lib/rules/symbolDescriptions.d.ts +0 -10
- package/lib/rules/symbolDescriptions.js +0 -32
- package/lib/rules/thisAliases.d.ts +0 -10
- package/lib/rules/thisAliases.js +0 -44
- package/lib/rules/thisBeforeSuper.d.ts +0 -10
- package/lib/rules/thisBeforeSuper.js +0 -86
- package/lib/rules/throwErrors.d.ts +0 -10
- package/lib/rules/throwErrors.js +0 -61
- package/lib/rules/topLevelAwaits.d.ts +0 -10
- package/lib/rules/topLevelAwaits.js +0 -49
- package/lib/rules/tripleSlashReferenceValidity.d.ts +0 -10
- package/lib/rules/tripleSlashReferenceValidity.js +0 -54
- package/lib/rules/tripleSlashReferences.d.ts +0 -10
- package/lib/rules/tripleSlashReferences.js +0 -34
- package/lib/rules/tsComments.d.ts +0 -22
- package/lib/rules/tsComments.js +0 -130
- package/lib/rules/tslintComments.d.ts +0 -10
- package/lib/rules/tslintComments.js +0 -36
- package/lib/rules/typeAssertionStyles.d.ts +0 -10
- package/lib/rules/typeAssertionStyles.js +0 -32
- package/lib/rules/typeImports.d.ts +0 -20
- package/lib/rules/typeImports.js +0 -283
- package/lib/rules/typeofComparisons.d.ts +0 -10
- package/lib/rules/typeofComparisons.js +0 -58
- package/lib/rules/unassignedVariables.d.ts +0 -10
- package/lib/rules/unassignedVariables.js +0 -34
- package/lib/rules/undefinedTypeofChecks.d.ts +0 -10
- package/lib/rules/undefinedTypeofChecks.js +0 -41
- package/lib/rules/undefinedVariables.d.ts +0 -10
- package/lib/rules/undefinedVariables.js +0 -39
- package/lib/rules/unicodeBOMs.d.ts +0 -10
- package/lib/rules/unicodeBOMs.js +0 -39
- package/lib/rules/unnecessaryBinds.d.ts +0 -10
- package/lib/rules/unnecessaryBinds.js +0 -78
- package/lib/rules/unnecessaryBlocks.d.ts +0 -10
- package/lib/rules/unnecessaryBlocks.js +0 -60
- package/lib/rules/unnecessaryBooleanCasts.d.ts +0 -10
- package/lib/rules/unnecessaryBooleanCasts.js +0 -58
- package/lib/rules/unnecessaryCatches.d.ts +0 -10
- package/lib/rules/unnecessaryCatches.js +0 -48
- package/lib/rules/unnecessaryComparisons.d.ts +0 -10
- package/lib/rules/unnecessaryComparisons.js +0 -300
- package/lib/rules/unnecessaryConcatenation.d.ts +0 -10
- package/lib/rules/unnecessaryConcatenation.js +0 -28
- package/lib/rules/unnecessaryEscapes.d.ts +0 -10
- package/lib/rules/unnecessaryEscapes.js +0 -134
- package/lib/rules/unnecessaryMathClamps.d.ts +0 -10
- package/lib/rules/unnecessaryMathClamps.js +0 -114
- package/lib/rules/unnecessaryNumericFractions.d.ts +0 -10
- package/lib/rules/unnecessaryNumericFractions.js +0 -50
- package/lib/rules/unnecessaryRenames.d.ts +0 -10
- package/lib/rules/unnecessaryRenames.js +0 -92
- package/lib/rules/unnecessaryTernaries.d.ts +0 -10
- package/lib/rules/unnecessaryTernaries.js +0 -88
- package/lib/rules/unnecessaryUseStricts.d.ts +0 -10
- package/lib/rules/unnecessaryUseStricts.js +0 -40
- package/lib/rules/unsafeNegations.d.ts +0 -10
- package/lib/rules/unsafeNegations.js +0 -38
- package/lib/rules/utils/collectAccessorPairs.d.ts +0 -12
- package/lib/rules/utils/collectAccessorPairs.js +0 -29
- package/lib/rules/utils/countCommentsInRange.d.ts +0 -3
- package/lib/rules/utils/countCommentsInRange.js +0 -12
- package/lib/rules/utils/discriminateAnyType.d.ts +0 -16
- package/lib/rules/utils/discriminateAnyType.js +0 -38
- package/lib/rules/utils/equalityOperators.d.ts +0 -9
- package/lib/rules/utils/equalityOperators.js +0 -36
- package/lib/rules/utils/forEachReturnStatement.d.ts +0 -3
- package/lib/rules/utils/forEachReturnStatement.js +0 -29
- package/lib/rules/utils/formatReportedType.d.ts +0 -4
- package/lib/rules/utils/formatReportedType.js +0 -9
- package/lib/rules/utils/getConstrainedType.d.ts +0 -3
- package/lib/rules/utils/getConstrainedType.js +0 -9
- package/lib/rules/utils/getFunctionName.d.ts +0 -3
- package/lib/rules/utils/getFunctionName.js +0 -16
- package/lib/rules/utils/getRegExpConstruction.d.ts +0 -10
- package/lib/rules/utils/getRegExpConstruction.js +0 -26
- package/lib/rules/utils/getRegExpLiteralDetails.d.ts +0 -7
- package/lib/rules/utils/getRegExpLiteralDetails.js +0 -13
- package/lib/rules/utils/getThisExpression.d.ts +0 -3
- package/lib/rules/utils/getThisExpression.js +0 -16
- package/lib/rules/utils/isArrayOrTupleTypeAtLocation.d.ts +0 -3
- package/lib/rules/utils/isArrayOrTupleTypeAtLocation.js +0 -13
- package/lib/rules/utils/isBuiltinSymbolLike.d.ts +0 -3
- package/lib/rules/utils/isBuiltinSymbolLike.js +0 -33
- package/lib/rules/utils/isDirectEqualityCheck.d.ts +0 -4
- package/lib/rules/utils/isDirectEqualityCheck.js +0 -29
- package/lib/rules/utils/isErrorSubclass.d.ts +0 -3
- package/lib/rules/utils/isErrorSubclass.js +0 -27
- package/lib/rules/utils/isInBooleanContext.d.ts +0 -3
- package/lib/rules/utils/isInBooleanContext.js +0 -22
- package/lib/rules/utils/isTypeRecursive.d.ts +0 -3
- package/lib/rules/utils/isTypeRecursive.js +0 -8
- package/lib/rules/utils/isUnsafeAssignment.d.ts +0 -15
- package/lib/rules/utils/isUnsafeAssignment.js +0 -45
- package/lib/rules/utils/operators.d.ts +0 -5
- package/lib/rules/utils/operators.js +0 -35
- package/lib/rules/utils/parseRegexpAst.d.ts +0 -2
- package/lib/rules/utils/parseRegexpAst.js +0 -17
- package/lib/rules/utils/parseRegexpAstFull.d.ts +0 -3
- package/lib/rules/utils/parseRegexpAstFull.js +0 -18
- package/lib/rules/utils/skipParentheses.d.ts +0 -3
- package/lib/rules/utils/skipParentheses.js +0 -10
- package/lib/rules/variableDeletions.d.ts +0 -10
- package/lib/rules/variableDeletions.js +0 -35
- package/lib/rules/voidOperator.d.ts +0 -10
- package/lib/rules/voidOperator.js +0 -34
- package/lib/rules/withStatements.d.ts +0 -10
- package/lib/rules/withStatements.js +0 -30
- package/lib/rules/wrapperObjects.d.ts +0 -10
- package/lib/rules/wrapperObjects.js +0 -36
- package/lib/type-utils/getSpecifierNames.d.ts +0 -3
- package/lib/type-utils/getSpecifierNames.js +0 -9
- package/lib/type-utils/isDeclaredInModuleBlock.d.ts +0 -3
- package/lib/type-utils/isDeclaredInModuleBlock.js +0 -14
- package/lib/type-utils/isFromFile.d.ts +0 -3
- package/lib/type-utils/isFromFile.js +0 -13
- package/lib/type-utils/isFromPackage.d.ts +0 -3
- package/lib/type-utils/isFromPackage.js +0 -16
- package/lib/type-utils/matchesSpecifier.d.ts +0 -4
- package/lib/type-utils/matchesSpecifier.js +0 -20
- package/lib/type-utils/schemas.d.ts +0 -15
- package/lib/type-utils/schemas.js +0 -25
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getTSNodeRange, typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
import * as tsutils from "ts-api-utils";
|
|
5
|
-
//#region src/rules/nonNullableTypeAssertions.ts
|
|
6
|
-
function couldBeNullish(type) {
|
|
7
|
-
if (type.flags & ts.TypeFlags.TypeParameter) {
|
|
8
|
-
const constraint = type.getConstraint();
|
|
9
|
-
return constraint === void 0 || couldBeNullish(constraint);
|
|
10
|
-
}
|
|
11
|
-
if (tsutils.isUnionType(type)) return type.types.some(couldBeNullish);
|
|
12
|
-
return (type.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) !== 0;
|
|
13
|
-
}
|
|
14
|
-
function getTypesIfNotLoose(node, typeChecker) {
|
|
15
|
-
const type = typeChecker.getTypeAtLocation(node);
|
|
16
|
-
if (tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) return;
|
|
17
|
-
return tsutils.unionConstituents(type);
|
|
18
|
-
}
|
|
19
|
-
function isConstAssertion(node, sourceFile) {
|
|
20
|
-
return node.type.kind === ts.SyntaxKind.TypeReference && node.type.typeName.kind === ts.SyntaxKind.Identifier && node.type.typeName.getText(sourceFile) === "const";
|
|
21
|
-
}
|
|
22
|
-
function needsParentheses(expression) {
|
|
23
|
-
switch (expression.kind) {
|
|
24
|
-
case ts.SyntaxKind.ArrowFunction:
|
|
25
|
-
case ts.SyntaxKind.AwaitExpression:
|
|
26
|
-
case ts.SyntaxKind.BinaryExpression:
|
|
27
|
-
case ts.SyntaxKind.ConditionalExpression:
|
|
28
|
-
case ts.SyntaxKind.PrefixUnaryExpression:
|
|
29
|
-
case ts.SyntaxKind.YieldExpression: return true;
|
|
30
|
-
default: return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function sameTypeWithoutNullish(assertedTypes, originalTypes) {
|
|
34
|
-
const nonNullishOriginalTypes = originalTypes.filter((type) => (type.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) === 0);
|
|
35
|
-
if (nonNullishOriginalTypes.length === originalTypes.length) return false;
|
|
36
|
-
for (const assertedType of assertedTypes) if (couldBeNullish(assertedType) || !nonNullishOriginalTypes.includes(assertedType)) return false;
|
|
37
|
-
for (const originalType of nonNullishOriginalTypes) if (!assertedTypes.includes(originalType)) return false;
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
var nonNullableTypeAssertions_default = ruleCreator.createRule(typescriptLanguage, {
|
|
41
|
-
about: {
|
|
42
|
-
description: "Reports type assertions that can be replaced with non-null assertions.",
|
|
43
|
-
id: "nonNullableTypeAssertions",
|
|
44
|
-
presets: ["stylistic", "stylisticStrict"]
|
|
45
|
-
},
|
|
46
|
-
messages: { preferNonNullAssertion: {
|
|
47
|
-
primary: "Use a non-null assertion (`!`) instead of an explicit type assertion.",
|
|
48
|
-
secondary: ["When the only difference between the original and asserted type is nullability, a non-null assertion is more concise.", "Non-null assertions clearly communicate that you're asserting the value is not null or undefined."],
|
|
49
|
-
suggestions: ["Replace the type assertion with a `!` assertion."]
|
|
50
|
-
} },
|
|
51
|
-
setup(context) {
|
|
52
|
-
function checkNode(node, { sourceFile, typeChecker }) {
|
|
53
|
-
if (isConstAssertion(node, sourceFile)) return;
|
|
54
|
-
const originalTypes = getTypesIfNotLoose(node.expression, typeChecker);
|
|
55
|
-
if (!originalTypes) return;
|
|
56
|
-
const assertedTypes = getTypesIfNotLoose(node.type, typeChecker);
|
|
57
|
-
if (!assertedTypes || !sameTypeWithoutNullish(assertedTypes, originalTypes)) return;
|
|
58
|
-
const expressionText = node.expression.getText(sourceFile);
|
|
59
|
-
const replacement = needsParentheses(node.expression) ? `(${expressionText})!` : `${expressionText}!`;
|
|
60
|
-
context.report({
|
|
61
|
-
fix: {
|
|
62
|
-
range: getTSNodeRange(node, sourceFile),
|
|
63
|
-
text: replacement
|
|
64
|
-
},
|
|
65
|
-
message: "preferNonNullAssertion",
|
|
66
|
-
range: getTSNodeRange(node, sourceFile)
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return { visitors: {
|
|
70
|
-
AsExpression: checkNode,
|
|
71
|
-
TypeAssertionExpression: checkNode
|
|
72
|
-
} };
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
//#endregion
|
|
76
|
-
export { nonNullableTypeAssertions_default as default };
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=nonNullableTypeAssertions.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports non-octal decimal escape sequences (\\8 and \\9) in string literals.";
|
|
3
|
-
readonly id: "nonOctalDecimalEscapes";
|
|
4
|
-
readonly presets: readonly ["logical", "logicalStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "unexpectedEscape", undefined>;
|
|
9
|
-
export default _default;
|
|
10
|
-
//# sourceMappingURL=nonOctalDecimalEscapes.d.ts.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
3
|
-
//#region src/rules/nonOctalDecimalEscapes.ts
|
|
4
|
-
const nonOctalDecimalEscapePattern = /\\[89]/g;
|
|
5
|
-
var nonOctalDecimalEscapes_default = ruleCreator.createRule(typescriptLanguage, {
|
|
6
|
-
about: {
|
|
7
|
-
description: "Reports non-octal decimal escape sequences (\\8 and \\9) in string literals.",
|
|
8
|
-
id: "nonOctalDecimalEscapes",
|
|
9
|
-
presets: ["logical", "logicalStrict"]
|
|
10
|
-
},
|
|
11
|
-
messages: { unexpectedEscape: {
|
|
12
|
-
primary: "Non-octal decimal escape sequences (\\8 and \\9) should not be used in string literals.",
|
|
13
|
-
secondary: [
|
|
14
|
-
"Non-octal decimal escape sequences \\8 and \\9 are legacy features that are treated as identity escapes (the same as the literal digits).",
|
|
15
|
-
"They are optional in the ECMAScript specification and not supported in strict mode in all environments.",
|
|
16
|
-
"Use the literal digits directly instead."
|
|
17
|
-
],
|
|
18
|
-
suggestions: ["Remove the backslash to use the literal digit.", "If an escape sequence is needed, use a Unicode escape like \\u0038 or \\u0039."]
|
|
19
|
-
} },
|
|
20
|
-
setup(context) {
|
|
21
|
-
function checkNode(node, { sourceFile }) {
|
|
22
|
-
const text = node.getText(sourceFile);
|
|
23
|
-
const matches = [...text.matchAll(nonOctalDecimalEscapePattern)];
|
|
24
|
-
for (const match of matches) {
|
|
25
|
-
const matchIndex = match.index;
|
|
26
|
-
let backslashesBefore = 0;
|
|
27
|
-
for (let i = matchIndex - 1; i >= 0 && text[i] === "\\"; i--) backslashesBefore++;
|
|
28
|
-
if (backslashesBefore % 2 === 1) continue;
|
|
29
|
-
const start = node.getStart(sourceFile) + matchIndex;
|
|
30
|
-
context.report({
|
|
31
|
-
message: "unexpectedEscape",
|
|
32
|
-
range: {
|
|
33
|
-
begin: start,
|
|
34
|
-
end: start + match[0].length
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { visitors: {
|
|
40
|
-
NoSubstitutionTemplateLiteral: checkNode,
|
|
41
|
-
StringLiteral: checkNode
|
|
42
|
-
} };
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
//#endregion
|
|
46
|
-
export { nonOctalDecimalEscapes_default as default };
|
|
47
|
-
|
|
48
|
-
//# sourceMappingURL=nonOctalDecimalEscapes.js.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
3
|
-
readonly description: "Enforces consistent equality operator usage when comparing with null or undefined.";
|
|
4
|
-
readonly id: "nullishCheckStyle";
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "preferLooseNull" | "preferLooseNullish" | "preferLooseUndefined" | "preferStrictNullish", {
|
|
9
|
-
looseNullishComparisonStyle: z.ZodDefault<z.ZodEnum<{
|
|
10
|
-
"prefer-null": "prefer-null";
|
|
11
|
-
"prefer-undefined": "prefer-undefined";
|
|
12
|
-
ignore: "ignore";
|
|
13
|
-
}>>;
|
|
14
|
-
nullishComparisonStrictness: z.ZodDefault<z.ZodEnum<{
|
|
15
|
-
ignore: "ignore";
|
|
16
|
-
"double-equals": "double-equals";
|
|
17
|
-
"triple-equals": "triple-equals";
|
|
18
|
-
}>>;
|
|
19
|
-
}>;
|
|
20
|
-
export default _default;
|
|
21
|
-
//# sourceMappingURL=nullishCheckStyle.d.ts.map
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { isNullishLiteral, isUndefinedIdentifier, toEqualityOperator, toLooseOperator, toStrictOperator } from "./utils/equalityOperators.js";
|
|
3
|
-
import { getTSNodeRange, typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
4
|
-
import { isNullKeyword } from "ts-api-utils";
|
|
5
|
-
import { z } from "zod/v4";
|
|
6
|
-
//#region src/rules/nullishCheckStyle.ts
|
|
7
|
-
var nullishCheckStyle_default = ruleCreator.createRule(typescriptLanguage, {
|
|
8
|
-
about: {
|
|
9
|
-
description: "Enforces consistent equality operator usage when comparing with null or undefined.",
|
|
10
|
-
id: "nullishCheckStyle"
|
|
11
|
-
},
|
|
12
|
-
messages: {
|
|
13
|
-
preferLooseNull: {
|
|
14
|
-
primary: "Compare with 'null' rather than 'undefined'.",
|
|
15
|
-
secondary: ["`x == null` and `x == undefined` are equivalent to each other; both check `x === null || x === undefined`.", "Use `x == null` since it is shorter."],
|
|
16
|
-
suggestions: ["Replace 'undefined' with 'null'."]
|
|
17
|
-
},
|
|
18
|
-
preferLooseNullish: {
|
|
19
|
-
primary: "Use loose equality ('{{ looseOperator }}') for nullish comparisons.",
|
|
20
|
-
secondary: ["When checking for nullish values (null or undefined), loose equality is more concise.", "`x == null` checks for both null and undefined, equivalent to `x === null || x === undefined`."],
|
|
21
|
-
suggestions: ["Replace '{{ strictOperator }}' with '{{ looseOperator }}'."]
|
|
22
|
-
},
|
|
23
|
-
preferLooseUndefined: {
|
|
24
|
-
primary: "Compare with 'undefined' rather than 'null'.",
|
|
25
|
-
secondary: ["`x == null` and `x == undefined` are equivalent to each other; both check `x === null || x === undefined`.", "Use `x == undefined`."],
|
|
26
|
-
suggestions: ["Replace 'null' with 'undefined'."]
|
|
27
|
-
},
|
|
28
|
-
preferStrictNullish: {
|
|
29
|
-
primary: "Use strict equality ('{{ strictOperator }}') for nullish comparisons.",
|
|
30
|
-
secondary: ["When nullish comparison strictness is set to 'strict', use strict equality operators for nullish comparisons."],
|
|
31
|
-
suggestions: ["Replace '{{ looseOperator }}' with '{{ strictOperator }}'."]
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
options: {
|
|
35
|
-
looseNullishComparisonStyle: z.enum([
|
|
36
|
-
"prefer-null",
|
|
37
|
-
"prefer-undefined",
|
|
38
|
-
"ignore"
|
|
39
|
-
]).default("prefer-null"),
|
|
40
|
-
nullishComparisonStrictness: z.enum([
|
|
41
|
-
"double-equals",
|
|
42
|
-
"triple-equals",
|
|
43
|
-
"ignore"
|
|
44
|
-
]).default("double-equals")
|
|
45
|
-
},
|
|
46
|
-
setup(context) {
|
|
47
|
-
return { visitors: { BinaryExpression: (node, { options, sourceFile }) => {
|
|
48
|
-
const operator = toEqualityOperator(node.operatorToken.kind);
|
|
49
|
-
if (operator == null) return;
|
|
50
|
-
const leftIsNullish = isNullishLiteral(node.left);
|
|
51
|
-
if (leftIsNullish === isNullishLiteral(node.right)) return;
|
|
52
|
-
const isLooseComparison = operator === "==" || operator === "!=";
|
|
53
|
-
if (options.nullishComparisonStrictness === "double-equals" && !isLooseComparison) {
|
|
54
|
-
const looseOperator = toLooseOperator(operator);
|
|
55
|
-
const operatorRange = getTSNodeRange(node.operatorToken, sourceFile);
|
|
56
|
-
context.report({
|
|
57
|
-
data: {
|
|
58
|
-
looseOperator,
|
|
59
|
-
strictOperator: operator
|
|
60
|
-
},
|
|
61
|
-
message: "preferLooseNullish",
|
|
62
|
-
range: leftIsNullish ? {
|
|
63
|
-
begin: node.left.getStart(sourceFile),
|
|
64
|
-
end: operatorRange.end
|
|
65
|
-
} : {
|
|
66
|
-
begin: operatorRange.begin,
|
|
67
|
-
end: node.right.getEnd()
|
|
68
|
-
},
|
|
69
|
-
suggestions: [{
|
|
70
|
-
id: "useLooseOperator",
|
|
71
|
-
range: operatorRange,
|
|
72
|
-
text: looseOperator
|
|
73
|
-
}]
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (options.nullishComparisonStrictness === "triple-equals" && isLooseComparison) {
|
|
78
|
-
const strictOperator = toStrictOperator(operator);
|
|
79
|
-
const operatorRange = getTSNodeRange(node.operatorToken, sourceFile);
|
|
80
|
-
context.report({
|
|
81
|
-
data: {
|
|
82
|
-
looseOperator: operator,
|
|
83
|
-
strictOperator
|
|
84
|
-
},
|
|
85
|
-
message: "preferStrictNullish",
|
|
86
|
-
range: leftIsNullish ? {
|
|
87
|
-
begin: node.left.getStart(sourceFile),
|
|
88
|
-
end: operatorRange.end
|
|
89
|
-
} : {
|
|
90
|
-
begin: operatorRange.begin,
|
|
91
|
-
end: node.right.getEnd()
|
|
92
|
-
},
|
|
93
|
-
suggestions: [{
|
|
94
|
-
id: "useStrictOperator",
|
|
95
|
-
range: operatorRange,
|
|
96
|
-
text: strictOperator
|
|
97
|
-
}]
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (isLooseComparison) {
|
|
102
|
-
if (options.looseNullishComparisonStyle === "prefer-null") {
|
|
103
|
-
const leftIsUndefined = isUndefinedIdentifier(node.left);
|
|
104
|
-
const rightIsUndefined = isUndefinedIdentifier(node.right);
|
|
105
|
-
if (leftIsUndefined || rightIsUndefined) context.report({
|
|
106
|
-
fix: [{
|
|
107
|
-
range: getTSNodeRange(leftIsUndefined ? node.left : node.right, sourceFile),
|
|
108
|
-
text: "null"
|
|
109
|
-
}],
|
|
110
|
-
message: "preferLooseNull",
|
|
111
|
-
range: leftIsUndefined ? {
|
|
112
|
-
begin: node.left.getStart(sourceFile),
|
|
113
|
-
end: node.operatorToken.getEnd()
|
|
114
|
-
} : {
|
|
115
|
-
begin: node.operatorToken.getStart(sourceFile),
|
|
116
|
-
end: node.right.getEnd()
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} else if (options.looseNullishComparisonStyle === "prefer-undefined") {
|
|
120
|
-
const leftIsNull = isNullKeyword(node.left);
|
|
121
|
-
const rightIsNull = isNullKeyword(node.right);
|
|
122
|
-
if (leftIsNull || rightIsNull) context.report({
|
|
123
|
-
fix: [{
|
|
124
|
-
range: getTSNodeRange(leftIsNull ? node.left : node.right, sourceFile),
|
|
125
|
-
text: "undefined"
|
|
126
|
-
}],
|
|
127
|
-
message: "preferLooseUndefined",
|
|
128
|
-
range: leftIsNull ? {
|
|
129
|
-
begin: node.left.getStart(sourceFile),
|
|
130
|
-
end: node.operatorToken.getEnd()
|
|
131
|
-
} : {
|
|
132
|
-
begin: node.operatorToken.getStart(sourceFile),
|
|
133
|
-
end: node.right.getEnd()
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} } };
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
//#endregion
|
|
142
|
-
export { nullishCheckStyle_default as default };
|
|
143
|
-
|
|
144
|
-
//# sourceMappingURL=nullishCheckStyle.js.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
3
|
-
readonly description: "Prefer nullish coalescing operator (??) over logical OR (||) for nullish values.";
|
|
4
|
-
readonly id: "nullishCoalescingOperators";
|
|
5
|
-
readonly presets: readonly ["stylistic", "stylisticStrict"];
|
|
6
|
-
} & {
|
|
7
|
-
readonly pluginId: string;
|
|
8
|
-
readonly url: string;
|
|
9
|
-
}, "preferNullish" | "preferNullishAssignment" | "preferNullishTernary", {
|
|
10
|
-
ignoreConditionalTests: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
-
ignoreIfStatements: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
-
ignoreMixedLogicalExpressions: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
-
ignorePrimitives: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodRecord<z.ZodEnum<{
|
|
14
|
-
string: "string";
|
|
15
|
-
number: "number";
|
|
16
|
-
bigint: "bigint";
|
|
17
|
-
boolean: "boolean";
|
|
18
|
-
}>, z.ZodBoolean>]>>;
|
|
19
|
-
ignoreTernaryTests: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
-
}>;
|
|
21
|
-
export default _default;
|
|
22
|
-
//# sourceMappingURL=nullishCoalescingOperators.d.ts.map
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getTSNodeRange, hasSameTokens, typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
import * as tsutils from "ts-api-utils";
|
|
5
|
-
import { z } from "zod/v4";
|
|
6
|
-
//#region src/rules/nullishCoalescingOperators.ts
|
|
7
|
-
function analyzeConditionalForNullish(node, sourceFile) {
|
|
8
|
-
const { condition, whenFalse, whenTrue } = node;
|
|
9
|
-
if (ts.isIdentifier(condition) && ts.isIdentifier(whenTrue) && condition.text === whenTrue.text) return {
|
|
10
|
-
alternate: whenFalse,
|
|
11
|
-
consequent: whenTrue,
|
|
12
|
-
operator: "",
|
|
13
|
-
test: condition
|
|
14
|
-
};
|
|
15
|
-
if (ts.isPrefixUnaryExpression(condition) && condition.operator === ts.SyntaxKind.ExclamationToken) {
|
|
16
|
-
const operand = condition.operand;
|
|
17
|
-
if (ts.isIdentifier(operand) && ts.isIdentifier(whenFalse) && operand.text === whenFalse.text) return {
|
|
18
|
-
alternate: whenTrue,
|
|
19
|
-
consequent: whenFalse,
|
|
20
|
-
operator: "!",
|
|
21
|
-
test: operand
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
if (ts.isBinaryExpression(condition) && isNullLikeComparison(condition)) {
|
|
25
|
-
const { isNegation, value: testValue } = extractValueFromComparison(condition);
|
|
26
|
-
if (!testValue) return {};
|
|
27
|
-
const operator = getComparisonOperator(condition);
|
|
28
|
-
const [alternate, consequent] = isNegation ? [whenFalse, whenTrue] : [whenTrue, whenFalse];
|
|
29
|
-
if (!consequentMatchesTest(consequent, testValue, sourceFile)) return {};
|
|
30
|
-
return {
|
|
31
|
-
alternate,
|
|
32
|
-
consequent,
|
|
33
|
-
operator,
|
|
34
|
-
test: testValue
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (ts.isBinaryExpression(condition) && condition.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
38
|
-
const leftIsComparison = ts.isBinaryExpression(condition.left) ? isNullLikeComparison(condition.left) : false;
|
|
39
|
-
const rightIsComparison = ts.isBinaryExpression(condition.right) ? isNullLikeComparison(condition.right) : false;
|
|
40
|
-
if (leftIsComparison && rightIsComparison) {
|
|
41
|
-
const leftComp = condition.left;
|
|
42
|
-
const rightComp = condition.right;
|
|
43
|
-
const leftValue = extractValueFromComparison(leftComp).value;
|
|
44
|
-
const rightValue = extractValueFromComparison(rightComp).value;
|
|
45
|
-
if (leftValue && rightValue && hasSameTokens(leftValue, rightValue, sourceFile)) return {
|
|
46
|
-
alternate: whenFalse,
|
|
47
|
-
consequent: whenTrue,
|
|
48
|
-
operator: "===",
|
|
49
|
-
test: leftValue
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (ts.isBinaryExpression(condition) && condition.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
|
|
54
|
-
const leftIsComparison = ts.isBinaryExpression(condition.left) ? isNullLikeComparison(condition.left) : false;
|
|
55
|
-
const rightIsComparison = ts.isBinaryExpression(condition.right) ? isNullLikeComparison(condition.right) : false;
|
|
56
|
-
if (leftIsComparison && rightIsComparison) {
|
|
57
|
-
const leftComp = condition.left;
|
|
58
|
-
const rightComp = condition.right;
|
|
59
|
-
const leftValue = extractValueFromComparison(leftComp).value;
|
|
60
|
-
const rightValue = extractValueFromComparison(rightComp).value;
|
|
61
|
-
if (leftValue && rightValue && hasSameTokens(leftValue, rightValue, sourceFile)) return {
|
|
62
|
-
alternate: whenTrue,
|
|
63
|
-
consequent: whenFalse,
|
|
64
|
-
operator: "===",
|
|
65
|
-
test: leftValue
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {};
|
|
70
|
-
}
|
|
71
|
-
function consequentMatchesTest(consequent, test, sourceFile) {
|
|
72
|
-
if (hasSameTokens(consequent, test, sourceFile)) return true;
|
|
73
|
-
if (ts.isPropertyAccessExpression(consequent) || ts.isElementAccessExpression(consequent) || ts.isCallExpression(consequent)) return consequentMatchesTest(consequent.expression, test, sourceFile);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
function extractAssignmentFromIfStatement(node) {
|
|
77
|
-
let assignmentExpr;
|
|
78
|
-
if (ts.isBlock(node.thenStatement)) {
|
|
79
|
-
if (node.thenStatement.statements.length === 1) {
|
|
80
|
-
const stmt = node.thenStatement.statements[0];
|
|
81
|
-
if (stmt && ts.isExpressionStatement(stmt)) assignmentExpr = stmt.expression;
|
|
82
|
-
}
|
|
83
|
-
} else if (ts.isExpressionStatement(node.thenStatement)) assignmentExpr = node.thenStatement.expression;
|
|
84
|
-
if (!assignmentExpr || !ts.isBinaryExpression(assignmentExpr) || assignmentExpr.operatorToken.kind !== ts.SyntaxKind.EqualsToken) return;
|
|
85
|
-
return {
|
|
86
|
-
left: assignmentExpr.left,
|
|
87
|
-
right: assignmentExpr.right
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function extractValueFromComparison(node) {
|
|
91
|
-
const isNegation = node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken || node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken;
|
|
92
|
-
if (isNullLike(node.left)) return {
|
|
93
|
-
isNegation,
|
|
94
|
-
value: node.right
|
|
95
|
-
};
|
|
96
|
-
if (isNullLike(node.right)) return {
|
|
97
|
-
isNegation,
|
|
98
|
-
value: node.left
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
isNegation,
|
|
102
|
-
value: null
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function getComparisonOperator(node) {
|
|
106
|
-
switch (node.operatorToken.kind) {
|
|
107
|
-
case ts.SyntaxKind.EqualsEqualsEqualsToken: return "===";
|
|
108
|
-
case ts.SyntaxKind.EqualsEqualsToken: return "==";
|
|
109
|
-
case ts.SyntaxKind.ExclamationEqualsEqualsToken: return "!==";
|
|
110
|
-
case ts.SyntaxKind.ExclamationEqualsToken: return "!=";
|
|
111
|
-
default: return "";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function getIfStatementNullishCheckValue(node) {
|
|
115
|
-
switch (node.expression.kind) {
|
|
116
|
-
case ts.SyntaxKind.BinaryExpression:
|
|
117
|
-
if (isNullLikeComparison(node.expression)) return extractValueFromComparison(node.expression).value ?? void 0;
|
|
118
|
-
return;
|
|
119
|
-
case ts.SyntaxKind.PrefixUnaryExpression:
|
|
120
|
-
if (node.expression.operator === ts.SyntaxKind.ExclamationToken) return node.expression.operand;
|
|
121
|
-
return;
|
|
122
|
-
default: return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function getTypeFlags(type) {
|
|
126
|
-
let flags = 0;
|
|
127
|
-
for (const constituent of tsutils.unionConstituents(type)) for (const subConstituent of tsutils.intersectionConstituents(constituent)) flags |= subConstituent.getFlags();
|
|
128
|
-
return flags;
|
|
129
|
-
}
|
|
130
|
-
function isConditionalTest(node) {
|
|
131
|
-
switch (node.parent.kind) {
|
|
132
|
-
case ts.SyntaxKind.BinaryExpression:
|
|
133
|
-
if (node.parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken || node.parent.operatorToken.kind === ts.SyntaxKind.BarBarToken) return isConditionalTest(node.parent);
|
|
134
|
-
return false;
|
|
135
|
-
case ts.SyntaxKind.ConditionalExpression: return node.parent.condition === node || isConditionalTest(node.parent);
|
|
136
|
-
case ts.SyntaxKind.DoStatement:
|
|
137
|
-
case ts.SyntaxKind.IfStatement:
|
|
138
|
-
case ts.SyntaxKind.WhileStatement: return node.parent.expression === node;
|
|
139
|
-
case ts.SyntaxKind.ForStatement: return node.parent.condition === node;
|
|
140
|
-
case ts.SyntaxKind.PrefixUnaryExpression: return node.parent.operator === ts.SyntaxKind.ExclamationToken && isConditionalTest(node.parent);
|
|
141
|
-
default: return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function isFalsyLiteralType(part) {
|
|
145
|
-
if (part.isNumberLiteral() && part.value === 0) return true;
|
|
146
|
-
if (part.isStringLiteral() && part.value === "") return true;
|
|
147
|
-
const flags = part.getFlags();
|
|
148
|
-
if (flags & ts.TypeFlags.BooleanLiteral) {
|
|
149
|
-
if (part.intrinsicName === "false") return true;
|
|
150
|
-
}
|
|
151
|
-
if (flags & ts.TypeFlags.BigIntLiteral) {
|
|
152
|
-
const value = part.value;
|
|
153
|
-
if (!value.negative && value.base10Value === "0") return true;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
function isMixedLogicalExpression(node) {
|
|
158
|
-
const seen = /* @__PURE__ */ new Set();
|
|
159
|
-
const queue = [
|
|
160
|
-
node.parent,
|
|
161
|
-
node.left,
|
|
162
|
-
node.right
|
|
163
|
-
];
|
|
164
|
-
for (const current of queue) {
|
|
165
|
-
if (!seen.has(current)) continue;
|
|
166
|
-
seen.add(current);
|
|
167
|
-
if (ts.isBinaryExpression(current)) {
|
|
168
|
-
if (current.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) return true;
|
|
169
|
-
if (current.operatorToken.kind === ts.SyntaxKind.BarBarToken || current.operatorToken.kind === ts.SyntaxKind.BarBarEqualsToken) queue.push(current.parent, current.left, current.right);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
function isNullishType(type) {
|
|
175
|
-
return tsutils.isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined);
|
|
176
|
-
}
|
|
177
|
-
function isNullLike(node) {
|
|
178
|
-
switch (node.kind) {
|
|
179
|
-
case ts.SyntaxKind.Identifier: return node.text === "undefined";
|
|
180
|
-
case ts.SyntaxKind.NullKeyword: return true;
|
|
181
|
-
default: return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function isNullLikeComparison(node) {
|
|
185
|
-
return (node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsToken || node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken || node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsToken || node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken) && (isNullLike(node.left) || isNullLike(node.right));
|
|
186
|
-
}
|
|
187
|
-
function isTypeEligibleForPreferNullish(type, ignorePrimitives) {
|
|
188
|
-
if (!typeCanBeNullish(type) || tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown) || !ignorePrimitives) return true;
|
|
189
|
-
const ignorableFlags = [
|
|
190
|
-
(ignorePrimitives === true || typeof ignorePrimitives === "object" && ignorePrimitives.bigint) && ts.TypeFlags.BigIntLike,
|
|
191
|
-
(ignorePrimitives === true || typeof ignorePrimitives === "object" && ignorePrimitives.boolean) && ts.TypeFlags.BooleanLike,
|
|
192
|
-
(ignorePrimitives === true || typeof ignorePrimitives === "object" && ignorePrimitives.number) && ts.TypeFlags.NumberLike,
|
|
193
|
-
(ignorePrimitives === true || typeof ignorePrimitives === "object" && ignorePrimitives.string) && ts.TypeFlags.StringLike
|
|
194
|
-
].filter((flag) => typeof flag === "number").reduce((previous, flag) => previous | flag, 0);
|
|
195
|
-
return ignorableFlags === 0 || !(getTypeFlags(type) & ignorableFlags);
|
|
196
|
-
}
|
|
197
|
-
function shouldIgnoreNode(node, ignorePrimitives, typeChecker) {
|
|
198
|
-
const type = typeChecker.getTypeAtLocation(node);
|
|
199
|
-
return tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown) || !typeCanBeNullish(type) || typeHasNonNullishFalsyValues(type) || !isTypeEligibleForPreferNullish(type, ignorePrimitives);
|
|
200
|
-
}
|
|
201
|
-
function typeCanBeNullish(type) {
|
|
202
|
-
return tsutils.unionConstituents(type).some(isNullishType);
|
|
203
|
-
}
|
|
204
|
-
function typeHasNonNullishFalsyValues(type) {
|
|
205
|
-
return tsutils.unionConstituents(type).some((constituent) => isFalsyLiteralType(constituent) || constituent.getFlags() & (ts.TypeFlags.String | ts.TypeFlags.Number | ts.TypeFlags.BigInt | ts.TypeFlags.Boolean));
|
|
206
|
-
}
|
|
207
|
-
var nullishCoalescingOperators_default = ruleCreator.createRule(typescriptLanguage, {
|
|
208
|
-
about: {
|
|
209
|
-
description: "Prefer nullish coalescing operator (??) over logical OR (||) for nullish values.",
|
|
210
|
-
id: "nullishCoalescingOperators",
|
|
211
|
-
presets: ["stylistic", "stylisticStrict"]
|
|
212
|
-
},
|
|
213
|
-
messages: {
|
|
214
|
-
preferNullish: {
|
|
215
|
-
primary: "Prefer nullish coalescing operator (`??`) over logical OR (`||`) for nullish checks.",
|
|
216
|
-
secondary: ["The `||` operator returns the right operand for any falsy value (empty string, 0, false, null, undefined).", "The `??` operator only returns the right operand for null or undefined, preserving other falsy values."],
|
|
217
|
-
suggestions: ["Replace `||` with `??`."]
|
|
218
|
-
},
|
|
219
|
-
preferNullishAssignment: {
|
|
220
|
-
primary: "Prefer nullish coalescing assignment (`??=`) over assignment with null/undefined check.",
|
|
221
|
-
secondary: [],
|
|
222
|
-
suggestions: ["Replace with nullish coalescing assignment."]
|
|
223
|
-
},
|
|
224
|
-
preferNullishTernary: {
|
|
225
|
-
primary: "Prefer nullish coalescing operator (`??`) over ternary expression for nullish checks.",
|
|
226
|
-
secondary: [],
|
|
227
|
-
suggestions: ["Replace with nullish coalescing."]
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
options: {
|
|
231
|
-
ignoreConditionalTests: z.boolean().default(true).describe("Whether to skip cases where the expression is in a conditional context."),
|
|
232
|
-
ignoreIfStatements: z.boolean().default(false).describe("Whether to skip if statement patterns with nullish checks."),
|
|
233
|
-
ignoreMixedLogicalExpressions: z.boolean().default(false).describe("Whether to skip expressions that mix && and || operators."),
|
|
234
|
-
ignorePrimitives: z.union([z.boolean(), z.record(z.enum([
|
|
235
|
-
"bigint",
|
|
236
|
-
"boolean",
|
|
237
|
-
"number",
|
|
238
|
-
"string"
|
|
239
|
-
]), z.boolean())]).default({
|
|
240
|
-
bigint: false,
|
|
241
|
-
boolean: false,
|
|
242
|
-
number: false,
|
|
243
|
-
string: false
|
|
244
|
-
}).describe("Whether to skip primitive types. Can be a boolean or an object with per-type configuration."),
|
|
245
|
-
ignoreTernaryTests: z.boolean().default(false).describe("Whether to skip ternary expressions.")
|
|
246
|
-
},
|
|
247
|
-
setup(context) {
|
|
248
|
-
function getOptionalChainInsertPosition(node, test, sourceFile) {
|
|
249
|
-
if (node.kind === ts.SyntaxKind.PropertyAccessExpression || node.kind === ts.SyntaxKind.ElementAccessExpression) {
|
|
250
|
-
if (hasSameTokens(node.expression, test, sourceFile)) return {
|
|
251
|
-
needsDot: ts.isElementAccessExpression(node),
|
|
252
|
-
pos: node.expression.getEnd()
|
|
253
|
-
};
|
|
254
|
-
return getOptionalChainInsertPosition(node.expression, test, sourceFile);
|
|
255
|
-
}
|
|
256
|
-
if (ts.isCallExpression(node)) return getOptionalChainInsertPosition(node.expression, test, sourceFile);
|
|
257
|
-
}
|
|
258
|
-
function createNullishNodesFix(consequent, alternate, sourceFile, range, test) {
|
|
259
|
-
const getText = (node) => sourceFile.text.substring(node.getStart(sourceFile), node.getEnd());
|
|
260
|
-
let leftText = getText(consequent);
|
|
261
|
-
if (test && test !== consequent) {
|
|
262
|
-
const insert = getOptionalChainInsertPosition(consequent, test, sourceFile);
|
|
263
|
-
if (insert) {
|
|
264
|
-
const offset = insert.pos - consequent.getStart(sourceFile);
|
|
265
|
-
leftText = leftText.slice(0, offset) + (insert.needsDot ? "?." : "?") + leftText.slice(offset);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
range,
|
|
270
|
-
text: `${leftText} ?? ${getText(alternate)}`
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
function createNullishAssignmentFix(left, right, sourceFile, range) {
|
|
274
|
-
const getText = (node) => sourceFile.text.substring(node.getStart(sourceFile), node.getEnd());
|
|
275
|
-
return {
|
|
276
|
-
range,
|
|
277
|
-
text: `${getText(left)} ??= ${getText(right)};`
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
return { visitors: {
|
|
281
|
-
BinaryExpression: (node, { options, sourceFile, typeChecker }) => {
|
|
282
|
-
if (options.ignoreConditionalTests && isConditionalTest(node) || options.ignoreMixedLogicalExpressions && isMixedLogicalExpression(node) || ![ts.SyntaxKind.BarBarEqualsToken, ts.SyntaxKind.BarBarToken].includes(node.operatorToken.kind) || shouldIgnoreNode(node.left, options.ignorePrimitives, typeChecker)) return;
|
|
283
|
-
const range = getTSNodeRange(node.operatorToken, sourceFile);
|
|
284
|
-
const fullRange = getTSNodeRange(node, sourceFile);
|
|
285
|
-
context.report({
|
|
286
|
-
fix: {
|
|
287
|
-
range,
|
|
288
|
-
text: node.operatorToken.kind === ts.SyntaxKind.BarBarToken ? "??" : "??="
|
|
289
|
-
},
|
|
290
|
-
message: "preferNullish",
|
|
291
|
-
range: fullRange
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
ConditionalExpression: (node, { options, sourceFile, typeChecker }) => {
|
|
295
|
-
if (options.ignoreTernaryTests || options.ignoreConditionalTests && isConditionalTest(node)) return;
|
|
296
|
-
const { alternate, consequent, test } = analyzeConditionalForNullish(node, sourceFile);
|
|
297
|
-
if (!test || !consequent || !alternate || shouldIgnoreNode(test, options.ignorePrimitives, typeChecker)) return;
|
|
298
|
-
const range = getTSNodeRange(node, sourceFile);
|
|
299
|
-
context.report({
|
|
300
|
-
fix: createNullishNodesFix(consequent, alternate, sourceFile, range, test),
|
|
301
|
-
message: "preferNullishTernary",
|
|
302
|
-
range
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
IfStatement: (node, { options, sourceFile, typeChecker }) => {
|
|
306
|
-
const checkedValue = getIfStatementNullishCheckValue(node);
|
|
307
|
-
if (options.ignoreIfStatements || node.elseStatement || !checkedValue) return;
|
|
308
|
-
const assignmentExpression = extractAssignmentFromIfStatement(node);
|
|
309
|
-
if (!assignmentExpression || !hasSameTokens(assignmentExpression.left, checkedValue, sourceFile) || shouldIgnoreNode(assignmentExpression.left, options.ignorePrimitives, typeChecker)) return;
|
|
310
|
-
const range = getTSNodeRange(node, sourceFile);
|
|
311
|
-
context.report({
|
|
312
|
-
fix: createNullishAssignmentFix(assignmentExpression.left, assignmentExpression.right, sourceFile, range),
|
|
313
|
-
message: "preferNullishAssignment",
|
|
314
|
-
range
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
} };
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
//#endregion
|
|
321
|
-
export { nullishCoalescingOperators_default as default };
|
|
322
|
-
|
|
323
|
-
//# sourceMappingURL=nullishCoalescingOperators.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports when number method arguments are outside their valid range.";
|
|
3
|
-
readonly id: "numberMethodRanges";
|
|
4
|
-
readonly presets: readonly ["logical", "logicalStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "outOfRange", undefined>;
|
|
9
|
-
export default _default;
|
|
10
|
-
//# sourceMappingURL=numberMethodRanges.d.ts.map
|