@flint.fyi/ts 0.21.0 → 0.23.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} +1 -1
- package/dist/index.mjs +22468 -0
- package/package.json +9 -8
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/plugin.js +0 -619
- package/lib/rules/accessorPairGroups.d.ts +0 -9
- package/lib/rules/accessorPairGroups.js +0 -46
- package/lib/rules/accessorPairTypes.d.ts +0 -9
- package/lib/rules/accessorPairTypes.js +0 -70
- package/lib/rules/accessorThisRecursion.d.ts +0 -9
- package/lib/rules/accessorThisRecursion.js +0 -63
- package/lib/rules/anyArguments.d.ts +0 -9
- package/lib/rules/anyArguments.js +0 -232
- package/lib/rules/anyAssignments.d.ts +0 -9
- package/lib/rules/anyAssignments.js +0 -263
- package/lib/rules/anyCalls.d.ts +0 -9
- package/lib/rules/anyCalls.js +0 -66
- package/lib/rules/anyMemberAccess.d.ts +0 -9
- package/lib/rules/anyMemberAccess.js +0 -83
- package/lib/rules/anyReturns.d.ts +0 -9
- package/lib/rules/anyReturns.js +0 -100
- package/lib/rules/arguments.d.ts +0 -9
- package/lib/rules/arguments.js +0 -36
- package/lib/rules/arrayCallbackReturns.d.ts +0 -9
- package/lib/rules/arrayCallbackReturns.js +0 -71
- package/lib/rules/arrayConstructors.d.ts +0 -9
- package/lib/rules/arrayConstructors.js +0 -45
- package/lib/rules/arrayDeleteUnnecessaryCounts.d.ts +0 -9
- package/lib/rules/arrayDeleteUnnecessaryCounts.js +0 -52
- package/lib/rules/arrayElementDeletions.d.ts +0 -9
- package/lib/rules/arrayElementDeletions.js +0 -41
- package/lib/rules/arrayEmptyCallbackSlots.d.ts +0 -9
- package/lib/rules/arrayEmptyCallbackSlots.js +0 -38
- package/lib/rules/arrayExistenceChecksConsistency.d.ts +0 -9
- package/lib/rules/arrayExistenceChecksConsistency.js +0 -84
- package/lib/rules/arrayFilteredFinds.d.ts +0 -9
- package/lib/rules/arrayFilteredFinds.js +0 -72
- package/lib/rules/arrayFinds.d.ts +0 -9
- package/lib/rules/arrayFinds.js +0 -39
- package/lib/rules/arrayFlatMapMethods.d.ts +0 -9
- package/lib/rules/arrayFlatMapMethods.js +0 -45
- package/lib/rules/arrayFlatMethods.d.ts +0 -9
- package/lib/rules/arrayFlatMethods.js +0 -81
- package/lib/rules/arrayFlatUnnecessaryDepths.d.ts +0 -9
- package/lib/rules/arrayFlatUnnecessaryDepths.js +0 -31
- package/lib/rules/arrayIncludes.d.ts +0 -9
- package/lib/rules/arrayIncludes.js +0 -51
- package/lib/rules/arrayIncludesMethods.d.ts +0 -9
- package/lib/rules/arrayIncludesMethods.js +0 -35
- package/lib/rules/arrayIndexOfMethods.d.ts +0 -9
- package/lib/rules/arrayIndexOfMethods.js +0 -49
- package/lib/rules/arrayLoops.d.ts +0 -9
- package/lib/rules/arrayLoops.js +0 -34
- package/lib/rules/arrayMapIdentities.d.ts +0 -9
- package/lib/rules/arrayMapIdentities.js +0 -72
- package/lib/rules/arrayMutableReverses.d.ts +0 -9
- package/lib/rules/arrayMutableReverses.js +0 -37
- package/lib/rules/arrayMutableSorts.d.ts +0 -9
- package/lib/rules/arrayMutableSorts.js +0 -70
- package/lib/rules/arrayReduceTypeArguments.d.ts +0 -9
- package/lib/rules/arrayReduceTypeArguments.js +0 -62
- package/lib/rules/arraySliceUnnecessaryEnd.d.ts +0 -9
- package/lib/rules/arraySliceUnnecessaryEnd.js +0 -49
- package/lib/rules/arraySomeMethods.d.ts +0 -9
- package/lib/rules/arraySomeMethods.js +0 -75
- package/lib/rules/arrayTernarySpreadingConsistency.d.ts +0 -9
- package/lib/rules/arrayTernarySpreadingConsistency.js +0 -72
- package/lib/rules/arrayTypes.d.ts +0 -16
- package/lib/rules/arrayTypes.js +0 -109
- package/lib/rules/arrayUnnecessaryLengthChecks.d.ts +0 -9
- package/lib/rules/arrayUnnecessaryLengthChecks.js +0 -95
- package/lib/rules/asConstAssertions.d.ts +0 -9
- package/lib/rules/asConstAssertions.js +0 -55
- package/lib/rules/assignmentOperatorShorthands.d.ts +0 -9
- package/lib/rules/assignmentOperatorShorthands.js +0 -45
- package/lib/rules/asyncFunctionAwaits.d.ts +0 -9
- package/lib/rules/asyncFunctionAwaits.js +0 -53
- package/lib/rules/asyncPromiseExecutors.d.ts +0 -9
- package/lib/rules/asyncPromiseExecutors.js +0 -39
- package/lib/rules/asyncUnnecessaryPromiseWrappers.d.ts +0 -9
- package/lib/rules/asyncUnnecessaryPromiseWrappers.js +0 -50
- package/lib/rules/atAccesses.d.ts +0 -9
- package/lib/rules/atAccesses.js +0 -50
- package/lib/rules/builtinCoercions.d.ts +0 -9
- package/lib/rules/builtinCoercions.js +0 -115
- package/lib/rules/builtinConstructorNews.d.ts +0 -9
- package/lib/rules/builtinConstructorNews.js +0 -87
- package/lib/rules/caseDeclarations.d.ts +0 -9
- package/lib/rules/caseDeclarations.js +0 -38
- package/lib/rules/caseDuplicates.d.ts +0 -9
- package/lib/rules/caseDuplicates.js +0 -34
- package/lib/rules/caseFallthroughs.d.ts +0 -9
- package/lib/rules/caseFallthroughs.js +0 -74
- package/lib/rules/catchCallbackTypes.d.ts +0 -9
- package/lib/rules/catchCallbackTypes.js +0 -65
- package/lib/rules/caughtVariableNames.d.ts +0 -9
- package/lib/rules/caughtVariableNames.js +0 -38
- package/lib/rules/chainedAssignments.d.ts +0 -9
- package/lib/rules/chainedAssignments.js +0 -31
- package/lib/rules/charAtComparisons.d.ts +0 -9
- package/lib/rules/charAtComparisons.js +0 -53
- package/lib/rules/classAssignments.d.ts +0 -9
- package/lib/rules/classAssignments.js +0 -27
- package/lib/rules/classFieldDeclarations.d.ts +0 -9
- package/lib/rules/classFieldDeclarations.js +0 -38
- package/lib/rules/classLiteralProperties.d.ts +0 -9
- package/lib/rules/classLiteralProperties.js +0 -43
- package/lib/rules/classMemberDuplicates.d.ts +0 -9
- package/lib/rules/classMemberDuplicates.js +0 -69
- package/lib/rules/classMethodsThis.d.ts +0 -13
- package/lib/rules/classMethodsThis.js +0 -122
- package/lib/rules/combinedPushes.d.ts +0 -9
- package/lib/rules/combinedPushes.js +0 -54
- package/lib/rules/consecutiveNonNullAssertions.d.ts +0 -9
- package/lib/rules/consecutiveNonNullAssertions.js +0 -37
- package/lib/rules/consoleCalls.d.ts +0 -8
- package/lib/rules/consoleCalls.js +0 -26
- package/lib/rules/constantAssignments.d.ts +0 -9
- package/lib/rules/constantAssignments.js +0 -39
- package/lib/rules/constructorGenericCalls.d.ts +0 -15
- package/lib/rules/constructorGenericCalls.js +0 -136
- package/lib/rules/constructorReturns.d.ts +0 -9
- package/lib/rules/constructorReturns.js +0 -39
- package/lib/rules/constructorSupers.d.ts +0 -9
- package/lib/rules/constructorSupers.js +0 -75
- package/lib/rules/dateConstructorClones.d.ts +0 -9
- package/lib/rules/dateConstructorClones.js +0 -35
- package/lib/rules/dateNowTimestamps.d.ts +0 -9
- package/lib/rules/dateNowTimestamps.js +0 -55
- package/lib/rules/debuggerStatements.d.ts +0 -9
- package/lib/rules/debuggerStatements.js +0 -31
- package/lib/rules/defaultCaseLast.d.ts +0 -9
- package/lib/rules/defaultCaseLast.js +0 -34
- package/lib/rules/defaultParameterLast.d.ts +0 -9
- package/lib/rules/defaultParameterLast.js +0 -40
- package/lib/rules/deprecated.d.ts +0 -9
- package/lib/rules/deprecated.js +0 -241
- package/lib/rules/destructuringConsistency.d.ts +0 -9
- package/lib/rules/destructuringConsistency.js +0 -104
- package/lib/rules/duplicateArguments.d.ts +0 -9
- package/lib/rules/duplicateArguments.js +0 -43
- package/lib/rules/dynamicDeletes.d.ts +0 -9
- package/lib/rules/dynamicDeletes.js +0 -35
- package/lib/rules/elseIfDuplicates.d.ts +0 -9
- package/lib/rules/elseIfDuplicates.js +0 -36
- package/lib/rules/elseReturns.d.ts +0 -9
- package/lib/rules/elseReturns.js +0 -65
- package/lib/rules/emptyBlocks.d.ts +0 -9
- package/lib/rules/emptyBlocks.js +0 -54
- package/lib/rules/emptyDestructures.d.ts +0 -9
- package/lib/rules/emptyDestructures.js +0 -32
- package/lib/rules/emptyEnums.d.ts +0 -9
- package/lib/rules/emptyEnums.js +0 -28
- package/lib/rules/emptyExports.d.ts +0 -9
- package/lib/rules/emptyExports.js +0 -58
- package/lib/rules/emptyFiles.d.ts +0 -9
- package/lib/rules/emptyFiles.js +0 -42
- package/lib/rules/emptyFunctions.d.ts +0 -9
- package/lib/rules/emptyFunctions.js +0 -59
- package/lib/rules/emptyModuleAttributes.d.ts +0 -9
- package/lib/rules/emptyModuleAttributes.js +0 -33
- package/lib/rules/emptyObjectTypes.d.ts +0 -9
- package/lib/rules/emptyObjectTypes.js +0 -45
- package/lib/rules/emptyStaticBlocks.d.ts +0 -9
- package/lib/rules/emptyStaticBlocks.js +0 -40
- package/lib/rules/emptyTypeParameterLists.d.ts +0 -9
- package/lib/rules/emptyTypeParameterLists.js +0 -29
- package/lib/rules/enumInitializers.d.ts +0 -9
- package/lib/rules/enumInitializers.js +0 -52
- package/lib/rules/enumMemberLiterals.d.ts +0 -9
- package/lib/rules/enumMemberLiterals.js +0 -37
- package/lib/rules/enumValueConsistency.d.ts +0 -9
- package/lib/rules/enumValueConsistency.js +0 -54
- package/lib/rules/enumValueDuplicates.d.ts +0 -9
- package/lib/rules/enumValueDuplicates.js +0 -43
- package/lib/rules/equalityOperatorNegations.d.ts +0 -8
- package/lib/rules/equalityOperatorNegations.js +0 -58
- package/lib/rules/equalityOperators.d.ts +0 -9
- package/lib/rules/equalityOperators.js +0 -42
- package/lib/rules/errorMessages.d.ts +0 -9
- package/lib/rules/errorMessages.js +0 -54
- package/lib/rules/errorSubclassProperties.d.ts +0 -9
- package/lib/rules/errorSubclassProperties.js +0 -142
- package/lib/rules/errorUnnecessaryCaptureStackTraces.d.ts +0 -9
- package/lib/rules/errorUnnecessaryCaptureStackTraces.js +0 -53
- package/lib/rules/escapeSequenceCasing.d.ts +0 -9
- package/lib/rules/escapeSequenceCasing.js +0 -73
- package/lib/rules/evals.d.ts +0 -9
- package/lib/rules/evals.js +0 -29
- package/lib/rules/evolvingVariableTypes.d.ts +0 -9
- package/lib/rules/evolvingVariableTypes.js +0 -31
- package/lib/rules/exceptionAssignments.d.ts +0 -9
- package/lib/rules/exceptionAssignments.js +0 -37
- package/lib/rules/explicitAnys.d.ts +0 -9
- package/lib/rules/explicitAnys.js +0 -53
- package/lib/rules/exponentiationOperators.d.ts +0 -9
- package/lib/rules/exponentiationOperators.js +0 -32
- package/lib/rules/exportFromImports.d.ts +0 -9
- package/lib/rules/exportFromImports.js +0 -117
- package/lib/rules/exportMutables.d.ts +0 -9
- package/lib/rules/exportMutables.js +0 -31
- package/lib/rules/exportUniqueNames.d.ts +0 -9
- package/lib/rules/exportUniqueNames.js +0 -63
- package/lib/rules/extraneousClasses.d.ts +0 -15
- package/lib/rules/extraneousClasses.js +0 -109
- package/lib/rules/fetchMethodBodies.d.ts +0 -9
- package/lib/rules/fetchMethodBodies.js +0 -70
- package/lib/rules/finallyStatementSafety.d.ts +0 -9
- package/lib/rules/finallyStatementSafety.js +0 -45
- package/lib/rules/forDirections.d.ts +0 -9
- package/lib/rules/forDirections.js +0 -73
- package/lib/rules/forInArrays.d.ts +0 -9
- package/lib/rules/forInArrays.js +0 -44
- package/lib/rules/forInGuards.d.ts +0 -8
- package/lib/rules/forInGuards.js +0 -42
- package/lib/rules/functionApplySpreads.d.ts +0 -9
- package/lib/rules/functionApplySpreads.js +0 -61
- package/lib/rules/functionAssignments.d.ts +0 -9
- package/lib/rules/functionAssignments.js +0 -27
- package/lib/rules/functionCurryingRedundancy.d.ts +0 -9
- package/lib/rules/functionCurryingRedundancy.js +0 -51
- package/lib/rules/functionDeclarationStyles.d.ts +0 -15
- package/lib/rules/functionDeclarationStyles.js +0 -65
- package/lib/rules/functionNameMatches.d.ts +0 -9
- package/lib/rules/functionNameMatches.js +0 -72
- package/lib/rules/functionNewCalls.d.ts +0 -9
- package/lib/rules/functionNewCalls.js +0 -40
- package/lib/rules/generatorFunctionYields.d.ts +0 -9
- package/lib/rules/generatorFunctionYields.js +0 -48
- package/lib/rules/getterReturns.d.ts +0 -9
- package/lib/rules/getterReturns.js +0 -63
- package/lib/rules/globalAssignments.d.ts +0 -9
- package/lib/rules/globalAssignments.js +0 -45
- package/lib/rules/globalObjectCalls.d.ts +0 -9
- package/lib/rules/globalObjectCalls.js +0 -40
- package/lib/rules/globalThisAliases.d.ts +0 -9
- package/lib/rules/globalThisAliases.js +0 -45
- package/lib/rules/impliedEvals.d.ts +0 -9
- package/lib/rules/impliedEvals.js +0 -128
- package/lib/rules/importEmptyBlocks.d.ts +0 -9
- package/lib/rules/importEmptyBlocks.js +0 -51
- package/lib/rules/importTypeSideEffects.d.ts +0 -9
- package/lib/rules/importTypeSideEffects.js +0 -29
- package/lib/rules/indexedObjectTypes.d.ts +0 -15
- package/lib/rules/indexedObjectTypes.js +0 -81
- package/lib/rules/instanceOfArrays.d.ts +0 -9
- package/lib/rules/instanceOfArrays.js +0 -29
- package/lib/rules/irregularWhitespaces.d.ts +0 -15
- package/lib/rules/irregularWhitespaces.js +0 -95
- package/lib/rules/isNaNComparisons.d.ts +0 -9
- package/lib/rules/isNaNComparisons.js +0 -41
- package/lib/rules/literalConstructorWrappers.d.ts +0 -9
- package/lib/rules/literalConstructorWrappers.js +0 -62
- package/lib/rules/mathMethods.d.ts +0 -9
- package/lib/rules/mathMethods.js +0 -126
- package/lib/rules/meaninglessVoidOperators.d.ts +0 -9
- package/lib/rules/meaninglessVoidOperators.js +0 -37
- package/lib/rules/misleadingVoidExpressions.d.ts +0 -9
- package/lib/rules/misleadingVoidExpressions.js +0 -126
- package/lib/rules/moduleSpecifierLists.d.ts +0 -9
- package/lib/rules/moduleSpecifierLists.js +0 -90
- package/lib/rules/multilineAmbiguities.d.ts +0 -9
- package/lib/rules/multilineAmbiguities.js +0 -62
- package/lib/rules/namedDefaultExports.d.ts +0 -9
- package/lib/rules/namedDefaultExports.js +0 -58
- package/lib/rules/namespaceDeclarations.d.ts +0 -13
- package/lib/rules/namespaceDeclarations.js +0 -35
- package/lib/rules/namespaceImplicitAmbientImports.d.ts +0 -9
- package/lib/rules/namespaceImplicitAmbientImports.js +0 -38
- package/lib/rules/namespaceKeywords.d.ts +0 -9
- package/lib/rules/namespaceKeywords.js +0 -38
- package/lib/rules/nativeObjectExtensions.d.ts +0 -9
- package/lib/rules/nativeObjectExtensions.js +0 -112
- package/lib/rules/negativeIndexLengthMethods.d.ts +0 -9
- package/lib/rules/negativeIndexLengthMethods.js +0 -178
- package/lib/rules/negativeZeroComparisons.d.ts +0 -9
- package/lib/rules/negativeZeroComparisons.js +0 -46
- package/lib/rules/nestedStandaloneIfs.d.ts +0 -9
- package/lib/rules/nestedStandaloneIfs.js +0 -103
- package/lib/rules/newDefinitions.d.ts +0 -9
- package/lib/rules/newDefinitions.js +0 -82
- package/lib/rules/newExpressions.d.ts +0 -9
- package/lib/rules/newExpressions.js +0 -36
- package/lib/rules/newNativeNonConstructors.d.ts +0 -9
- package/lib/rules/newNativeNonConstructors.js +0 -37
- package/lib/rules/nonNullAssertedNullishCoalesces.d.ts +0 -9
- package/lib/rules/nonNullAssertedNullishCoalesces.js +0 -61
- package/lib/rules/nonNullAssertedOptionalChains.d.ts +0 -9
- package/lib/rules/nonNullAssertedOptionalChains.js +0 -67
- package/lib/rules/nonNullAssertionPlacement.d.ts +0 -9
- package/lib/rules/nonNullAssertionPlacement.js +0 -92
- package/lib/rules/nonNullableTypeAssertions.d.ts +0 -9
- package/lib/rules/nonNullableTypeAssertions.js +0 -76
- package/lib/rules/nonOctalDecimalEscapes.d.ts +0 -9
- package/lib/rules/nonOctalDecimalEscapes.js +0 -46
- package/lib/rules/nullishCheckStyle.d.ts +0 -20
- package/lib/rules/nullishCheckStyle.js +0 -142
- package/lib/rules/nullishCoalescingOperators.d.ts +0 -21
- package/lib/rules/nullishCoalescingOperators.js +0 -321
- package/lib/rules/numberMethodRanges.d.ts +0 -9
- package/lib/rules/numberMethodRanges.js +0 -72
- package/lib/rules/numberStaticMethods.d.ts +0 -9
- package/lib/rules/numberStaticMethods.js +0 -51
- package/lib/rules/numericErasingOperations.d.ts +0 -9
- package/lib/rules/numericErasingOperations.js +0 -44
- package/lib/rules/numericLiteralParsing.d.ts +0 -9
- package/lib/rules/numericLiteralParsing.js +0 -55
- package/lib/rules/numericPrecision.d.ts +0 -9
- package/lib/rules/numericPrecision.js +0 -100
- package/lib/rules/numericSeparatorGroups.d.ts +0 -9
- package/lib/rules/numericSeparatorGroups.js +0 -99
- package/lib/rules/objectAssignSpreads.d.ts +0 -9
- package/lib/rules/objectAssignSpreads.js +0 -51
- package/lib/rules/objectCalls.d.ts +0 -9
- package/lib/rules/objectCalls.js +0 -36
- package/lib/rules/objectEntriesMethods.d.ts +0 -9
- package/lib/rules/objectEntriesMethods.js +0 -80
- package/lib/rules/objectHasOwns.d.ts +0 -9
- package/lib/rules/objectHasOwns.js +0 -48
- package/lib/rules/objectKeyDuplicates.d.ts +0 -9
- package/lib/rules/objectKeyDuplicates.js +0 -61
- package/lib/rules/objectProto.d.ts +0 -9
- package/lib/rules/objectProto.js +0 -48
- package/lib/rules/objectPrototypeBuiltIns.d.ts +0 -9
- package/lib/rules/objectPrototypeBuiltIns.js +0 -52
- package/lib/rules/objectShorthand.d.ts +0 -9
- package/lib/rules/objectShorthand.js +0 -82
- package/lib/rules/objectSpreadUnnecessaryFallbacks.d.ts +0 -9
- package/lib/rules/objectSpreadUnnecessaryFallbacks.js +0 -41
- package/lib/rules/objectTypeDefinitions.d.ts +0 -9
- package/lib/rules/objectTypeDefinitions.js +0 -32
- package/lib/rules/octalEscapes.d.ts +0 -9
- package/lib/rules/octalEscapes.js +0 -56
- package/lib/rules/octalNumbers.d.ts +0 -9
- package/lib/rules/octalNumbers.js +0 -53
- package/lib/rules/operatorAssignmentShorthand.d.ts +0 -9
- package/lib/rules/operatorAssignmentShorthand.js +0 -75
- package/lib/rules/overloadSignaturesAdjacent.d.ts +0 -9
- package/lib/rules/overloadSignaturesAdjacent.js +0 -138
- package/lib/rules/parameterReassignments.d.ts +0 -9
- package/lib/rules/parameterReassignments.js +0 -43
- package/lib/rules/parseIntRadixes.d.ts +0 -9
- package/lib/rules/parseIntRadixes.js +0 -57
- package/lib/rules/propertyAccessNotation.d.ts +0 -12
- package/lib/rules/propertyAccessNotation.js +0 -117
- package/lib/rules/recursionOnlyArguments.d.ts +0 -9
- package/lib/rules/recursionOnlyArguments.js +0 -62
- package/lib/rules/redundantTypeConstituents.d.ts +0 -9
- package/lib/rules/redundantTypeConstituents.js +0 -275
- package/lib/rules/regexAllGlobalFlags.d.ts +0 -9
- package/lib/rules/regexAllGlobalFlags.js +0 -54
- package/lib/rules/regexAmbiguousInvalidity.d.ts +0 -9
- package/lib/rules/regexAmbiguousInvalidity.js +0 -295
- package/lib/rules/regexCharacterClassRanges.d.ts +0 -9
- package/lib/rules/regexCharacterClassRanges.js +0 -135
- package/lib/rules/regexCharacterClassSetOperations.d.ts +0 -9
- package/lib/rules/regexCharacterClassSetOperations.js +0 -79
- package/lib/rules/regexCharacterClasses.d.ts +0 -9
- package/lib/rules/regexCharacterClasses.js +0 -232
- package/lib/rules/regexConciseCharacterClassNegations.d.ts +0 -9
- package/lib/rules/regexConciseCharacterClassNegations.js +0 -50
- package/lib/rules/regexContradictoryAssertions.d.ts +0 -9
- package/lib/rules/regexContradictoryAssertions.js +0 -208
- package/lib/rules/regexControlCharacterEscapes.d.ts +0 -9
- package/lib/rules/regexControlCharacterEscapes.js +0 -128
- package/lib/rules/regexControlCharacters.d.ts +0 -9
- package/lib/rules/regexControlCharacters.js +0 -93
- package/lib/rules/regexDigitMatchers.d.ts +0 -9
- package/lib/rules/regexDigitMatchers.js +0 -178
- package/lib/rules/regexDollarEscapes.d.ts +0 -9
- package/lib/rules/regexDollarEscapes.js +0 -89
- package/lib/rules/regexDuplicateCharacterClassCharacters.d.ts +0 -9
- package/lib/rules/regexDuplicateCharacterClassCharacters.js +0 -126
- package/lib/rules/regexEmptyAlternatives.d.ts +0 -9
- package/lib/rules/regexEmptyAlternatives.js +0 -138
- package/lib/rules/regexEmptyCapturingGroups.d.ts +0 -9
- package/lib/rules/regexEmptyCapturingGroups.js +0 -65
- package/lib/rules/regexEmptyCharacterClasses.d.ts +0 -9
- package/lib/rules/regexEmptyCharacterClasses.js +0 -66
- package/lib/rules/regexEmptyGroups.d.ts +0 -9
- package/lib/rules/regexEmptyGroups.js +0 -64
- package/lib/rules/regexEmptyLazyQuantifiers.d.ts +0 -9
- package/lib/rules/regexEmptyLazyQuantifiers.js +0 -90
- package/lib/rules/regexEmptyLookaroundsAssertions.d.ts +0 -9
- package/lib/rules/regexEmptyLookaroundsAssertions.js +0 -66
- package/lib/rules/regexEmptyStringLiterals.d.ts +0 -9
- package/lib/rules/regexEmptyStringLiterals.js +0 -64
- package/lib/rules/regexEscapeBackspaces.d.ts +0 -9
- package/lib/rules/regexEscapeBackspaces.js +0 -67
- package/lib/rules/regexExecutors.d.ts +0 -9
- package/lib/rules/regexExecutors.js +0 -56
- package/lib/rules/regexGraphemeStringLiterals.d.ts +0 -9
- package/lib/rules/regexGraphemeStringLiterals.js +0 -49
- package/lib/rules/regexHexadecimalEscapes.d.ts +0 -9
- package/lib/rules/regexHexadecimalEscapes.js +0 -69
- package/lib/rules/regexIgnoreCaseFlags.d.ts +0 -9
- package/lib/rules/regexIgnoreCaseFlags.js +0 -143
- package/lib/rules/regexInvisibleCharacters.d.ts +0 -9
- package/lib/rules/regexInvisibleCharacters.js +0 -88
- package/lib/rules/regexLetterCasing.d.ts +0 -9
- package/lib/rules/regexLetterCasing.js +0 -184
- package/lib/rules/regexLiterals.d.ts +0 -9
- package/lib/rules/regexLiterals.js +0 -87
- package/lib/rules/regexLookaroundAssertions.d.ts +0 -9
- package/lib/rules/regexLookaroundAssertions.js +0 -161
- package/lib/rules/regexLookaroundQuantifierOptimizations.d.ts +0 -9
- package/lib/rules/regexLookaroundQuantifierOptimizations.js +0 -92
- package/lib/rules/regexMatchNotation.d.ts +0 -9
- package/lib/rules/regexMatchNotation.js +0 -137
- package/lib/rules/regexMisleadingCapturingGroups.d.ts +0 -9
- package/lib/rules/regexMisleadingCapturingGroups.js +0 -227
- package/lib/rules/regexMisleadingQuantifiers.d.ts +0 -9
- package/lib/rules/regexMisleadingQuantifiers.js +0 -76
- package/lib/rules/regexMisleadingUnicodeCharacters.d.ts +0 -9
- package/lib/rules/regexMisleadingUnicodeCharacters.js +0 -201
- package/lib/rules/regexNamedBackreferences.d.ts +0 -9
- package/lib/rules/regexNamedBackreferences.js +0 -46
- package/lib/rules/regexNamedCaptureGroups.d.ts +0 -8
- package/lib/rules/regexNamedCaptureGroups.js +0 -65
- package/lib/rules/regexNamedReplacements.d.ts +0 -9
- package/lib/rules/regexNamedReplacements.js +0 -91
- package/lib/rules/regexNonStandardFlags.d.ts +0 -9
- package/lib/rules/regexNonStandardFlags.js +0 -64
- package/lib/rules/regexObscureRanges.d.ts +0 -9
- package/lib/rules/regexObscureRanges.js +0 -91
- package/lib/rules/regexOctalEscapes.d.ts +0 -9
- package/lib/rules/regexOctalEscapes.js +0 -68
- package/lib/rules/regexPlusQuantifiers.d.ts +0 -9
- package/lib/rules/regexPlusQuantifiers.js +0 -66
- package/lib/rules/regexPredefinedAssertions.d.ts +0 -9
- package/lib/rules/regexPredefinedAssertions.js +0 -125
- package/lib/rules/regexQuestionQuantifiers.d.ts +0 -9
- package/lib/rules/regexQuestionQuantifiers.js +0 -102
- package/lib/rules/regexRepeatQuantifiers.d.ts +0 -9
- package/lib/rules/regexRepeatQuantifiers.js +0 -94
- package/lib/rules/regexResultArrayGroups.d.ts +0 -9
- package/lib/rules/regexResultArrayGroups.js +0 -185
- package/lib/rules/regexSetOperationOptimizations.d.ts +0 -9
- package/lib/rules/regexSetOperationOptimizations.js +0 -175
- package/lib/rules/regexStandaloneBackslashes.d.ts +0 -9
- package/lib/rules/regexStandaloneBackslashes.js +0 -57
- package/lib/rules/regexStarQuantifiers.d.ts +0 -9
- package/lib/rules/regexStarQuantifiers.js +0 -66
- package/lib/rules/regexSuperLinearBacktracking.d.ts +0 -9
- package/lib/rules/regexSuperLinearBacktracking.js +0 -96
- package/lib/rules/regexSuperLinearMoves.d.ts +0 -9
- package/lib/rules/regexSuperLinearMoves.js +0 -140
- package/lib/rules/regexTestMethods.d.ts +0 -9
- package/lib/rules/regexTestMethods.js +0 -81
- package/lib/rules/regexUnicodeCodepointEscapes.d.ts +0 -9
- package/lib/rules/regexUnicodeCodepointEscapes.js +0 -105
- package/lib/rules/regexUnicodeEscapes.d.ts +0 -8
- package/lib/rules/regexUnicodeEscapes.js +0 -95
- package/lib/rules/regexUnicodeFlag.d.ts +0 -8
- package/lib/rules/regexUnicodeFlag.js +0 -95
- package/lib/rules/regexUnicodeProperties.d.ts +0 -9
- package/lib/rules/regexUnicodeProperties.js +0 -131
- package/lib/rules/regexUnnecessaryAssertions.d.ts +0 -9
- package/lib/rules/regexUnnecessaryAssertions.js +0 -221
- package/lib/rules/regexUnnecessaryBackreferences.d.ts +0 -9
- package/lib/rules/regexUnnecessaryBackreferences.js +0 -123
- package/lib/rules/regexUnnecessaryCharacterClasses.d.ts +0 -9
- package/lib/rules/regexUnnecessaryCharacterClasses.js +0 -72
- package/lib/rules/regexUnnecessaryCharacterRanges.d.ts +0 -9
- package/lib/rules/regexUnnecessaryCharacterRanges.js +0 -106
- package/lib/rules/regexUnnecessaryDisjunctions.d.ts +0 -9
- package/lib/rules/regexUnnecessaryDisjunctions.js +0 -116
- package/lib/rules/regexUnnecessaryDollarReplacements.d.ts +0 -9
- package/lib/rules/regexUnnecessaryDollarReplacements.js +0 -142
- package/lib/rules/regexUnnecessaryEscapes.d.ts +0 -9
- package/lib/rules/regexUnnecessaryEscapes.js +0 -134
- package/lib/rules/regexUnnecessaryLookaroundAssertions.d.ts +0 -9
- package/lib/rules/regexUnnecessaryLookaroundAssertions.js +0 -78
- package/lib/rules/regexUnnecessaryNestedAssertions.d.ts +0 -9
- package/lib/rules/regexUnnecessaryNestedAssertions.js +0 -196
- package/lib/rules/regexUnnecessaryNestedQuantifiers.d.ts +0 -9
- package/lib/rules/regexUnnecessaryNestedQuantifiers.js +0 -91
- package/lib/rules/regexUnnecessaryNonCapturingGroups.d.ts +0 -9
- package/lib/rules/regexUnnecessaryNonCapturingGroups.js +0 -102
- package/lib/rules/regexUnnecessaryNumericQuantifiers.d.ts +0 -9
- package/lib/rules/regexUnnecessaryNumericQuantifiers.js +0 -67
- package/lib/rules/regexUnnecessaryOptionalAssertions.d.ts +0 -9
- package/lib/rules/regexUnnecessaryOptionalAssertions.js +0 -135
- package/lib/rules/regexUnnecessaryReferentialBackreferences.d.ts +0 -9
- package/lib/rules/regexUnnecessaryReferentialBackreferences.js +0 -121
- package/lib/rules/regexUnnecessarySetOperands.d.ts +0 -9
- package/lib/rules/regexUnnecessarySetOperands.js +0 -134
- package/lib/rules/regexUnusedCapturingGroups.d.ts +0 -9
- package/lib/rules/regexUnusedCapturingGroups.js +0 -67
- package/lib/rules/regexUnusedFlags.d.ts +0 -9
- package/lib/rules/regexUnusedFlags.js +0 -114
- package/lib/rules/regexUnusedLazyQuantifiers.d.ts +0 -9
- package/lib/rules/regexUnusedLazyQuantifiers.js +0 -61
- package/lib/rules/regexUnusedQuantifiers.d.ts +0 -9
- package/lib/rules/regexUnusedQuantifiers.js +0 -61
- package/lib/rules/regexValidity.d.ts +0 -9
- package/lib/rules/regexValidity.js +0 -144
- package/lib/rules/regexWordMatchers.d.ts +0 -9
- package/lib/rules/regexWordMatchers.js +0 -144
- package/lib/rules/regexZeroQuantifiers.d.ts +0 -9
- package/lib/rules/regexZeroQuantifiers.js +0 -58
- package/lib/rules/requireImports.d.ts +0 -9
- package/lib/rules/requireImports.js +0 -46
- package/lib/rules/responseJsonMethods.d.ts +0 -9
- package/lib/rules/responseJsonMethods.js +0 -49
- package/lib/rules/restrictedIdentifiers.d.ts +0 -12
- package/lib/rules/restrictedIdentifiers.js +0 -39
- package/lib/rules/restrictedImports.d.ts +0 -26
- package/lib/rules/restrictedImports.js +0 -164
- package/lib/rules/returnAssignments.d.ts +0 -9
- package/lib/rules/returnAssignments.js +0 -36
- package/lib/rules/returnThisTypes.d.ts +0 -9
- package/lib/rules/returnThisTypes.js +0 -92
- package/lib/rules/ruleCreator.d.ts +0 -2
- package/lib/rules/ruleCreator.js +0 -15
- package/lib/rules/selfAssignments.d.ts +0 -9
- package/lib/rules/selfAssignments.js +0 -27
- package/lib/rules/sequences.d.ts +0 -9
- package/lib/rules/sequences.js +0 -26
- package/lib/rules/setSizeLengthChecks.d.ts +0 -9
- package/lib/rules/setSizeLengthChecks.js +0 -46
- package/lib/rules/setterReturns.d.ts +0 -9
- package/lib/rules/setterReturns.js +0 -39
- package/lib/rules/shadowedRestrictedNames.d.ts +0 -9
- package/lib/rules/shadowedRestrictedNames.js +0 -66
- package/lib/rules/singleVariableDeclarations.d.ts +0 -9
- package/lib/rules/singleVariableDeclarations.js +0 -34
- package/lib/rules/sizeComparisonOperators.d.ts +0 -15
- package/lib/rules/sizeComparisonOperators.js +0 -146
- package/lib/rules/sparseArrays.d.ts +0 -9
- package/lib/rules/sparseArrays.js +0 -41
- package/lib/rules/staticMemberOnlyClasses.d.ts +0 -9
- package/lib/rules/staticMemberOnlyClasses.js +0 -75
- package/lib/rules/stringCaseMismatches.d.ts +0 -9
- package/lib/rules/stringCaseMismatches.js +0 -53
- package/lib/rules/stringCodePoints.d.ts +0 -9
- package/lib/rules/stringCodePoints.js +0 -48
- package/lib/rules/stringSliceMethods.d.ts +0 -9
- package/lib/rules/stringSliceMethods.js +0 -45
- package/lib/rules/stringStartsEndsWith.d.ts +0 -9
- package/lib/rules/stringStartsEndsWith.js +0 -77
- package/lib/rules/structuredCloneMethods.d.ts +0 -9
- package/lib/rules/structuredCloneMethods.js +0 -37
- package/lib/rules/symbolDescriptions.d.ts +0 -9
- package/lib/rules/symbolDescriptions.js +0 -30
- package/lib/rules/thisAliases.d.ts +0 -9
- package/lib/rules/thisAliases.js +0 -42
- package/lib/rules/thisBeforeSuper.d.ts +0 -9
- package/lib/rules/thisBeforeSuper.js +0 -84
- package/lib/rules/throwErrors.d.ts +0 -9
- package/lib/rules/throwErrors.js +0 -59
- package/lib/rules/topLevelAwaits.d.ts +0 -9
- package/lib/rules/topLevelAwaits.js +0 -47
- package/lib/rules/tripleSlashReferenceValidity.d.ts +0 -9
- package/lib/rules/tripleSlashReferenceValidity.js +0 -52
- package/lib/rules/tripleSlashReferences.d.ts +0 -9
- package/lib/rules/tripleSlashReferences.js +0 -32
- package/lib/rules/tsComments.d.ts +0 -21
- package/lib/rules/tsComments.js +0 -128
- package/lib/rules/tslintComments.d.ts +0 -9
- package/lib/rules/tslintComments.js +0 -34
- package/lib/rules/typeAssertionStyles.d.ts +0 -9
- package/lib/rules/typeAssertionStyles.js +0 -30
- package/lib/rules/typeImports.d.ts +0 -19
- package/lib/rules/typeImports.js +0 -281
- package/lib/rules/typeofComparisons.d.ts +0 -9
- package/lib/rules/typeofComparisons.js +0 -53
- package/lib/rules/unassignedVariables.d.ts +0 -9
- package/lib/rules/unassignedVariables.js +0 -32
- package/lib/rules/undefinedTypeofChecks.d.ts +0 -9
- package/lib/rules/undefinedTypeofChecks.js +0 -39
- package/lib/rules/undefinedVariables.d.ts +0 -9
- package/lib/rules/undefinedVariables.js +0 -37
- package/lib/rules/unicodeBOMs.d.ts +0 -9
- package/lib/rules/unicodeBOMs.js +0 -37
- package/lib/rules/unnecessaryBinds.d.ts +0 -9
- package/lib/rules/unnecessaryBinds.js +0 -76
- package/lib/rules/unnecessaryBlocks.d.ts +0 -9
- package/lib/rules/unnecessaryBlocks.js +0 -58
- package/lib/rules/unnecessaryBooleanCasts.d.ts +0 -9
- package/lib/rules/unnecessaryBooleanCasts.js +0 -56
- package/lib/rules/unnecessaryCatches.d.ts +0 -9
- package/lib/rules/unnecessaryCatches.js +0 -46
- package/lib/rules/unnecessaryComparisons.d.ts +0 -9
- package/lib/rules/unnecessaryComparisons.js +0 -291
- package/lib/rules/unnecessaryConcatenation.d.ts +0 -9
- package/lib/rules/unnecessaryConcatenation.js +0 -26
- package/lib/rules/unnecessaryEscapes.d.ts +0 -9
- package/lib/rules/unnecessaryEscapes.js +0 -132
- package/lib/rules/unnecessaryMathClamps.d.ts +0 -9
- package/lib/rules/unnecessaryMathClamps.js +0 -106
- package/lib/rules/unnecessaryNumericFractions.d.ts +0 -9
- package/lib/rules/unnecessaryNumericFractions.js +0 -48
- package/lib/rules/unnecessaryRenames.d.ts +0 -9
- package/lib/rules/unnecessaryRenames.js +0 -90
- package/lib/rules/unnecessaryTernaries.d.ts +0 -9
- package/lib/rules/unnecessaryTernaries.js +0 -86
- package/lib/rules/unnecessaryUseStricts.d.ts +0 -9
- package/lib/rules/unnecessaryUseStricts.js +0 -38
- package/lib/rules/unsafeNegations.d.ts +0 -9
- package/lib/rules/unsafeNegations.js +0 -36
- package/lib/rules/utils/collectAccessorPairs.d.ts +0 -11
- package/lib/rules/utils/collectAccessorPairs.js +0 -27
- package/lib/rules/utils/countCommentsInRange.d.ts +0 -2
- package/lib/rules/utils/countCommentsInRange.js +0 -10
- package/lib/rules/utils/discriminateAnyType.d.ts +0 -15
- package/lib/rules/utils/discriminateAnyType.js +0 -36
- package/lib/rules/utils/equalityOperators.d.ts +0 -8
- package/lib/rules/utils/equalityOperators.js +0 -34
- package/lib/rules/utils/forEachReturnStatement.d.ts +0 -2
- package/lib/rules/utils/forEachReturnStatement.js +0 -27
- package/lib/rules/utils/formatReportedType.d.ts +0 -3
- package/lib/rules/utils/formatReportedType.js +0 -7
- package/lib/rules/utils/getConstrainedType.d.ts +0 -2
- package/lib/rules/utils/getConstrainedType.js +0 -7
- package/lib/rules/utils/getFunctionName.d.ts +0 -2
- package/lib/rules/utils/getFunctionName.js +0 -14
- package/lib/rules/utils/getRegExpConstruction.d.ts +0 -8
- package/lib/rules/utils/getRegExpConstruction.js +0 -25
- package/lib/rules/utils/getRegExpLiteralDetails.d.ts +0 -6
- package/lib/rules/utils/getRegExpLiteralDetails.js +0 -11
- package/lib/rules/utils/getThisExpression.d.ts +0 -2
- package/lib/rules/utils/getThisExpression.js +0 -14
- package/lib/rules/utils/isArrayOrTupleTypeAtLocation.d.ts +0 -2
- package/lib/rules/utils/isArrayOrTupleTypeAtLocation.js +0 -11
- package/lib/rules/utils/isBuiltinSymbolLike.d.ts +0 -2
- package/lib/rules/utils/isBuiltinSymbolLike.js +0 -31
- package/lib/rules/utils/isDirectEqualityCheck.d.ts +0 -3
- package/lib/rules/utils/isDirectEqualityCheck.js +0 -27
- package/lib/rules/utils/isErrorSubclass.d.ts +0 -3
- package/lib/rules/utils/isErrorSubclass.js +0 -25
- package/lib/rules/utils/isInBooleanContext.d.ts +0 -2
- package/lib/rules/utils/isInBooleanContext.js +0 -20
- package/lib/rules/utils/isTypeRecursive.d.ts +0 -2
- package/lib/rules/utils/isTypeRecursive.js +0 -6
- package/lib/rules/utils/isUnsafeAssignment.d.ts +0 -14
- package/lib/rules/utils/isUnsafeAssignment.js +0 -43
- package/lib/rules/utils/operators.d.ts +0 -4
- package/lib/rules/utils/operators.js +0 -33
- package/lib/rules/utils/parseRegexpAst.d.ts +0 -1
- package/lib/rules/utils/parseRegexpAst.js +0 -15
- package/lib/rules/utils/parseRegexpAstFull.d.ts +0 -2
- package/lib/rules/utils/parseRegexpAstFull.js +0 -16
- package/lib/rules/utils/skipParentheses.d.ts +0 -2
- package/lib/rules/utils/skipParentheses.js +0 -8
- package/lib/rules/variableDeletions.d.ts +0 -9
- package/lib/rules/variableDeletions.js +0 -33
- package/lib/rules/voidOperator.d.ts +0 -9
- package/lib/rules/voidOperator.js +0 -32
- package/lib/rules/withStatements.d.ts +0 -9
- package/lib/rules/withStatements.js +0 -28
- package/lib/rules/wrapperObjects.d.ts +0 -9
- package/lib/rules/wrapperObjects.js +0 -34
- package/lib/type-utils/getSpecifierNames.d.ts +0 -2
- package/lib/type-utils/getSpecifierNames.js +0 -7
- package/lib/type-utils/isDeclaredInModuleBlock.d.ts +0 -2
- package/lib/type-utils/isDeclaredInModuleBlock.js +0 -12
- package/lib/type-utils/isFromFile.d.ts +0 -2
- package/lib/type-utils/isFromFile.js +0 -11
- package/lib/type-utils/isFromPackage.d.ts +0 -2
- package/lib/type-utils/isFromPackage.js +0 -13
- package/lib/type-utils/matchesSpecifier.d.ts +0 -3
- package/lib/type-utils/matchesSpecifier.js +0 -18
- package/lib/type-utils/schemas.d.ts +0 -14
- package/lib/type-utils/schemas.js +0 -23
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getRegExpConstruction } from "./utils/getRegExpConstruction.js";
|
|
3
|
-
import { getRegExpLiteralDetails } from "./utils/getRegExpLiteralDetails.js";
|
|
4
|
-
import { typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
5
|
-
//#region src/rules/regexContradictoryAssertions.ts
|
|
6
|
-
function findContradictions(pattern, doubleEscaped) {
|
|
7
|
-
const contradictions = [];
|
|
8
|
-
const wordBoundaryRegex = doubleEscaped ? /\\\\b/g : /\\b/g;
|
|
9
|
-
let match;
|
|
10
|
-
while ((match = wordBoundaryRegex.exec(pattern)) !== null) {
|
|
11
|
-
const assertionStart = match.index;
|
|
12
|
-
const assertionEnd = match.index + match[0].length;
|
|
13
|
-
const characterBefore = getCharBeforeAssertion(pattern, assertionStart, doubleEscaped);
|
|
14
|
-
if (!characterBefore) continue;
|
|
15
|
-
const optional = parseOptionalQuantifier(pattern, assertionEnd, doubleEscaped);
|
|
16
|
-
if (!optional) continue;
|
|
17
|
-
const beforeIsWord = isWordCharacter(characterBefore);
|
|
18
|
-
const elementIsWord = isWordCharacter(getElementChar(optional.element, doubleEscaped));
|
|
19
|
-
const afterOptional = getCharRepresentation(pattern, optional.end, doubleEscaped);
|
|
20
|
-
if (!afterOptional) continue;
|
|
21
|
-
const afterIsWord = isWordCharacter(afterOptional.character);
|
|
22
|
-
if (beforeIsWord === elementIsWord) contradictions.push({
|
|
23
|
-
assertionRaw: match[0],
|
|
24
|
-
elementRaw: optional.element,
|
|
25
|
-
end: optional.end,
|
|
26
|
-
start: assertionEnd,
|
|
27
|
-
type: "cannotEnter"
|
|
28
|
-
});
|
|
29
|
-
else if (beforeIsWord === afterIsWord) contradictions.push({
|
|
30
|
-
assertionRaw: match[0],
|
|
31
|
-
elementRaw: optional.element,
|
|
32
|
-
end: optional.end,
|
|
33
|
-
start: assertionEnd,
|
|
34
|
-
type: "alwaysEnter"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return contradictions;
|
|
38
|
-
}
|
|
39
|
-
function getCharacterFromEscape(escape) {
|
|
40
|
-
switch (escape) {
|
|
41
|
-
case "\\\\d":
|
|
42
|
-
case "\\d": return "0";
|
|
43
|
-
case "\\\\D":
|
|
44
|
-
case "\\D": return " ";
|
|
45
|
-
case "\\\\s":
|
|
46
|
-
case "\\s": return " ";
|
|
47
|
-
case "\\\\S":
|
|
48
|
-
case "\\S": return "a";
|
|
49
|
-
case "\\\\w":
|
|
50
|
-
case "\\w": return "a";
|
|
51
|
-
case "\\\\W":
|
|
52
|
-
case "\\W": return " ";
|
|
53
|
-
default: return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function getCharBeforeAssertion(pattern, assertionStart, doubleEscaped) {
|
|
57
|
-
if (assertionStart <= 0) return;
|
|
58
|
-
if (doubleEscaped) {
|
|
59
|
-
if (assertionStart >= 3 && pattern[assertionStart - 3] === "\\") {
|
|
60
|
-
const charResult = getCharacterFromEscape(pattern.slice(assertionStart - 3, assertionStart));
|
|
61
|
-
if (charResult) return charResult;
|
|
62
|
-
return pattern[assertionStart - 1];
|
|
63
|
-
}
|
|
64
|
-
return pattern[assertionStart - 1];
|
|
65
|
-
}
|
|
66
|
-
if (assertionStart >= 2 && pattern[assertionStart - 2] === "\\") {
|
|
67
|
-
const charResult = getCharacterFromEscape(pattern.slice(assertionStart - 2, assertionStart));
|
|
68
|
-
if (charResult) return charResult;
|
|
69
|
-
return pattern[assertionStart - 1];
|
|
70
|
-
}
|
|
71
|
-
return pattern[assertionStart - 1];
|
|
72
|
-
}
|
|
73
|
-
function getCharRepresentation(pattern, startIndex, doubleEscaped) {
|
|
74
|
-
if (startIndex >= pattern.length) return;
|
|
75
|
-
const remaining = pattern.slice(startIndex);
|
|
76
|
-
if (doubleEscaped) {
|
|
77
|
-
if (remaining.startsWith("\\\\")) {
|
|
78
|
-
const charResult = getCharacterFromEscape(remaining.slice(0, 3));
|
|
79
|
-
if (charResult) return {
|
|
80
|
-
character: charResult,
|
|
81
|
-
length: 3
|
|
82
|
-
};
|
|
83
|
-
if (remaining.length >= 3 && remaining[2]) return {
|
|
84
|
-
character: remaining[2],
|
|
85
|
-
length: 3
|
|
86
|
-
};
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
} else if (remaining.startsWith("\\")) {
|
|
90
|
-
const twoCharEscape = remaining.slice(0, 2);
|
|
91
|
-
const charResult = getCharacterFromEscape(twoCharEscape);
|
|
92
|
-
if (charResult) return {
|
|
93
|
-
character: charResult,
|
|
94
|
-
length: 2
|
|
95
|
-
};
|
|
96
|
-
if (twoCharEscape === "\\b" || twoCharEscape === "\\B" || twoCharEscape === "\\0" || remaining.length < 1 || !remaining[1]) return;
|
|
97
|
-
return {
|
|
98
|
-
character: remaining[1],
|
|
99
|
-
length: 2
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
character: remaining[0],
|
|
104
|
-
length: 1
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function getElementChar(element, doubleEscaped) {
|
|
108
|
-
if (element.startsWith("[")) {
|
|
109
|
-
const inner = element.slice(1, element.lastIndexOf("]"));
|
|
110
|
-
if (!inner.length || inner.startsWith("^")) return;
|
|
111
|
-
if (inner.includes("-") && inner.length > 1) {
|
|
112
|
-
const rangeMatch = /^(.)/.exec(inner);
|
|
113
|
-
if (rangeMatch) return rangeMatch[1];
|
|
114
|
-
}
|
|
115
|
-
return inner[0];
|
|
116
|
-
}
|
|
117
|
-
const withoutQuantifier = element.replace(/[*?]$/, "");
|
|
118
|
-
if (doubleEscaped && withoutQuantifier.startsWith("\\\\")) {
|
|
119
|
-
const characterResult = getCharacterFromEscape(withoutQuantifier);
|
|
120
|
-
if (characterResult) return characterResult;
|
|
121
|
-
if (withoutQuantifier.length >= 3) return withoutQuantifier[2];
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (!doubleEscaped && withoutQuantifier.startsWith("\\")) {
|
|
125
|
-
const charResult = getCharacterFromEscape(withoutQuantifier);
|
|
126
|
-
if (charResult) return charResult;
|
|
127
|
-
if (withoutQuantifier.length >= 2) return withoutQuantifier[1];
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
return withoutQuantifier;
|
|
131
|
-
}
|
|
132
|
-
function isWordCharacter(character) {
|
|
133
|
-
return character ? /^\w$/.test(character) : false;
|
|
134
|
-
}
|
|
135
|
-
function parseOptionalQuantifier(pattern, startIndex, doubleEscaped) {
|
|
136
|
-
if (startIndex >= pattern.length) return;
|
|
137
|
-
const remaining = pattern.slice(startIndex);
|
|
138
|
-
const characterClassMatch = /^\[[^\]]*\][*?]/.exec(remaining);
|
|
139
|
-
if (characterClassMatch) return {
|
|
140
|
-
element: characterClassMatch[0],
|
|
141
|
-
end: startIndex + characterClassMatch[0].length
|
|
142
|
-
};
|
|
143
|
-
const escapePattern = doubleEscaped ? /^(?:\\\\.|.)[*?]/ : /^(?:\\.|.)[*?]/;
|
|
144
|
-
const simpleMatch = remaining.match(escapePattern);
|
|
145
|
-
if (simpleMatch) return {
|
|
146
|
-
element: simpleMatch[0],
|
|
147
|
-
end: startIndex + simpleMatch[0].length
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
var regexContradictoryAssertions_default = ruleCreator.createRule(typescriptLanguage, {
|
|
151
|
-
about: {
|
|
152
|
-
description: "Reports elements in regular expressions that contradict assertions.",
|
|
153
|
-
id: "regexContradictoryAssertions",
|
|
154
|
-
presets: ["logical", "logicalStrict"]
|
|
155
|
-
},
|
|
156
|
-
messages: {
|
|
157
|
-
alwaysEnter: {
|
|
158
|
-
primary: "The quantifier '{{ element }}' is always entered despite having a minimum of 0.",
|
|
159
|
-
secondary: ["The quantifier appears after an assertion that forces it to be matched at least once.", "This can lead to unexpected matching behavior."],
|
|
160
|
-
suggestions: ["Change the quantifier minimum to 1."]
|
|
161
|
-
},
|
|
162
|
-
cannotEnter: {
|
|
163
|
-
primary: "The quantifier '{{ element }}' can never be entered because it contradicts the assertion '{{ assertion }}'.",
|
|
164
|
-
secondary: ["The quantifier element would need to match characters that the assertion explicitly forbids.", "This means the quantifier is effectively dead code."],
|
|
165
|
-
suggestions: ["Remove the quantifier or fix the pattern."]
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
setup(context) {
|
|
169
|
-
function checkRegexLiteral(node, services) {
|
|
170
|
-
const { pattern, start } = getRegExpLiteralDetails(node, services);
|
|
171
|
-
const contradictions = findContradictions(pattern, false);
|
|
172
|
-
for (const contradiction of contradictions) context.report({
|
|
173
|
-
data: {
|
|
174
|
-
assertion: contradiction.assertionRaw,
|
|
175
|
-
element: contradiction.elementRaw
|
|
176
|
-
},
|
|
177
|
-
message: contradiction.type === "alwaysEnter" ? "alwaysEnter" : "cannotEnter",
|
|
178
|
-
range: {
|
|
179
|
-
begin: start + contradiction.start,
|
|
180
|
-
end: start + contradiction.end
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function checkRegExpConstructor(node, services) {
|
|
185
|
-
const construction = getRegExpConstruction(node, services);
|
|
186
|
-
if (!construction) return;
|
|
187
|
-
const contradictions = findContradictions(construction.pattern, true);
|
|
188
|
-
for (const contradiction of contradictions) context.report({
|
|
189
|
-
data: {
|
|
190
|
-
assertion: contradiction.assertionRaw,
|
|
191
|
-
element: contradiction.elementRaw
|
|
192
|
-
},
|
|
193
|
-
message: contradiction.type === "alwaysEnter" ? "alwaysEnter" : "cannotEnter",
|
|
194
|
-
range: {
|
|
195
|
-
begin: construction.start + 1 + contradiction.start,
|
|
196
|
-
end: construction.start + 1 + contradiction.end
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
return { visitors: {
|
|
201
|
-
CallExpression: checkRegExpConstructor,
|
|
202
|
-
NewExpression: checkRegExpConstructor,
|
|
203
|
-
RegularExpressionLiteral: checkRegexLiteral
|
|
204
|
-
} };
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
//#endregion
|
|
208
|
-
export { regexContradictoryAssertions_default as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports control characters that are not escaped using standard escape sequences.";
|
|
3
|
-
readonly id: "regexControlCharacterEscapes";
|
|
4
|
-
readonly presets: readonly ["logical", "logicalStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "preferStandardEscape", undefined>;
|
|
9
|
-
export default _default;
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getRegExpConstruction } from "./utils/getRegExpConstruction.js";
|
|
3
|
-
import { getRegExpLiteralDetails } from "./utils/getRegExpLiteralDetails.js";
|
|
4
|
-
import { typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
5
|
-
//#region src/rules/regexControlCharacterEscapes.ts
|
|
6
|
-
const controlCharacters = {
|
|
7
|
-
"\\0": "\\0",
|
|
8
|
-
"\\cI": "\\t",
|
|
9
|
-
"\\cJ": "\\n",
|
|
10
|
-
"\\cK": "\\v",
|
|
11
|
-
"\\cL": "\\f",
|
|
12
|
-
"\\cM": "\\r",
|
|
13
|
-
"\\u000A": "\\n",
|
|
14
|
-
"\\u000a": "\\n",
|
|
15
|
-
"\\u000B": "\\v",
|
|
16
|
-
"\\u000b": "\\v",
|
|
17
|
-
"\\u000C": "\\f",
|
|
18
|
-
"\\u000c": "\\f",
|
|
19
|
-
"\\u000D": "\\r",
|
|
20
|
-
"\\u000d": "\\r",
|
|
21
|
-
"\\u0000": "\\0",
|
|
22
|
-
"\\u0009": "\\t",
|
|
23
|
-
"\\u{0}": "\\0",
|
|
24
|
-
"\\u{9}": "\\t",
|
|
25
|
-
"\\u{a}": "\\n",
|
|
26
|
-
"\\u{A}": "\\n",
|
|
27
|
-
"\\u{b}": "\\v",
|
|
28
|
-
"\\u{B}": "\\v",
|
|
29
|
-
"\\u{c}": "\\f",
|
|
30
|
-
"\\u{C}": "\\f",
|
|
31
|
-
"\\u{d}": "\\r",
|
|
32
|
-
"\\u{D}": "\\r",
|
|
33
|
-
"\\x0A": "\\n",
|
|
34
|
-
"\\x0a": "\\n",
|
|
35
|
-
"\\x0B": "\\v",
|
|
36
|
-
"\\x0b": "\\v",
|
|
37
|
-
"\\x0C": "\\f",
|
|
38
|
-
"\\x0c": "\\f",
|
|
39
|
-
"\\x0D": "\\r",
|
|
40
|
-
"\\x0d": "\\r",
|
|
41
|
-
"\\x00": "\\0",
|
|
42
|
-
"\\x09": "\\t"
|
|
43
|
-
};
|
|
44
|
-
const controlDoubleEscapePattern = /\\\\(?:x0[09A-Da-d]|u000[09A-Da-d]|u\{[09A-Da-d]\}|c[I-M])/g;
|
|
45
|
-
const controlSingleEscapePattern = /\\(?:x0[09A-Da-d]|u000[09A-Da-d]|u\{[09A-Da-d]\}|c[I-M])/g;
|
|
46
|
-
function findControlCharacterIssues(pattern, doubleEscaped) {
|
|
47
|
-
const issues = [];
|
|
48
|
-
const searchPattern = doubleEscaped ? controlDoubleEscapePattern : controlSingleEscapePattern;
|
|
49
|
-
let match;
|
|
50
|
-
while ((match = searchPattern.exec(pattern)) !== null) {
|
|
51
|
-
const found = match[0];
|
|
52
|
-
const normalizedKey = doubleEscaped ? found.slice(1) : found;
|
|
53
|
-
const expected = controlCharacters[normalizedKey];
|
|
54
|
-
if (expected && normalizedKey !== expected) issues.push({
|
|
55
|
-
end: match.index + found.length,
|
|
56
|
-
expected: doubleEscaped ? "\\" + expected : expected,
|
|
57
|
-
found,
|
|
58
|
-
start: match.index
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return issues;
|
|
62
|
-
}
|
|
63
|
-
var regexControlCharacterEscapes_default = ruleCreator.createRule(typescriptLanguage, {
|
|
64
|
-
about: {
|
|
65
|
-
description: "Reports control characters that are not escaped using standard escape sequences.",
|
|
66
|
-
id: "regexControlCharacterEscapes",
|
|
67
|
-
presets: ["logical", "logicalStrict"]
|
|
68
|
-
},
|
|
69
|
-
messages: { preferStandardEscape: {
|
|
70
|
-
primary: "Prefer standard escape sequence '{{ expected }}' over '{{ found }}'.",
|
|
71
|
-
secondary: ["Standard escape sequences like \\t, \\n, \\r are more readable than hex or unicode escapes."],
|
|
72
|
-
suggestions: ["Replace '{{ found }}' with '{{ expected }}'."]
|
|
73
|
-
} },
|
|
74
|
-
setup(context) {
|
|
75
|
-
function checkRegexLiteral(node, services) {
|
|
76
|
-
const { pattern, start } = getRegExpLiteralDetails(node, services);
|
|
77
|
-
const issues = findControlCharacterIssues(pattern, false);
|
|
78
|
-
for (const issue of issues) context.report({
|
|
79
|
-
data: {
|
|
80
|
-
expected: issue.expected,
|
|
81
|
-
found: issue.found
|
|
82
|
-
},
|
|
83
|
-
fix: {
|
|
84
|
-
range: {
|
|
85
|
-
begin: start + issue.start,
|
|
86
|
-
end: start + issue.end
|
|
87
|
-
},
|
|
88
|
-
text: issue.expected
|
|
89
|
-
},
|
|
90
|
-
message: "preferStandardEscape",
|
|
91
|
-
range: {
|
|
92
|
-
begin: start + issue.start,
|
|
93
|
-
end: start + issue.end
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function checkRegExpConstructor(node, services) {
|
|
98
|
-
const construction = getRegExpConstruction(node, services);
|
|
99
|
-
if (!construction) return;
|
|
100
|
-
const issues = findControlCharacterIssues(construction.pattern, true);
|
|
101
|
-
for (const issue of issues) context.report({
|
|
102
|
-
data: {
|
|
103
|
-
expected: issue.expected,
|
|
104
|
-
found: issue.found
|
|
105
|
-
},
|
|
106
|
-
fix: {
|
|
107
|
-
range: {
|
|
108
|
-
begin: construction.start + 1 + issue.start,
|
|
109
|
-
end: construction.start + 1 + issue.end
|
|
110
|
-
},
|
|
111
|
-
text: issue.expected
|
|
112
|
-
},
|
|
113
|
-
message: "preferStandardEscape",
|
|
114
|
-
range: {
|
|
115
|
-
begin: construction.start + 1 + issue.start,
|
|
116
|
-
end: construction.start + 1 + issue.end
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return { visitors: {
|
|
121
|
-
CallExpression: checkRegExpConstructor,
|
|
122
|
-
NewExpression: checkRegExpConstructor,
|
|
123
|
-
RegularExpressionLiteral: checkRegexLiteral
|
|
124
|
-
} };
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
//#endregion
|
|
128
|
-
export { regexControlCharacterEscapes_default as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports control characters in regular expressions.";
|
|
3
|
-
readonly id: "regexControlCharacters";
|
|
4
|
-
readonly presets: readonly ["logical", "logicalStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "unexpectedControlChar", undefined>;
|
|
9
|
-
export default _default;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getRegExpLiteralDetails } from "./utils/getRegExpLiteralDetails.js";
|
|
3
|
-
import { typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
4
|
-
import * as ts$1 from "typescript";
|
|
5
|
-
//#region src/rules/regexControlCharacters.ts
|
|
6
|
-
const knownControlEscapes = {
|
|
7
|
-
0: "\\0",
|
|
8
|
-
9: "\\t",
|
|
9
|
-
10: "\\n",
|
|
10
|
-
11: "\\v",
|
|
11
|
-
12: "\\f",
|
|
12
|
-
13: "\\r"
|
|
13
|
-
};
|
|
14
|
-
const controlCharacterSinglePattern = /\\x(0[0-9a-fA-F]|1[0-9a-fA-F])|\\u00(0[0-9a-fA-F]|1[0-9a-fA-F])|\\u\{([0-9a-fA-F]|1[0-9a-fA-F])\}|\\c[A-Z]/g;
|
|
15
|
-
const controlCharacterDoubleEscapedPattern = /\\\\x(0[0-9A-Fa-f]|1[0-9A-Fa-f])|\\\\u00(0[0-9A-Fa-f]|1[0-9A-Fa-f])|\\\\u\{([0-9A-Fa-f]|1[0-9A-Fa-f])\}|\\\\c[A-Z]/g;
|
|
16
|
-
function findControlCharacters(pattern, doubleEscaped) {
|
|
17
|
-
const issues = [];
|
|
18
|
-
const searchPattern = doubleEscaped ? controlCharacterDoubleEscapedPattern : controlCharacterSinglePattern;
|
|
19
|
-
let match;
|
|
20
|
-
while ((match = searchPattern.exec(pattern)) !== null) {
|
|
21
|
-
const found = match[0];
|
|
22
|
-
const codePoint = parseControlCharCodePoint(doubleEscaped ? found.slice(1) : found);
|
|
23
|
-
if (codePoint !== void 0 && codePoint <= 31) {
|
|
24
|
-
const suggestedEscape = knownControlEscapes[codePoint];
|
|
25
|
-
issues.push({
|
|
26
|
-
codePoint,
|
|
27
|
-
end: match.index + found.length,
|
|
28
|
-
found,
|
|
29
|
-
start: match.index,
|
|
30
|
-
suggestedEscape: suggestedEscape ? doubleEscaped ? "\\" + suggestedEscape : suggestedEscape : void 0
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return issues;
|
|
35
|
-
}
|
|
36
|
-
function formatCodePoint(codePoint) {
|
|
37
|
-
return `U+${codePoint.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
38
|
-
}
|
|
39
|
-
function parseControlCharCodePoint(match) {
|
|
40
|
-
if (match.startsWith("\\x")) return parseInt(match.slice(2), 16);
|
|
41
|
-
if (match.startsWith("\\u{")) return parseInt(match.slice(3, -1), 16);
|
|
42
|
-
if (match.startsWith("\\u00")) return parseInt(match.slice(4), 16);
|
|
43
|
-
if (match.startsWith("\\c")) {
|
|
44
|
-
const letter = match[2];
|
|
45
|
-
if (letter) return letter.charCodeAt(0) - 64;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
var regexControlCharacters_default = ruleCreator.createRule(typescriptLanguage, {
|
|
49
|
-
about: {
|
|
50
|
-
description: "Reports control characters in regular expressions.",
|
|
51
|
-
id: "regexControlCharacters",
|
|
52
|
-
presets: ["logical", "logicalStrict"]
|
|
53
|
-
},
|
|
54
|
-
messages: { unexpectedControlChar: {
|
|
55
|
-
primary: "Unexpected control character '{{ found }}' ({{ codePoint }}) in regular expression.",
|
|
56
|
-
secondary: ["Control characters in regular expressions are rarely intentional and can cause unexpected matching behavior.", "If intentional, consider using a more readable escape sequence."],
|
|
57
|
-
suggestions: ["Remove the control character or use a standard escape."]
|
|
58
|
-
} },
|
|
59
|
-
setup(context) {
|
|
60
|
-
function reportIssues(issues, start) {
|
|
61
|
-
for (const issue of issues) context.report({
|
|
62
|
-
data: {
|
|
63
|
-
codePoint: formatCodePoint(issue.codePoint),
|
|
64
|
-
found: issue.found
|
|
65
|
-
},
|
|
66
|
-
message: "unexpectedControlChar",
|
|
67
|
-
range: {
|
|
68
|
-
begin: start + 1 + issue.start,
|
|
69
|
-
end: start + 1 + issue.end
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function checkRegexLiteral(node, services) {
|
|
74
|
-
const { pattern, start } = getRegExpLiteralDetails(node, services);
|
|
75
|
-
reportIssues(findControlCharacters(pattern, false), start - 1);
|
|
76
|
-
}
|
|
77
|
-
function checkRegExpConstructor(node, services) {
|
|
78
|
-
if (node.expression.kind !== ts$1.SyntaxKind.Identifier || node.expression.text !== "RegExp") return;
|
|
79
|
-
const args = node.arguments;
|
|
80
|
-
if (!args?.length) return;
|
|
81
|
-
const stringLiteral = args[0];
|
|
82
|
-
if (stringLiteral.kind !== ts$1.SyntaxKind.StringLiteral) return;
|
|
83
|
-
reportIssues(findControlCharacters(stringLiteral.getText(services.sourceFile).slice(1, -1), true), stringLiteral.getStart(services.sourceFile));
|
|
84
|
-
}
|
|
85
|
-
return { visitors: {
|
|
86
|
-
CallExpression: checkRegExpConstructor,
|
|
87
|
-
NewExpression: checkRegExpConstructor,
|
|
88
|
-
RegularExpressionLiteral: checkRegexLiteral
|
|
89
|
-
} };
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
//#endregion
|
|
93
|
-
export { regexControlCharacters_default as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports character classes with multiple adjacent characters that could use a range instead.";
|
|
3
|
-
readonly id: "regexDigitMatchers";
|
|
4
|
-
readonly presets: readonly ["stylisticStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "preferRange", undefined>;
|
|
9
|
-
export default _default;
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { ruleCreator } from "./ruleCreator.js";
|
|
2
|
-
import { getRegExpConstruction } from "./utils/getRegExpConstruction.js";
|
|
3
|
-
import { typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
4
|
-
import { parseRegExpLiteral, visitRegExpAST } from "@eslint-community/regexpp";
|
|
5
|
-
//#region src/rules/regexDigitMatchers.ts
|
|
6
|
-
const ALLOWED_RANGES = [
|
|
7
|
-
{
|
|
8
|
-
max: 57,
|
|
9
|
-
min: 48
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
max: 90,
|
|
13
|
-
min: 65
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
max: 122,
|
|
17
|
-
min: 97
|
|
18
|
-
}
|
|
19
|
-
];
|
|
20
|
-
function checkInAllowedRange(value, rangeMin, rangeMax) {
|
|
21
|
-
const min = rangeMin ?? value;
|
|
22
|
-
const max = rangeMax ?? value;
|
|
23
|
-
return ALLOWED_RANGES.some((r) => r.min <= min && max <= r.max);
|
|
24
|
-
}
|
|
25
|
-
function findIssues(pattern, flags) {
|
|
26
|
-
const issues = [];
|
|
27
|
-
let ast;
|
|
28
|
-
try {
|
|
29
|
-
ast = parseRegExpLiteral(new RegExp(pattern, flags));
|
|
30
|
-
} catch {
|
|
31
|
-
return issues;
|
|
32
|
-
}
|
|
33
|
-
visitRegExpAST(ast, { onCharacterClassEnter(ccNode) {
|
|
34
|
-
const groups = [];
|
|
35
|
-
for (const element of ccNode.elements) {
|
|
36
|
-
let data;
|
|
37
|
-
if (element.type === "Character") if (checkInAllowedRange(element.value)) data = {
|
|
38
|
-
max: element,
|
|
39
|
-
min: element
|
|
40
|
-
};
|
|
41
|
-
else continue;
|
|
42
|
-
else if (element.type === "CharacterClassRange") if (checkInAllowedRange(element.min.value, element.min.value, element.max.value)) data = {
|
|
43
|
-
max: element.max,
|
|
44
|
-
min: element.min
|
|
45
|
-
};
|
|
46
|
-
else continue;
|
|
47
|
-
else continue;
|
|
48
|
-
const group = groups.find((gp) => {
|
|
49
|
-
if (!(gp.min.value - 1 <= data.max.value && data.min.value <= gp.max.value + 1)) return false;
|
|
50
|
-
const min = Math.min(gp.min.value, data.min.value);
|
|
51
|
-
return checkInAllowedRange(min, min, Math.max(gp.max.value, data.max.value));
|
|
52
|
-
});
|
|
53
|
-
if (group) {
|
|
54
|
-
if (data.min.value < group.min.value) group.min = data.min;
|
|
55
|
-
if (group.max.value < data.max.value) group.max = data.max;
|
|
56
|
-
group.nodes.push(element);
|
|
57
|
-
} else groups.push({
|
|
58
|
-
...data,
|
|
59
|
-
nodes: [element]
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
for (const group of groups) if (group.max.value - group.min.value + 1 >= 4 && group.nodes.length > 1) {
|
|
63
|
-
const newText = `${group.min.raw}-${group.max.raw}`;
|
|
64
|
-
const nodeRanges = [];
|
|
65
|
-
for (const node of group.nodes) nodeRanges.push({
|
|
66
|
-
end: node.end,
|
|
67
|
-
start: node.start
|
|
68
|
-
});
|
|
69
|
-
nodeRanges.sort((a, b) => a.start - b.start);
|
|
70
|
-
const mergedRanges = [];
|
|
71
|
-
for (const range of nodeRanges) {
|
|
72
|
-
const last = mergedRanges.at(-1);
|
|
73
|
-
if (last && last.end >= range.start) last.end = Math.max(last.end, range.end);
|
|
74
|
-
else mergedRanges.push({ ...range });
|
|
75
|
-
}
|
|
76
|
-
const firstMerged = mergedRanges[0];
|
|
77
|
-
const lastMerged = mergedRanges.at(-1);
|
|
78
|
-
if (firstMerged && lastMerged) issues.push({
|
|
79
|
-
end: lastMerged.end,
|
|
80
|
-
newText,
|
|
81
|
-
nodeRanges: mergedRanges,
|
|
82
|
-
start: firstMerged.start
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
} });
|
|
86
|
-
return issues;
|
|
87
|
-
}
|
|
88
|
-
function getRegexPattern(node) {
|
|
89
|
-
const text = node.text;
|
|
90
|
-
const lastSlash = text.lastIndexOf("/");
|
|
91
|
-
return {
|
|
92
|
-
flags: text.slice(lastSlash + 1),
|
|
93
|
-
pattern: text.slice(1, lastSlash)
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
var regexDigitMatchers_default = ruleCreator.createRule(typescriptLanguage, {
|
|
97
|
-
about: {
|
|
98
|
-
description: "Reports character classes with multiple adjacent characters that could use a range instead.",
|
|
99
|
-
id: "regexDigitMatchers",
|
|
100
|
-
presets: ["stylisticStrict"]
|
|
101
|
-
},
|
|
102
|
-
messages: { preferRange: {
|
|
103
|
-
primary: "These multiple adjacent characters can be simplified to `{{ range }}` instead.",
|
|
104
|
-
secondary: ["Character class ranges (e.g., `a-d`) are more concise and readable than listing multiple adjacent characters (e.g., `abcd`)."],
|
|
105
|
-
suggestions: ["Replace adjacent characters with '{{ range }}'."]
|
|
106
|
-
} },
|
|
107
|
-
setup(context) {
|
|
108
|
-
function checkRegexLiteral(node, { sourceFile }) {
|
|
109
|
-
const { flags, pattern } = getRegexPattern(node);
|
|
110
|
-
const issues = findIssues(pattern, flags);
|
|
111
|
-
const nodeStart = node.getStart(sourceFile);
|
|
112
|
-
for (const issue of issues) {
|
|
113
|
-
const firstRange = issue.nodeRanges[0];
|
|
114
|
-
if (!firstRange) continue;
|
|
115
|
-
context.report({
|
|
116
|
-
data: { range: issue.newText },
|
|
117
|
-
fix: issue.nodeRanges.map((range, index) => ({
|
|
118
|
-
range: {
|
|
119
|
-
begin: nodeStart + range.start,
|
|
120
|
-
end: nodeStart + range.end
|
|
121
|
-
},
|
|
122
|
-
text: index === 0 ? issue.newText : ""
|
|
123
|
-
})),
|
|
124
|
-
message: "preferRange",
|
|
125
|
-
range: {
|
|
126
|
-
begin: nodeStart + firstRange.start,
|
|
127
|
-
end: nodeStart + firstRange.end
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function checkRegExpConstructor(node, services) {
|
|
133
|
-
const construction = getRegExpConstruction(node, services);
|
|
134
|
-
if (!construction) return;
|
|
135
|
-
const { pattern, start } = construction;
|
|
136
|
-
const issues = findIssues(pattern.replace(/\\\\/g, "\\"), construction.flags);
|
|
137
|
-
function mapPositionToSource(pos) {
|
|
138
|
-
let sourcePos = 0;
|
|
139
|
-
let patternPos = 0;
|
|
140
|
-
while (patternPos < pos && sourcePos < pattern.length) {
|
|
141
|
-
if (pattern[sourcePos] === "\\" && pattern[sourcePos + 1] === "\\") sourcePos += 2;
|
|
142
|
-
else sourcePos += 1;
|
|
143
|
-
patternPos += 1;
|
|
144
|
-
}
|
|
145
|
-
return sourcePos;
|
|
146
|
-
}
|
|
147
|
-
for (const issue of issues) {
|
|
148
|
-
const adjustedRanges = issue.nodeRanges.map((range) => ({
|
|
149
|
-
end: mapPositionToSource(range.end - 1),
|
|
150
|
-
start: mapPositionToSource(range.start - 1)
|
|
151
|
-
}));
|
|
152
|
-
const firstRange = adjustedRanges[0];
|
|
153
|
-
context.report({
|
|
154
|
-
data: { range: issue.newText.replace(/\\/g, "\\\\") },
|
|
155
|
-
fix: adjustedRanges.map((range, index) => ({
|
|
156
|
-
range: {
|
|
157
|
-
begin: start + 1 + range.start,
|
|
158
|
-
end: start + 1 + range.end
|
|
159
|
-
},
|
|
160
|
-
text: index === 0 ? issue.newText.replace(/\\/g, "\\\\") : ""
|
|
161
|
-
})),
|
|
162
|
-
message: "preferRange",
|
|
163
|
-
range: {
|
|
164
|
-
begin: start + 1 + firstRange.start,
|
|
165
|
-
end: start + 1 + firstRange.end
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return { visitors: {
|
|
171
|
-
CallExpression: checkRegExpConstructor,
|
|
172
|
-
NewExpression: checkRegExpConstructor,
|
|
173
|
-
RegularExpressionLiteral: checkRegexLiteral
|
|
174
|
-
} };
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
//#endregion
|
|
178
|
-
export { regexDigitMatchers_default as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const _default: import("@flint.fyi/core").Rule<{
|
|
2
|
-
readonly description: "Reports replacement strings with unescaped `$` that should use `$$`.";
|
|
3
|
-
readonly id: "regexDollarEscapes";
|
|
4
|
-
readonly presets: readonly ["stylistic", "stylisticStrict"];
|
|
5
|
-
} & {
|
|
6
|
-
readonly pluginId: string;
|
|
7
|
-
readonly url: string;
|
|
8
|
-
}, "unescapedDollar", undefined>;
|
|
9
|
-
export default _default;
|