diff --git a/crates/oxc_linter/src/generated/rule_runner_impls.rs b/crates/oxc_linter/src/generated/rule_runner_impls.rs index 525821ed824bb..16c9a4e107c1b 100644 --- a/crates/oxc_linter/src/generated/rule_runner_impls.rs +++ b/crates/oxc_linter/src/generated/rule_runner_impls.rs @@ -1385,6 +1385,12 @@ impl RuleRunner const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } +impl RuleRunner for crate::rules::typescript::consistent_type_assertions::ConsistentTypeAssertions { + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::TSAsExpression, AstType::TSTypeAssertion])); + const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; +} + impl RuleRunner for crate::rules::typescript::consistent_type_definitions::ConsistentTypeDefinitions { diff --git a/crates/oxc_linter/src/generated/rules_enum.rs b/crates/oxc_linter/src/generated/rules_enum.rs index d12e9e610f703..87529927cd941 100644 --- a/crates/oxc_linter/src/generated/rules_enum.rs +++ b/crates/oxc_linter/src/generated/rules_enum.rs @@ -440,6 +440,7 @@ pub use crate::rules::typescript::ban_tslint_comment::BanTslintComment as Typesc pub use crate::rules::typescript::ban_types::BanTypes as TypescriptBanTypes; pub use crate::rules::typescript::consistent_generic_constructors::ConsistentGenericConstructors as TypescriptConsistentGenericConstructors; pub use crate::rules::typescript::consistent_indexed_object_style::ConsistentIndexedObjectStyle as TypescriptConsistentIndexedObjectStyle; +pub use crate::rules::typescript::consistent_type_assertions::ConsistentTypeAssertions as TypescriptConsistentTypeAssertions; pub use crate::rules::typescript::consistent_type_definitions::ConsistentTypeDefinitions as TypescriptConsistentTypeDefinitions; pub use crate::rules::typescript::consistent_type_imports::ConsistentTypeImports as TypescriptConsistentTypeImports; pub use crate::rules::typescript::explicit_function_return_type::ExplicitFunctionReturnType as TypescriptExplicitFunctionReturnType; @@ -891,6 +892,7 @@ pub enum RuleEnum { TypescriptBanTypes(TypescriptBanTypes), TypescriptConsistentGenericConstructors(TypescriptConsistentGenericConstructors), TypescriptConsistentIndexedObjectStyle(TypescriptConsistentIndexedObjectStyle), + TypescriptConsistentTypeAssertions(TypescriptConsistentTypeAssertions), TypescriptConsistentTypeDefinitions(TypescriptConsistentTypeDefinitions), TypescriptConsistentTypeImports(TypescriptConsistentTypeImports), TypescriptExplicitFunctionReturnType(TypescriptExplicitFunctionReturnType), @@ -1566,466 +1568,467 @@ impl RuleEnum { Self::TypescriptBanTypes(_) => 204usize, Self::TypescriptConsistentGenericConstructors(_) => 205usize, Self::TypescriptConsistentIndexedObjectStyle(_) => 206usize, - Self::TypescriptConsistentTypeDefinitions(_) => 207usize, - Self::TypescriptConsistentTypeImports(_) => 208usize, - Self::TypescriptExplicitFunctionReturnType(_) => 209usize, - Self::TypescriptExplicitModuleBoundaryTypes(_) => 210usize, - Self::TypescriptNoArrayDelete(_) => 211usize, - Self::TypescriptNoBaseToString(_) => 212usize, - Self::TypescriptNoConfusingNonNullAssertion(_) => 213usize, - Self::TypescriptNoConfusingVoidExpression(_) => 214usize, - Self::TypescriptNoDeprecated(_) => 215usize, - Self::TypescriptNoDuplicateEnumValues(_) => 216usize, - Self::TypescriptNoDuplicateTypeConstituents(_) => 217usize, - Self::TypescriptNoDynamicDelete(_) => 218usize, - Self::TypescriptNoEmptyInterface(_) => 219usize, - Self::TypescriptNoEmptyObjectType(_) => 220usize, - Self::TypescriptNoExplicitAny(_) => 221usize, - Self::TypescriptNoExtraNonNullAssertion(_) => 222usize, - Self::TypescriptNoExtraneousClass(_) => 223usize, - Self::TypescriptNoFloatingPromises(_) => 224usize, - Self::TypescriptNoForInArray(_) => 225usize, - Self::TypescriptNoImpliedEval(_) => 226usize, - Self::TypescriptNoImportTypeSideEffects(_) => 227usize, - Self::TypescriptNoInferrableTypes(_) => 228usize, - Self::TypescriptNoMeaninglessVoidOperator(_) => 229usize, - Self::TypescriptNoMisusedNew(_) => 230usize, - Self::TypescriptNoMisusedPromises(_) => 231usize, - Self::TypescriptNoMisusedSpread(_) => 232usize, - Self::TypescriptNoMixedEnums(_) => 233usize, - Self::TypescriptNoNamespace(_) => 234usize, - Self::TypescriptNoNonNullAssertedNullishCoalescing(_) => 235usize, - Self::TypescriptNoNonNullAssertedOptionalChain(_) => 236usize, - Self::TypescriptNoNonNullAssertion(_) => 237usize, - Self::TypescriptNoRedundantTypeConstituents(_) => 238usize, - Self::TypescriptNoRequireImports(_) => 239usize, - Self::TypescriptNoRestrictedTypes(_) => 240usize, - Self::TypescriptNoThisAlias(_) => 241usize, - Self::TypescriptNoUnnecessaryBooleanLiteralCompare(_) => 242usize, - Self::TypescriptNoUnnecessaryParameterPropertyAssignment(_) => 243usize, - Self::TypescriptNoUnnecessaryTemplateExpression(_) => 244usize, - Self::TypescriptNoUnnecessaryTypeArguments(_) => 245usize, - Self::TypescriptNoUnnecessaryTypeAssertion(_) => 246usize, - Self::TypescriptNoUnnecessaryTypeConstraint(_) => 247usize, - Self::TypescriptNoUnsafeArgument(_) => 248usize, - Self::TypescriptNoUnsafeAssignment(_) => 249usize, - Self::TypescriptNoUnsafeCall(_) => 250usize, - Self::TypescriptNoUnsafeDeclarationMerging(_) => 251usize, - Self::TypescriptNoUnsafeEnumComparison(_) => 252usize, - Self::TypescriptNoUnsafeFunctionType(_) => 253usize, - Self::TypescriptNoUnsafeMemberAccess(_) => 254usize, - Self::TypescriptNoUnsafeReturn(_) => 255usize, - Self::TypescriptNoUnsafeTypeAssertion(_) => 256usize, - Self::TypescriptNoUnsafeUnaryMinus(_) => 257usize, - Self::TypescriptNoUselessEmptyExport(_) => 258usize, - Self::TypescriptNoVarRequires(_) => 259usize, - Self::TypescriptNoWrapperObjectTypes(_) => 260usize, - Self::TypescriptNonNullableTypeAssertionStyle(_) => 261usize, - Self::TypescriptOnlyThrowError(_) => 262usize, - Self::TypescriptPreferAsConst(_) => 263usize, - Self::TypescriptPreferEnumInitializers(_) => 264usize, - Self::TypescriptPreferForOf(_) => 265usize, - Self::TypescriptPreferFunctionType(_) => 266usize, - Self::TypescriptPreferIncludes(_) => 267usize, - Self::TypescriptPreferLiteralEnumMember(_) => 268usize, - Self::TypescriptPreferNamespaceKeyword(_) => 269usize, - Self::TypescriptPreferNullishCoalescing(_) => 270usize, - Self::TypescriptPreferOptionalChain(_) => 271usize, - Self::TypescriptPreferPromiseRejectErrors(_) => 272usize, - Self::TypescriptPreferReduceTypeParameter(_) => 273usize, - Self::TypescriptPreferReturnThisType(_) => 274usize, - Self::TypescriptPreferTsExpectError(_) => 275usize, - Self::TypescriptPromiseFunctionAsync(_) => 276usize, - Self::TypescriptRelatedGetterSetterPairs(_) => 277usize, - Self::TypescriptRequireArraySortCompare(_) => 278usize, - Self::TypescriptRequireAwait(_) => 279usize, - Self::TypescriptRestrictPlusOperands(_) => 280usize, - Self::TypescriptRestrictTemplateExpressions(_) => 281usize, - Self::TypescriptReturnAwait(_) => 282usize, - Self::TypescriptStrictBooleanExpressions(_) => 283usize, - Self::TypescriptSwitchExhaustivenessCheck(_) => 284usize, - Self::TypescriptTripleSlashReference(_) => 285usize, - Self::TypescriptUnboundMethod(_) => 286usize, - Self::TypescriptUseUnknownInCatchCallbackVariable(_) => 287usize, - Self::JestConsistentTestIt(_) => 288usize, - Self::JestExpectExpect(_) => 289usize, - Self::JestMaxExpects(_) => 290usize, - Self::JestMaxNestedDescribe(_) => 291usize, - Self::JestNoAliasMethods(_) => 292usize, - Self::JestNoCommentedOutTests(_) => 293usize, - Self::JestNoConditionalExpect(_) => 294usize, - Self::JestNoConditionalInTest(_) => 295usize, - Self::JestNoConfusingSetTimeout(_) => 296usize, - Self::JestNoDeprecatedFunctions(_) => 297usize, - Self::JestNoDisabledTests(_) => 298usize, - Self::JestNoDoneCallback(_) => 299usize, - Self::JestNoDuplicateHooks(_) => 300usize, - Self::JestNoExport(_) => 301usize, - Self::JestNoFocusedTests(_) => 302usize, - Self::JestNoHooks(_) => 303usize, - Self::JestNoIdenticalTitle(_) => 304usize, - Self::JestNoInterpolationInSnapshots(_) => 305usize, - Self::JestNoJasmineGlobals(_) => 306usize, - Self::JestNoLargeSnapshots(_) => 307usize, - Self::JestNoMocksImport(_) => 308usize, - Self::JestNoRestrictedJestMethods(_) => 309usize, - Self::JestNoRestrictedMatchers(_) => 310usize, - Self::JestNoStandaloneExpect(_) => 311usize, - Self::JestNoTestPrefixes(_) => 312usize, - Self::JestNoTestReturnStatement(_) => 313usize, - Self::JestNoUnneededAsyncExpectFunction(_) => 314usize, - Self::JestNoUntypedMockFactory(_) => 315usize, - Self::JestPaddingAroundTestBlocks(_) => 316usize, - Self::JestPreferCalledWith(_) => 317usize, - Self::JestPreferComparisonMatcher(_) => 318usize, - Self::JestPreferEach(_) => 319usize, - Self::JestPreferEqualityMatcher(_) => 320usize, - Self::JestPreferExpectResolves(_) => 321usize, - Self::JestPreferHooksInOrder(_) => 322usize, - Self::JestPreferHooksOnTop(_) => 323usize, - Self::JestPreferJestMocked(_) => 324usize, - Self::JestPreferLowercaseTitle(_) => 325usize, - Self::JestPreferMockPromiseShorthand(_) => 326usize, - Self::JestPreferSpyOn(_) => 327usize, - Self::JestPreferStrictEqual(_) => 328usize, - Self::JestPreferToBe(_) => 329usize, - Self::JestPreferToContain(_) => 330usize, - Self::JestPreferToHaveBeenCalled(_) => 331usize, - Self::JestPreferToHaveBeenCalledTimes(_) => 332usize, - Self::JestPreferToHaveLength(_) => 333usize, - Self::JestPreferTodo(_) => 334usize, - Self::JestRequireHook(_) => 335usize, - Self::JestRequireToThrowMessage(_) => 336usize, - Self::JestRequireTopLevelDescribe(_) => 337usize, - Self::JestValidDescribeCallback(_) => 338usize, - Self::JestValidExpect(_) => 339usize, - Self::JestValidTitle(_) => 340usize, - Self::ReactButtonHasType(_) => 341usize, - Self::ReactCheckedRequiresOnchangeOrReadonly(_) => 342usize, - Self::ReactDisplayName(_) => 343usize, - Self::ReactExhaustiveDeps(_) => 344usize, - Self::ReactForbidDomProps(_) => 345usize, - Self::ReactForbidElements(_) => 346usize, - Self::ReactForwardRefUsesRef(_) => 347usize, - Self::ReactIframeMissingSandbox(_) => 348usize, - Self::ReactJsxBooleanValue(_) => 349usize, - Self::ReactJsxCurlyBracePresence(_) => 350usize, - Self::ReactJsxFilenameExtension(_) => 351usize, - Self::ReactJsxFragments(_) => 352usize, - Self::ReactJsxHandlerNames(_) => 353usize, - Self::ReactJsxKey(_) => 354usize, - Self::ReactJsxMaxDepth(_) => 355usize, - Self::ReactJsxNoCommentTextnodes(_) => 356usize, - Self::ReactJsxNoDuplicateProps(_) => 357usize, - Self::ReactJsxNoScriptUrl(_) => 358usize, - Self::ReactJsxNoTargetBlank(_) => 359usize, - Self::ReactJsxNoUndef(_) => 360usize, - Self::ReactJsxNoUselessFragment(_) => 361usize, - Self::ReactJsxPascalCase(_) => 362usize, - Self::ReactJsxPropsNoSpreadMulti(_) => 363usize, - Self::ReactJsxPropsNoSpreading(_) => 364usize, - Self::ReactNoArrayIndexKey(_) => 365usize, - Self::ReactNoChildrenProp(_) => 366usize, - Self::ReactNoDanger(_) => 367usize, - Self::ReactNoDangerWithChildren(_) => 368usize, - Self::ReactNoDidMountSetState(_) => 369usize, - Self::ReactNoDirectMutationState(_) => 370usize, - Self::ReactNoFindDomNode(_) => 371usize, - Self::ReactNoIsMounted(_) => 372usize, - Self::ReactNoMultiComp(_) => 373usize, - Self::ReactNoNamespace(_) => 374usize, - Self::ReactNoRedundantShouldComponentUpdate(_) => 375usize, - Self::ReactNoRenderReturnValue(_) => 376usize, - Self::ReactNoSetState(_) => 377usize, - Self::ReactNoStringRefs(_) => 378usize, - Self::ReactNoThisInSfc(_) => 379usize, - Self::ReactNoUnescapedEntities(_) => 380usize, - Self::ReactNoUnknownProperty(_) => 381usize, - Self::ReactNoUnsafe(_) => 382usize, - Self::ReactNoWillUpdateSetState(_) => 383usize, - Self::ReactOnlyExportComponents(_) => 384usize, - Self::ReactPreferEs6Class(_) => 385usize, - Self::ReactReactInJsxScope(_) => 386usize, - Self::ReactRequireRenderReturn(_) => 387usize, - Self::ReactRulesOfHooks(_) => 388usize, - Self::ReactSelfClosingComp(_) => 389usize, - Self::ReactStateInConstructor(_) => 390usize, - Self::ReactStylePropObject(_) => 391usize, - Self::ReactVoidDomElementsNoChildren(_) => 392usize, - Self::ReactPerfJsxNoJsxAsProp(_) => 393usize, - Self::ReactPerfJsxNoNewArrayAsProp(_) => 394usize, - Self::ReactPerfJsxNoNewFunctionAsProp(_) => 395usize, - Self::ReactPerfJsxNoNewObjectAsProp(_) => 396usize, - Self::UnicornCatchErrorName(_) => 397usize, - Self::UnicornConsistentAssert(_) => 398usize, - Self::UnicornConsistentDateClone(_) => 399usize, - Self::UnicornConsistentEmptyArraySpread(_) => 400usize, - Self::UnicornConsistentExistenceIndexCheck(_) => 401usize, - Self::UnicornConsistentFunctionScoping(_) => 402usize, - Self::UnicornEmptyBraceSpaces(_) => 403usize, - Self::UnicornErrorMessage(_) => 404usize, - Self::UnicornEscapeCase(_) => 405usize, - Self::UnicornExplicitLengthCheck(_) => 406usize, - Self::UnicornFilenameCase(_) => 407usize, - Self::UnicornNewForBuiltins(_) => 408usize, - Self::UnicornNoAbusiveEslintDisable(_) => 409usize, - Self::UnicornNoAccessorRecursion(_) => 410usize, - Self::UnicornNoAnonymousDefaultExport(_) => 411usize, - Self::UnicornNoArrayCallbackReference(_) => 412usize, - Self::UnicornNoArrayForEach(_) => 413usize, - Self::UnicornNoArrayMethodThisArgument(_) => 414usize, - Self::UnicornNoArrayReduce(_) => 415usize, - Self::UnicornNoArrayReverse(_) => 416usize, - Self::UnicornNoArraySort(_) => 417usize, - Self::UnicornNoAwaitExpressionMember(_) => 418usize, - Self::UnicornNoAwaitInPromiseMethods(_) => 419usize, - Self::UnicornNoConsoleSpaces(_) => 420usize, - Self::UnicornNoDocumentCookie(_) => 421usize, - Self::UnicornNoEmptyFile(_) => 422usize, - Self::UnicornNoHexEscape(_) => 423usize, - Self::UnicornNoImmediateMutation(_) => 424usize, - Self::UnicornNoInstanceofArray(_) => 425usize, - Self::UnicornNoInstanceofBuiltins(_) => 426usize, - Self::UnicornNoInvalidFetchOptions(_) => 427usize, - Self::UnicornNoInvalidRemoveEventListener(_) => 428usize, - Self::UnicornNoLengthAsSliceEnd(_) => 429usize, - Self::UnicornNoLonelyIf(_) => 430usize, - Self::UnicornNoMagicArrayFlatDepth(_) => 431usize, - Self::UnicornNoNegationInEqualityCheck(_) => 432usize, - Self::UnicornNoNestedTernary(_) => 433usize, - Self::UnicornNoNewArray(_) => 434usize, - Self::UnicornNoNewBuffer(_) => 435usize, - Self::UnicornNoNull(_) => 436usize, - Self::UnicornNoObjectAsDefaultParameter(_) => 437usize, - Self::UnicornNoProcessExit(_) => 438usize, - Self::UnicornNoSinglePromiseInPromiseMethods(_) => 439usize, - Self::UnicornNoStaticOnlyClass(_) => 440usize, - Self::UnicornNoThenable(_) => 441usize, - Self::UnicornNoThisAssignment(_) => 442usize, - Self::UnicornNoTypeofUndefined(_) => 443usize, - Self::UnicornNoUnnecessaryArrayFlatDepth(_) => 444usize, - Self::UnicornNoUnnecessaryArraySpliceCount(_) => 445usize, - Self::UnicornNoUnnecessaryAwait(_) => 446usize, - Self::UnicornNoUnnecessarySliceEnd(_) => 447usize, - Self::UnicornNoUnreadableArrayDestructuring(_) => 448usize, - Self::UnicornNoUnreadableIife(_) => 449usize, - Self::UnicornNoUselessCollectionArgument(_) => 450usize, - Self::UnicornNoUselessErrorCaptureStackTrace(_) => 451usize, - Self::UnicornNoUselessFallbackInSpread(_) => 452usize, - Self::UnicornNoUselessLengthCheck(_) => 453usize, - Self::UnicornNoUselessPromiseResolveReject(_) => 454usize, - Self::UnicornNoUselessSpread(_) => 455usize, - Self::UnicornNoUselessSwitchCase(_) => 456usize, - Self::UnicornNoUselessUndefined(_) => 457usize, - Self::UnicornNoZeroFractions(_) => 458usize, - Self::UnicornNumberLiteralCase(_) => 459usize, - Self::UnicornNumericSeparatorsStyle(_) => 460usize, - Self::UnicornPreferAddEventListener(_) => 461usize, - Self::UnicornPreferArrayFind(_) => 462usize, - Self::UnicornPreferArrayFlat(_) => 463usize, - Self::UnicornPreferArrayFlatMap(_) => 464usize, - Self::UnicornPreferArrayIndexOf(_) => 465usize, - Self::UnicornPreferArraySome(_) => 466usize, - Self::UnicornPreferAt(_) => 467usize, - Self::UnicornPreferBigintLiterals(_) => 468usize, - Self::UnicornPreferBlobReadingMethods(_) => 469usize, - Self::UnicornPreferClassFields(_) => 470usize, - Self::UnicornPreferClasslistToggle(_) => 471usize, - Self::UnicornPreferCodePoint(_) => 472usize, - Self::UnicornPreferDateNow(_) => 473usize, - Self::UnicornPreferDefaultParameters(_) => 474usize, - Self::UnicornPreferDomNodeAppend(_) => 475usize, - Self::UnicornPreferDomNodeDataset(_) => 476usize, - Self::UnicornPreferDomNodeRemove(_) => 477usize, - Self::UnicornPreferDomNodeTextContent(_) => 478usize, - Self::UnicornPreferEventTarget(_) => 479usize, - Self::UnicornPreferGlobalThis(_) => 480usize, - Self::UnicornPreferIncludes(_) => 481usize, - Self::UnicornPreferKeyboardEventKey(_) => 482usize, - Self::UnicornPreferLogicalOperatorOverTernary(_) => 483usize, - Self::UnicornPreferMathMinMax(_) => 484usize, - Self::UnicornPreferMathTrunc(_) => 485usize, - Self::UnicornPreferModernDomApis(_) => 486usize, - Self::UnicornPreferModernMathApis(_) => 487usize, - Self::UnicornPreferNativeCoercionFunctions(_) => 488usize, - Self::UnicornPreferNegativeIndex(_) => 489usize, - Self::UnicornPreferNodeProtocol(_) => 490usize, - Self::UnicornPreferNumberProperties(_) => 491usize, - Self::UnicornPreferObjectFromEntries(_) => 492usize, - Self::UnicornPreferOptionalCatchBinding(_) => 493usize, - Self::UnicornPreferPrototypeMethods(_) => 494usize, - Self::UnicornPreferQuerySelector(_) => 495usize, - Self::UnicornPreferReflectApply(_) => 496usize, - Self::UnicornPreferRegexpTest(_) => 497usize, - Self::UnicornPreferResponseStaticJson(_) => 498usize, - Self::UnicornPreferSetHas(_) => 499usize, - Self::UnicornPreferSetSize(_) => 500usize, - Self::UnicornPreferSpread(_) => 501usize, - Self::UnicornPreferStringRaw(_) => 502usize, - Self::UnicornPreferStringReplaceAll(_) => 503usize, - Self::UnicornPreferStringSlice(_) => 504usize, - Self::UnicornPreferStringStartsEndsWith(_) => 505usize, - Self::UnicornPreferStringTrimStartEnd(_) => 506usize, - Self::UnicornPreferStructuredClone(_) => 507usize, - Self::UnicornPreferTopLevelAwait(_) => 508usize, - Self::UnicornPreferTypeError(_) => 509usize, - Self::UnicornRelativeUrlStyle(_) => 510usize, - Self::UnicornRequireArrayJoinSeparator(_) => 511usize, - Self::UnicornRequireModuleAttributes(_) => 512usize, - Self::UnicornRequireModuleSpecifiers(_) => 513usize, - Self::UnicornRequireNumberToFixedDigitsArgument(_) => 514usize, - Self::UnicornRequirePostMessageTargetOrigin(_) => 515usize, - Self::UnicornSwitchCaseBraces(_) => 516usize, - Self::UnicornTextEncodingIdentifierCase(_) => 517usize, - Self::UnicornThrowNewError(_) => 518usize, - Self::JsxA11YAltText(_) => 519usize, - Self::JsxA11YAnchorAmbiguousText(_) => 520usize, - Self::JsxA11YAnchorHasContent(_) => 521usize, - Self::JsxA11YAnchorIsValid(_) => 522usize, - Self::JsxA11YAriaActivedescendantHasTabindex(_) => 523usize, - Self::JsxA11YAriaProps(_) => 524usize, - Self::JsxA11YAriaProptypes(_) => 525usize, - Self::JsxA11YAriaRole(_) => 526usize, - Self::JsxA11YAriaUnsupportedElements(_) => 527usize, - Self::JsxA11YAutocompleteValid(_) => 528usize, - Self::JsxA11YClickEventsHaveKeyEvents(_) => 529usize, - Self::JsxA11YHeadingHasContent(_) => 530usize, - Self::JsxA11YHtmlHasLang(_) => 531usize, - Self::JsxA11YIframeHasTitle(_) => 532usize, - Self::JsxA11YImgRedundantAlt(_) => 533usize, - Self::JsxA11YLabelHasAssociatedControl(_) => 534usize, - Self::JsxA11YLang(_) => 535usize, - Self::JsxA11YMediaHasCaption(_) => 536usize, - Self::JsxA11YMouseEventsHaveKeyEvents(_) => 537usize, - Self::JsxA11YNoAccessKey(_) => 538usize, - Self::JsxA11YNoAriaHiddenOnFocusable(_) => 539usize, - Self::JsxA11YNoAutofocus(_) => 540usize, - Self::JsxA11YNoDistractingElements(_) => 541usize, - Self::JsxA11YNoNoninteractiveTabindex(_) => 542usize, - Self::JsxA11YNoRedundantRoles(_) => 543usize, - Self::JsxA11YNoStaticElementInteractions(_) => 544usize, - Self::JsxA11YPreferTagOverRole(_) => 545usize, - Self::JsxA11YRoleHasRequiredAriaProps(_) => 546usize, - Self::JsxA11YRoleSupportsAriaProps(_) => 547usize, - Self::JsxA11YScope(_) => 548usize, - Self::JsxA11YTabindexNoPositive(_) => 549usize, - Self::OxcApproxConstant(_) => 550usize, - Self::OxcBadArrayMethodOnArguments(_) => 551usize, - Self::OxcBadBitwiseOperator(_) => 552usize, - Self::OxcBadCharAtComparison(_) => 553usize, - Self::OxcBadComparisonSequence(_) => 554usize, - Self::OxcBadMinMaxFunc(_) => 555usize, - Self::OxcBadObjectLiteralComparison(_) => 556usize, - Self::OxcBadReplaceAllArg(_) => 557usize, - Self::OxcBranchesSharingCode(_) => 558usize, - Self::OxcConstComparisons(_) => 559usize, - Self::OxcDoubleComparisons(_) => 560usize, - Self::OxcErasingOp(_) => 561usize, - Self::OxcMisrefactoredAssignOp(_) => 562usize, - Self::OxcMissingThrow(_) => 563usize, - Self::OxcNoAccumulatingSpread(_) => 564usize, - Self::OxcNoAsyncAwait(_) => 565usize, - Self::OxcNoAsyncEndpointHandlers(_) => 566usize, - Self::OxcNoBarrelFile(_) => 567usize, - Self::OxcNoConstEnum(_) => 568usize, - Self::OxcNoMapSpread(_) => 569usize, - Self::OxcNoOptionalChaining(_) => 570usize, - Self::OxcNoRestSpreadProperties(_) => 571usize, - Self::OxcNoThisInExportedFunction(_) => 572usize, - Self::OxcNumberArgOutOfRange(_) => 573usize, - Self::OxcOnlyUsedInRecursion(_) => 574usize, - Self::OxcUninvokedArrayCallback(_) => 575usize, - Self::NextjsGoogleFontDisplay(_) => 576usize, - Self::NextjsGoogleFontPreconnect(_) => 577usize, - Self::NextjsInlineScriptId(_) => 578usize, - Self::NextjsNextScriptForGa(_) => 579usize, - Self::NextjsNoAssignModuleVariable(_) => 580usize, - Self::NextjsNoAsyncClientComponent(_) => 581usize, - Self::NextjsNoBeforeInteractiveScriptOutsideDocument(_) => 582usize, - Self::NextjsNoCssTags(_) => 583usize, - Self::NextjsNoDocumentImportInPage(_) => 584usize, - Self::NextjsNoDuplicateHead(_) => 585usize, - Self::NextjsNoHeadElement(_) => 586usize, - Self::NextjsNoHeadImportInDocument(_) => 587usize, - Self::NextjsNoHtmlLinkForPages(_) => 588usize, - Self::NextjsNoImgElement(_) => 589usize, - Self::NextjsNoPageCustomFont(_) => 590usize, - Self::NextjsNoScriptComponentInHead(_) => 591usize, - Self::NextjsNoStyledJsxInDocument(_) => 592usize, - Self::NextjsNoSyncScripts(_) => 593usize, - Self::NextjsNoTitleInDocumentHead(_) => 594usize, - Self::NextjsNoTypos(_) => 595usize, - Self::NextjsNoUnwantedPolyfillio(_) => 596usize, - Self::JsdocCheckAccess(_) => 597usize, - Self::JsdocCheckPropertyNames(_) => 598usize, - Self::JsdocCheckTagNames(_) => 599usize, - Self::JsdocEmptyTags(_) => 600usize, - Self::JsdocImplementsOnClasses(_) => 601usize, - Self::JsdocNoDefaults(_) => 602usize, - Self::JsdocRequireParam(_) => 603usize, - Self::JsdocRequireParamDescription(_) => 604usize, - Self::JsdocRequireParamName(_) => 605usize, - Self::JsdocRequireParamType(_) => 606usize, - Self::JsdocRequireProperty(_) => 607usize, - Self::JsdocRequirePropertyDescription(_) => 608usize, - Self::JsdocRequirePropertyName(_) => 609usize, - Self::JsdocRequirePropertyType(_) => 610usize, - Self::JsdocRequireReturns(_) => 611usize, - Self::JsdocRequireReturnsDescription(_) => 612usize, - Self::JsdocRequireReturnsType(_) => 613usize, - Self::JsdocRequireYields(_) => 614usize, - Self::PromiseAlwaysReturn(_) => 615usize, - Self::PromiseAvoidNew(_) => 616usize, - Self::PromiseCatchOrReturn(_) => 617usize, - Self::PromiseNoCallbackInPromise(_) => 618usize, - Self::PromiseNoMultipleResolved(_) => 619usize, - Self::PromiseNoNesting(_) => 620usize, - Self::PromiseNoNewStatics(_) => 621usize, - Self::PromiseNoPromiseInCallback(_) => 622usize, - Self::PromiseNoReturnInFinally(_) => 623usize, - Self::PromiseNoReturnWrap(_) => 624usize, - Self::PromiseParamNames(_) => 625usize, - Self::PromisePreferAwaitToCallbacks(_) => 626usize, - Self::PromisePreferAwaitToThen(_) => 627usize, - Self::PromisePreferCatch(_) => 628usize, - Self::PromiseSpecOnly(_) => 629usize, - Self::PromiseValidParams(_) => 630usize, - Self::VitestConsistentEachFor(_) => 631usize, - Self::VitestConsistentTestFilename(_) => 632usize, - Self::VitestConsistentVitestVi(_) => 633usize, - Self::VitestHoistedApisOnTop(_) => 634usize, - Self::VitestNoConditionalTests(_) => 635usize, - Self::VitestNoImportNodeTest(_) => 636usize, - Self::VitestPreferCalledOnce(_) => 637usize, - Self::VitestPreferCalledTimes(_) => 638usize, - Self::VitestPreferDescribeFunctionTitle(_) => 639usize, - Self::VitestPreferExpectTypeOf(_) => 640usize, - Self::VitestPreferToBeFalsy(_) => 641usize, - Self::VitestPreferToBeObject(_) => 642usize, - Self::VitestPreferToBeTruthy(_) => 643usize, - Self::VitestRequireLocalTestContextForConcurrentSnapshots(_) => 644usize, - Self::VitestWarnTodo(_) => 645usize, - Self::NodeGlobalRequire(_) => 646usize, - Self::NodeNoExportsAssign(_) => 647usize, - Self::NodeNoNewRequire(_) => 648usize, - Self::NodeNoProcessEnv(_) => 649usize, - Self::VueDefineEmitsDeclaration(_) => 650usize, - Self::VueDefinePropsDeclaration(_) => 651usize, - Self::VueDefinePropsDestructuring(_) => 652usize, - Self::VueMaxProps(_) => 653usize, - Self::VueNoArrowFunctionsInWatch(_) => 654usize, - Self::VueNoDeprecatedDestroyedLifecycle(_) => 655usize, - Self::VueNoExportInScriptSetup(_) => 656usize, - Self::VueNoImportCompilerMacros(_) => 657usize, - Self::VueNoLifecycleAfterAwait(_) => 658usize, - Self::VueNoMultipleSlotArgs(_) => 659usize, - Self::VueNoRequiredPropWithDefault(_) => 660usize, - Self::VueNoThisInBeforeRouteEnter(_) => 661usize, - Self::VuePreferImportFromVue(_) => 662usize, - Self::VueRequireDefaultExport(_) => 663usize, - Self::VueRequireTypedRef(_) => 664usize, - Self::VueValidDefineEmits(_) => 665usize, - Self::VueValidDefineProps(_) => 666usize, + Self::TypescriptConsistentTypeAssertions(_) => 207usize, + Self::TypescriptConsistentTypeDefinitions(_) => 208usize, + Self::TypescriptConsistentTypeImports(_) => 209usize, + Self::TypescriptExplicitFunctionReturnType(_) => 210usize, + Self::TypescriptExplicitModuleBoundaryTypes(_) => 211usize, + Self::TypescriptNoArrayDelete(_) => 212usize, + Self::TypescriptNoBaseToString(_) => 213usize, + Self::TypescriptNoConfusingNonNullAssertion(_) => 214usize, + Self::TypescriptNoConfusingVoidExpression(_) => 215usize, + Self::TypescriptNoDeprecated(_) => 216usize, + Self::TypescriptNoDuplicateEnumValues(_) => 217usize, + Self::TypescriptNoDuplicateTypeConstituents(_) => 218usize, + Self::TypescriptNoDynamicDelete(_) => 219usize, + Self::TypescriptNoEmptyInterface(_) => 220usize, + Self::TypescriptNoEmptyObjectType(_) => 221usize, + Self::TypescriptNoExplicitAny(_) => 222usize, + Self::TypescriptNoExtraNonNullAssertion(_) => 223usize, + Self::TypescriptNoExtraneousClass(_) => 224usize, + Self::TypescriptNoFloatingPromises(_) => 225usize, + Self::TypescriptNoForInArray(_) => 226usize, + Self::TypescriptNoImpliedEval(_) => 227usize, + Self::TypescriptNoImportTypeSideEffects(_) => 228usize, + Self::TypescriptNoInferrableTypes(_) => 229usize, + Self::TypescriptNoMeaninglessVoidOperator(_) => 230usize, + Self::TypescriptNoMisusedNew(_) => 231usize, + Self::TypescriptNoMisusedPromises(_) => 232usize, + Self::TypescriptNoMisusedSpread(_) => 233usize, + Self::TypescriptNoMixedEnums(_) => 234usize, + Self::TypescriptNoNamespace(_) => 235usize, + Self::TypescriptNoNonNullAssertedNullishCoalescing(_) => 236usize, + Self::TypescriptNoNonNullAssertedOptionalChain(_) => 237usize, + Self::TypescriptNoNonNullAssertion(_) => 238usize, + Self::TypescriptNoRedundantTypeConstituents(_) => 239usize, + Self::TypescriptNoRequireImports(_) => 240usize, + Self::TypescriptNoRestrictedTypes(_) => 241usize, + Self::TypescriptNoThisAlias(_) => 242usize, + Self::TypescriptNoUnnecessaryBooleanLiteralCompare(_) => 243usize, + Self::TypescriptNoUnnecessaryParameterPropertyAssignment(_) => 244usize, + Self::TypescriptNoUnnecessaryTemplateExpression(_) => 245usize, + Self::TypescriptNoUnnecessaryTypeArguments(_) => 246usize, + Self::TypescriptNoUnnecessaryTypeAssertion(_) => 247usize, + Self::TypescriptNoUnnecessaryTypeConstraint(_) => 248usize, + Self::TypescriptNoUnsafeArgument(_) => 249usize, + Self::TypescriptNoUnsafeAssignment(_) => 250usize, + Self::TypescriptNoUnsafeCall(_) => 251usize, + Self::TypescriptNoUnsafeDeclarationMerging(_) => 252usize, + Self::TypescriptNoUnsafeEnumComparison(_) => 253usize, + Self::TypescriptNoUnsafeFunctionType(_) => 254usize, + Self::TypescriptNoUnsafeMemberAccess(_) => 255usize, + Self::TypescriptNoUnsafeReturn(_) => 256usize, + Self::TypescriptNoUnsafeTypeAssertion(_) => 257usize, + Self::TypescriptNoUnsafeUnaryMinus(_) => 258usize, + Self::TypescriptNoUselessEmptyExport(_) => 259usize, + Self::TypescriptNoVarRequires(_) => 260usize, + Self::TypescriptNoWrapperObjectTypes(_) => 261usize, + Self::TypescriptNonNullableTypeAssertionStyle(_) => 262usize, + Self::TypescriptOnlyThrowError(_) => 263usize, + Self::TypescriptPreferAsConst(_) => 264usize, + Self::TypescriptPreferEnumInitializers(_) => 265usize, + Self::TypescriptPreferForOf(_) => 266usize, + Self::TypescriptPreferFunctionType(_) => 267usize, + Self::TypescriptPreferIncludes(_) => 268usize, + Self::TypescriptPreferLiteralEnumMember(_) => 269usize, + Self::TypescriptPreferNamespaceKeyword(_) => 270usize, + Self::TypescriptPreferNullishCoalescing(_) => 271usize, + Self::TypescriptPreferOptionalChain(_) => 272usize, + Self::TypescriptPreferPromiseRejectErrors(_) => 273usize, + Self::TypescriptPreferReduceTypeParameter(_) => 274usize, + Self::TypescriptPreferReturnThisType(_) => 275usize, + Self::TypescriptPreferTsExpectError(_) => 276usize, + Self::TypescriptPromiseFunctionAsync(_) => 277usize, + Self::TypescriptRelatedGetterSetterPairs(_) => 278usize, + Self::TypescriptRequireArraySortCompare(_) => 279usize, + Self::TypescriptRequireAwait(_) => 280usize, + Self::TypescriptRestrictPlusOperands(_) => 281usize, + Self::TypescriptRestrictTemplateExpressions(_) => 282usize, + Self::TypescriptReturnAwait(_) => 283usize, + Self::TypescriptStrictBooleanExpressions(_) => 284usize, + Self::TypescriptSwitchExhaustivenessCheck(_) => 285usize, + Self::TypescriptTripleSlashReference(_) => 286usize, + Self::TypescriptUnboundMethod(_) => 287usize, + Self::TypescriptUseUnknownInCatchCallbackVariable(_) => 288usize, + Self::JestConsistentTestIt(_) => 289usize, + Self::JestExpectExpect(_) => 290usize, + Self::JestMaxExpects(_) => 291usize, + Self::JestMaxNestedDescribe(_) => 292usize, + Self::JestNoAliasMethods(_) => 293usize, + Self::JestNoCommentedOutTests(_) => 294usize, + Self::JestNoConditionalExpect(_) => 295usize, + Self::JestNoConditionalInTest(_) => 296usize, + Self::JestNoConfusingSetTimeout(_) => 297usize, + Self::JestNoDeprecatedFunctions(_) => 298usize, + Self::JestNoDisabledTests(_) => 299usize, + Self::JestNoDoneCallback(_) => 300usize, + Self::JestNoDuplicateHooks(_) => 301usize, + Self::JestNoExport(_) => 302usize, + Self::JestNoFocusedTests(_) => 303usize, + Self::JestNoHooks(_) => 304usize, + Self::JestNoIdenticalTitle(_) => 305usize, + Self::JestNoInterpolationInSnapshots(_) => 306usize, + Self::JestNoJasmineGlobals(_) => 307usize, + Self::JestNoLargeSnapshots(_) => 308usize, + Self::JestNoMocksImport(_) => 309usize, + Self::JestNoRestrictedJestMethods(_) => 310usize, + Self::JestNoRestrictedMatchers(_) => 311usize, + Self::JestNoStandaloneExpect(_) => 312usize, + Self::JestNoTestPrefixes(_) => 313usize, + Self::JestNoTestReturnStatement(_) => 314usize, + Self::JestNoUnneededAsyncExpectFunction(_) => 315usize, + Self::JestNoUntypedMockFactory(_) => 316usize, + Self::JestPaddingAroundTestBlocks(_) => 317usize, + Self::JestPreferCalledWith(_) => 318usize, + Self::JestPreferComparisonMatcher(_) => 319usize, + Self::JestPreferEach(_) => 320usize, + Self::JestPreferEqualityMatcher(_) => 321usize, + Self::JestPreferExpectResolves(_) => 322usize, + Self::JestPreferHooksInOrder(_) => 323usize, + Self::JestPreferHooksOnTop(_) => 324usize, + Self::JestPreferJestMocked(_) => 325usize, + Self::JestPreferLowercaseTitle(_) => 326usize, + Self::JestPreferMockPromiseShorthand(_) => 327usize, + Self::JestPreferSpyOn(_) => 328usize, + Self::JestPreferStrictEqual(_) => 329usize, + Self::JestPreferToBe(_) => 330usize, + Self::JestPreferToContain(_) => 331usize, + Self::JestPreferToHaveBeenCalled(_) => 332usize, + Self::JestPreferToHaveBeenCalledTimes(_) => 333usize, + Self::JestPreferToHaveLength(_) => 334usize, + Self::JestPreferTodo(_) => 335usize, + Self::JestRequireHook(_) => 336usize, + Self::JestRequireToThrowMessage(_) => 337usize, + Self::JestRequireTopLevelDescribe(_) => 338usize, + Self::JestValidDescribeCallback(_) => 339usize, + Self::JestValidExpect(_) => 340usize, + Self::JestValidTitle(_) => 341usize, + Self::ReactButtonHasType(_) => 342usize, + Self::ReactCheckedRequiresOnchangeOrReadonly(_) => 343usize, + Self::ReactDisplayName(_) => 344usize, + Self::ReactExhaustiveDeps(_) => 345usize, + Self::ReactForbidDomProps(_) => 346usize, + Self::ReactForbidElements(_) => 347usize, + Self::ReactForwardRefUsesRef(_) => 348usize, + Self::ReactIframeMissingSandbox(_) => 349usize, + Self::ReactJsxBooleanValue(_) => 350usize, + Self::ReactJsxCurlyBracePresence(_) => 351usize, + Self::ReactJsxFilenameExtension(_) => 352usize, + Self::ReactJsxFragments(_) => 353usize, + Self::ReactJsxHandlerNames(_) => 354usize, + Self::ReactJsxKey(_) => 355usize, + Self::ReactJsxMaxDepth(_) => 356usize, + Self::ReactJsxNoCommentTextnodes(_) => 357usize, + Self::ReactJsxNoDuplicateProps(_) => 358usize, + Self::ReactJsxNoScriptUrl(_) => 359usize, + Self::ReactJsxNoTargetBlank(_) => 360usize, + Self::ReactJsxNoUndef(_) => 361usize, + Self::ReactJsxNoUselessFragment(_) => 362usize, + Self::ReactJsxPascalCase(_) => 363usize, + Self::ReactJsxPropsNoSpreadMulti(_) => 364usize, + Self::ReactJsxPropsNoSpreading(_) => 365usize, + Self::ReactNoArrayIndexKey(_) => 366usize, + Self::ReactNoChildrenProp(_) => 367usize, + Self::ReactNoDanger(_) => 368usize, + Self::ReactNoDangerWithChildren(_) => 369usize, + Self::ReactNoDidMountSetState(_) => 370usize, + Self::ReactNoDirectMutationState(_) => 371usize, + Self::ReactNoFindDomNode(_) => 372usize, + Self::ReactNoIsMounted(_) => 373usize, + Self::ReactNoMultiComp(_) => 374usize, + Self::ReactNoNamespace(_) => 375usize, + Self::ReactNoRedundantShouldComponentUpdate(_) => 376usize, + Self::ReactNoRenderReturnValue(_) => 377usize, + Self::ReactNoSetState(_) => 378usize, + Self::ReactNoStringRefs(_) => 379usize, + Self::ReactNoThisInSfc(_) => 380usize, + Self::ReactNoUnescapedEntities(_) => 381usize, + Self::ReactNoUnknownProperty(_) => 382usize, + Self::ReactNoUnsafe(_) => 383usize, + Self::ReactNoWillUpdateSetState(_) => 384usize, + Self::ReactOnlyExportComponents(_) => 385usize, + Self::ReactPreferEs6Class(_) => 386usize, + Self::ReactReactInJsxScope(_) => 387usize, + Self::ReactRequireRenderReturn(_) => 388usize, + Self::ReactRulesOfHooks(_) => 389usize, + Self::ReactSelfClosingComp(_) => 390usize, + Self::ReactStateInConstructor(_) => 391usize, + Self::ReactStylePropObject(_) => 392usize, + Self::ReactVoidDomElementsNoChildren(_) => 393usize, + Self::ReactPerfJsxNoJsxAsProp(_) => 394usize, + Self::ReactPerfJsxNoNewArrayAsProp(_) => 395usize, + Self::ReactPerfJsxNoNewFunctionAsProp(_) => 396usize, + Self::ReactPerfJsxNoNewObjectAsProp(_) => 397usize, + Self::UnicornCatchErrorName(_) => 398usize, + Self::UnicornConsistentAssert(_) => 399usize, + Self::UnicornConsistentDateClone(_) => 400usize, + Self::UnicornConsistentEmptyArraySpread(_) => 401usize, + Self::UnicornConsistentExistenceIndexCheck(_) => 402usize, + Self::UnicornConsistentFunctionScoping(_) => 403usize, + Self::UnicornEmptyBraceSpaces(_) => 404usize, + Self::UnicornErrorMessage(_) => 405usize, + Self::UnicornEscapeCase(_) => 406usize, + Self::UnicornExplicitLengthCheck(_) => 407usize, + Self::UnicornFilenameCase(_) => 408usize, + Self::UnicornNewForBuiltins(_) => 409usize, + Self::UnicornNoAbusiveEslintDisable(_) => 410usize, + Self::UnicornNoAccessorRecursion(_) => 411usize, + Self::UnicornNoAnonymousDefaultExport(_) => 412usize, + Self::UnicornNoArrayCallbackReference(_) => 413usize, + Self::UnicornNoArrayForEach(_) => 414usize, + Self::UnicornNoArrayMethodThisArgument(_) => 415usize, + Self::UnicornNoArrayReduce(_) => 416usize, + Self::UnicornNoArrayReverse(_) => 417usize, + Self::UnicornNoArraySort(_) => 418usize, + Self::UnicornNoAwaitExpressionMember(_) => 419usize, + Self::UnicornNoAwaitInPromiseMethods(_) => 420usize, + Self::UnicornNoConsoleSpaces(_) => 421usize, + Self::UnicornNoDocumentCookie(_) => 422usize, + Self::UnicornNoEmptyFile(_) => 423usize, + Self::UnicornNoHexEscape(_) => 424usize, + Self::UnicornNoImmediateMutation(_) => 425usize, + Self::UnicornNoInstanceofArray(_) => 426usize, + Self::UnicornNoInstanceofBuiltins(_) => 427usize, + Self::UnicornNoInvalidFetchOptions(_) => 428usize, + Self::UnicornNoInvalidRemoveEventListener(_) => 429usize, + Self::UnicornNoLengthAsSliceEnd(_) => 430usize, + Self::UnicornNoLonelyIf(_) => 431usize, + Self::UnicornNoMagicArrayFlatDepth(_) => 432usize, + Self::UnicornNoNegationInEqualityCheck(_) => 433usize, + Self::UnicornNoNestedTernary(_) => 434usize, + Self::UnicornNoNewArray(_) => 435usize, + Self::UnicornNoNewBuffer(_) => 436usize, + Self::UnicornNoNull(_) => 437usize, + Self::UnicornNoObjectAsDefaultParameter(_) => 438usize, + Self::UnicornNoProcessExit(_) => 439usize, + Self::UnicornNoSinglePromiseInPromiseMethods(_) => 440usize, + Self::UnicornNoStaticOnlyClass(_) => 441usize, + Self::UnicornNoThenable(_) => 442usize, + Self::UnicornNoThisAssignment(_) => 443usize, + Self::UnicornNoTypeofUndefined(_) => 444usize, + Self::UnicornNoUnnecessaryArrayFlatDepth(_) => 445usize, + Self::UnicornNoUnnecessaryArraySpliceCount(_) => 446usize, + Self::UnicornNoUnnecessaryAwait(_) => 447usize, + Self::UnicornNoUnnecessarySliceEnd(_) => 448usize, + Self::UnicornNoUnreadableArrayDestructuring(_) => 449usize, + Self::UnicornNoUnreadableIife(_) => 450usize, + Self::UnicornNoUselessCollectionArgument(_) => 451usize, + Self::UnicornNoUselessErrorCaptureStackTrace(_) => 452usize, + Self::UnicornNoUselessFallbackInSpread(_) => 453usize, + Self::UnicornNoUselessLengthCheck(_) => 454usize, + Self::UnicornNoUselessPromiseResolveReject(_) => 455usize, + Self::UnicornNoUselessSpread(_) => 456usize, + Self::UnicornNoUselessSwitchCase(_) => 457usize, + Self::UnicornNoUselessUndefined(_) => 458usize, + Self::UnicornNoZeroFractions(_) => 459usize, + Self::UnicornNumberLiteralCase(_) => 460usize, + Self::UnicornNumericSeparatorsStyle(_) => 461usize, + Self::UnicornPreferAddEventListener(_) => 462usize, + Self::UnicornPreferArrayFind(_) => 463usize, + Self::UnicornPreferArrayFlat(_) => 464usize, + Self::UnicornPreferArrayFlatMap(_) => 465usize, + Self::UnicornPreferArrayIndexOf(_) => 466usize, + Self::UnicornPreferArraySome(_) => 467usize, + Self::UnicornPreferAt(_) => 468usize, + Self::UnicornPreferBigintLiterals(_) => 469usize, + Self::UnicornPreferBlobReadingMethods(_) => 470usize, + Self::UnicornPreferClassFields(_) => 471usize, + Self::UnicornPreferClasslistToggle(_) => 472usize, + Self::UnicornPreferCodePoint(_) => 473usize, + Self::UnicornPreferDateNow(_) => 474usize, + Self::UnicornPreferDefaultParameters(_) => 475usize, + Self::UnicornPreferDomNodeAppend(_) => 476usize, + Self::UnicornPreferDomNodeDataset(_) => 477usize, + Self::UnicornPreferDomNodeRemove(_) => 478usize, + Self::UnicornPreferDomNodeTextContent(_) => 479usize, + Self::UnicornPreferEventTarget(_) => 480usize, + Self::UnicornPreferGlobalThis(_) => 481usize, + Self::UnicornPreferIncludes(_) => 482usize, + Self::UnicornPreferKeyboardEventKey(_) => 483usize, + Self::UnicornPreferLogicalOperatorOverTernary(_) => 484usize, + Self::UnicornPreferMathMinMax(_) => 485usize, + Self::UnicornPreferMathTrunc(_) => 486usize, + Self::UnicornPreferModernDomApis(_) => 487usize, + Self::UnicornPreferModernMathApis(_) => 488usize, + Self::UnicornPreferNativeCoercionFunctions(_) => 489usize, + Self::UnicornPreferNegativeIndex(_) => 490usize, + Self::UnicornPreferNodeProtocol(_) => 491usize, + Self::UnicornPreferNumberProperties(_) => 492usize, + Self::UnicornPreferObjectFromEntries(_) => 493usize, + Self::UnicornPreferOptionalCatchBinding(_) => 494usize, + Self::UnicornPreferPrototypeMethods(_) => 495usize, + Self::UnicornPreferQuerySelector(_) => 496usize, + Self::UnicornPreferReflectApply(_) => 497usize, + Self::UnicornPreferRegexpTest(_) => 498usize, + Self::UnicornPreferResponseStaticJson(_) => 499usize, + Self::UnicornPreferSetHas(_) => 500usize, + Self::UnicornPreferSetSize(_) => 501usize, + Self::UnicornPreferSpread(_) => 502usize, + Self::UnicornPreferStringRaw(_) => 503usize, + Self::UnicornPreferStringReplaceAll(_) => 504usize, + Self::UnicornPreferStringSlice(_) => 505usize, + Self::UnicornPreferStringStartsEndsWith(_) => 506usize, + Self::UnicornPreferStringTrimStartEnd(_) => 507usize, + Self::UnicornPreferStructuredClone(_) => 508usize, + Self::UnicornPreferTopLevelAwait(_) => 509usize, + Self::UnicornPreferTypeError(_) => 510usize, + Self::UnicornRelativeUrlStyle(_) => 511usize, + Self::UnicornRequireArrayJoinSeparator(_) => 512usize, + Self::UnicornRequireModuleAttributes(_) => 513usize, + Self::UnicornRequireModuleSpecifiers(_) => 514usize, + Self::UnicornRequireNumberToFixedDigitsArgument(_) => 515usize, + Self::UnicornRequirePostMessageTargetOrigin(_) => 516usize, + Self::UnicornSwitchCaseBraces(_) => 517usize, + Self::UnicornTextEncodingIdentifierCase(_) => 518usize, + Self::UnicornThrowNewError(_) => 519usize, + Self::JsxA11YAltText(_) => 520usize, + Self::JsxA11YAnchorAmbiguousText(_) => 521usize, + Self::JsxA11YAnchorHasContent(_) => 522usize, + Self::JsxA11YAnchorIsValid(_) => 523usize, + Self::JsxA11YAriaActivedescendantHasTabindex(_) => 524usize, + Self::JsxA11YAriaProps(_) => 525usize, + Self::JsxA11YAriaProptypes(_) => 526usize, + Self::JsxA11YAriaRole(_) => 527usize, + Self::JsxA11YAriaUnsupportedElements(_) => 528usize, + Self::JsxA11YAutocompleteValid(_) => 529usize, + Self::JsxA11YClickEventsHaveKeyEvents(_) => 530usize, + Self::JsxA11YHeadingHasContent(_) => 531usize, + Self::JsxA11YHtmlHasLang(_) => 532usize, + Self::JsxA11YIframeHasTitle(_) => 533usize, + Self::JsxA11YImgRedundantAlt(_) => 534usize, + Self::JsxA11YLabelHasAssociatedControl(_) => 535usize, + Self::JsxA11YLang(_) => 536usize, + Self::JsxA11YMediaHasCaption(_) => 537usize, + Self::JsxA11YMouseEventsHaveKeyEvents(_) => 538usize, + Self::JsxA11YNoAccessKey(_) => 539usize, + Self::JsxA11YNoAriaHiddenOnFocusable(_) => 540usize, + Self::JsxA11YNoAutofocus(_) => 541usize, + Self::JsxA11YNoDistractingElements(_) => 542usize, + Self::JsxA11YNoNoninteractiveTabindex(_) => 543usize, + Self::JsxA11YNoRedundantRoles(_) => 544usize, + Self::JsxA11YNoStaticElementInteractions(_) => 545usize, + Self::JsxA11YPreferTagOverRole(_) => 546usize, + Self::JsxA11YRoleHasRequiredAriaProps(_) => 547usize, + Self::JsxA11YRoleSupportsAriaProps(_) => 548usize, + Self::JsxA11YScope(_) => 549usize, + Self::JsxA11YTabindexNoPositive(_) => 550usize, + Self::OxcApproxConstant(_) => 551usize, + Self::OxcBadArrayMethodOnArguments(_) => 552usize, + Self::OxcBadBitwiseOperator(_) => 553usize, + Self::OxcBadCharAtComparison(_) => 554usize, + Self::OxcBadComparisonSequence(_) => 555usize, + Self::OxcBadMinMaxFunc(_) => 556usize, + Self::OxcBadObjectLiteralComparison(_) => 557usize, + Self::OxcBadReplaceAllArg(_) => 558usize, + Self::OxcBranchesSharingCode(_) => 559usize, + Self::OxcConstComparisons(_) => 560usize, + Self::OxcDoubleComparisons(_) => 561usize, + Self::OxcErasingOp(_) => 562usize, + Self::OxcMisrefactoredAssignOp(_) => 563usize, + Self::OxcMissingThrow(_) => 564usize, + Self::OxcNoAccumulatingSpread(_) => 565usize, + Self::OxcNoAsyncAwait(_) => 566usize, + Self::OxcNoAsyncEndpointHandlers(_) => 567usize, + Self::OxcNoBarrelFile(_) => 568usize, + Self::OxcNoConstEnum(_) => 569usize, + Self::OxcNoMapSpread(_) => 570usize, + Self::OxcNoOptionalChaining(_) => 571usize, + Self::OxcNoRestSpreadProperties(_) => 572usize, + Self::OxcNoThisInExportedFunction(_) => 573usize, + Self::OxcNumberArgOutOfRange(_) => 574usize, + Self::OxcOnlyUsedInRecursion(_) => 575usize, + Self::OxcUninvokedArrayCallback(_) => 576usize, + Self::NextjsGoogleFontDisplay(_) => 577usize, + Self::NextjsGoogleFontPreconnect(_) => 578usize, + Self::NextjsInlineScriptId(_) => 579usize, + Self::NextjsNextScriptForGa(_) => 580usize, + Self::NextjsNoAssignModuleVariable(_) => 581usize, + Self::NextjsNoAsyncClientComponent(_) => 582usize, + Self::NextjsNoBeforeInteractiveScriptOutsideDocument(_) => 583usize, + Self::NextjsNoCssTags(_) => 584usize, + Self::NextjsNoDocumentImportInPage(_) => 585usize, + Self::NextjsNoDuplicateHead(_) => 586usize, + Self::NextjsNoHeadElement(_) => 587usize, + Self::NextjsNoHeadImportInDocument(_) => 588usize, + Self::NextjsNoHtmlLinkForPages(_) => 589usize, + Self::NextjsNoImgElement(_) => 590usize, + Self::NextjsNoPageCustomFont(_) => 591usize, + Self::NextjsNoScriptComponentInHead(_) => 592usize, + Self::NextjsNoStyledJsxInDocument(_) => 593usize, + Self::NextjsNoSyncScripts(_) => 594usize, + Self::NextjsNoTitleInDocumentHead(_) => 595usize, + Self::NextjsNoTypos(_) => 596usize, + Self::NextjsNoUnwantedPolyfillio(_) => 597usize, + Self::JsdocCheckAccess(_) => 598usize, + Self::JsdocCheckPropertyNames(_) => 599usize, + Self::JsdocCheckTagNames(_) => 600usize, + Self::JsdocEmptyTags(_) => 601usize, + Self::JsdocImplementsOnClasses(_) => 602usize, + Self::JsdocNoDefaults(_) => 603usize, + Self::JsdocRequireParam(_) => 604usize, + Self::JsdocRequireParamDescription(_) => 605usize, + Self::JsdocRequireParamName(_) => 606usize, + Self::JsdocRequireParamType(_) => 607usize, + Self::JsdocRequireProperty(_) => 608usize, + Self::JsdocRequirePropertyDescription(_) => 609usize, + Self::JsdocRequirePropertyName(_) => 610usize, + Self::JsdocRequirePropertyType(_) => 611usize, + Self::JsdocRequireReturns(_) => 612usize, + Self::JsdocRequireReturnsDescription(_) => 613usize, + Self::JsdocRequireReturnsType(_) => 614usize, + Self::JsdocRequireYields(_) => 615usize, + Self::PromiseAlwaysReturn(_) => 616usize, + Self::PromiseAvoidNew(_) => 617usize, + Self::PromiseCatchOrReturn(_) => 618usize, + Self::PromiseNoCallbackInPromise(_) => 619usize, + Self::PromiseNoMultipleResolved(_) => 620usize, + Self::PromiseNoNesting(_) => 621usize, + Self::PromiseNoNewStatics(_) => 622usize, + Self::PromiseNoPromiseInCallback(_) => 623usize, + Self::PromiseNoReturnInFinally(_) => 624usize, + Self::PromiseNoReturnWrap(_) => 625usize, + Self::PromiseParamNames(_) => 626usize, + Self::PromisePreferAwaitToCallbacks(_) => 627usize, + Self::PromisePreferAwaitToThen(_) => 628usize, + Self::PromisePreferCatch(_) => 629usize, + Self::PromiseSpecOnly(_) => 630usize, + Self::PromiseValidParams(_) => 631usize, + Self::VitestConsistentEachFor(_) => 632usize, + Self::VitestConsistentTestFilename(_) => 633usize, + Self::VitestConsistentVitestVi(_) => 634usize, + Self::VitestHoistedApisOnTop(_) => 635usize, + Self::VitestNoConditionalTests(_) => 636usize, + Self::VitestNoImportNodeTest(_) => 637usize, + Self::VitestPreferCalledOnce(_) => 638usize, + Self::VitestPreferCalledTimes(_) => 639usize, + Self::VitestPreferDescribeFunctionTitle(_) => 640usize, + Self::VitestPreferExpectTypeOf(_) => 641usize, + Self::VitestPreferToBeFalsy(_) => 642usize, + Self::VitestPreferToBeObject(_) => 643usize, + Self::VitestPreferToBeTruthy(_) => 644usize, + Self::VitestRequireLocalTestContextForConcurrentSnapshots(_) => 645usize, + Self::VitestWarnTodo(_) => 646usize, + Self::NodeGlobalRequire(_) => 647usize, + Self::NodeNoExportsAssign(_) => 648usize, + Self::NodeNoNewRequire(_) => 649usize, + Self::NodeNoProcessEnv(_) => 650usize, + Self::VueDefineEmitsDeclaration(_) => 651usize, + Self::VueDefinePropsDeclaration(_) => 652usize, + Self::VueDefinePropsDestructuring(_) => 653usize, + Self::VueMaxProps(_) => 654usize, + Self::VueNoArrowFunctionsInWatch(_) => 655usize, + Self::VueNoDeprecatedDestroyedLifecycle(_) => 656usize, + Self::VueNoExportInScriptSetup(_) => 657usize, + Self::VueNoImportCompilerMacros(_) => 658usize, + Self::VueNoLifecycleAfterAwait(_) => 659usize, + Self::VueNoMultipleSlotArgs(_) => 660usize, + Self::VueNoRequiredPropWithDefault(_) => 661usize, + Self::VueNoThisInBeforeRouteEnter(_) => 662usize, + Self::VuePreferImportFromVue(_) => 663usize, + Self::VueRequireDefaultExport(_) => 664usize, + Self::VueRequireTypedRef(_) => 665usize, + Self::VueValidDefineEmits(_) => 666usize, + Self::VueValidDefineProps(_) => 667usize, } } pub fn name(&self) -> &'static str { @@ -2243,6 +2246,7 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::NAME } + Self::TypescriptConsistentTypeAssertions(_) => TypescriptConsistentTypeAssertions::NAME, Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::NAME } @@ -3004,6 +3008,9 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::CATEGORY } + Self::TypescriptConsistentTypeAssertions(_) => { + TypescriptConsistentTypeAssertions::CATEGORY + } Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::CATEGORY } @@ -3796,6 +3803,7 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::FIX } + Self::TypescriptConsistentTypeAssertions(_) => TypescriptConsistentTypeAssertions::FIX, Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::FIX } @@ -4580,6 +4588,9 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::documentation() } + Self::TypescriptConsistentTypeAssertions(_) => { + TypescriptConsistentTypeAssertions::documentation() + } Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::documentation() } @@ -5800,6 +5811,10 @@ impl RuleEnum { TypescriptConsistentIndexedObjectStyle::config_schema(generator) .or_else(|| TypescriptConsistentIndexedObjectStyle::schema(generator)) } + Self::TypescriptConsistentTypeAssertions(_) => { + TypescriptConsistentTypeAssertions::config_schema(generator) + .or_else(|| TypescriptConsistentTypeAssertions::schema(generator)) + } Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::config_schema(generator) .or_else(|| TypescriptConsistentTypeDefinitions::schema(generator)) @@ -7364,6 +7379,7 @@ impl RuleEnum { Self::TypescriptBanTypes(_) => "typescript", Self::TypescriptConsistentGenericConstructors(_) => "typescript", Self::TypescriptConsistentIndexedObjectStyle(_) => "typescript", + Self::TypescriptConsistentTypeAssertions(_) => "typescript", Self::TypescriptConsistentTypeDefinitions(_) => "typescript", Self::TypescriptConsistentTypeImports(_) => "typescript", Self::TypescriptExplicitFunctionReturnType(_) => "typescript", @@ -8452,6 +8468,11 @@ impl RuleEnum { TypescriptConsistentIndexedObjectStyle::from_configuration(value)?, )) } + Self::TypescriptConsistentTypeAssertions(_) => { + Ok(Self::TypescriptConsistentTypeAssertions( + TypescriptConsistentTypeAssertions::from_configuration(value)?, + )) + } Self::TypescriptConsistentTypeDefinitions(_) => { Ok(Self::TypescriptConsistentTypeDefinitions( TypescriptConsistentTypeDefinitions::from_configuration(value)?, @@ -10167,6 +10188,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.to_configuration(), Self::TypescriptConsistentGenericConstructors(rule) => rule.to_configuration(), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.to_configuration(), + Self::TypescriptConsistentTypeAssertions(rule) => rule.to_configuration(), Self::TypescriptConsistentTypeDefinitions(rule) => rule.to_configuration(), Self::TypescriptConsistentTypeImports(rule) => rule.to_configuration(), Self::TypescriptExplicitFunctionReturnType(rule) => rule.to_configuration(), @@ -10842,6 +10864,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.run(node, ctx), Self::TypescriptConsistentGenericConstructors(rule) => rule.run(node, ctx), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.run(node, ctx), + Self::TypescriptConsistentTypeAssertions(rule) => rule.run(node, ctx), Self::TypescriptConsistentTypeDefinitions(rule) => rule.run(node, ctx), Self::TypescriptConsistentTypeImports(rule) => rule.run(node, ctx), Self::TypescriptExplicitFunctionReturnType(rule) => rule.run(node, ctx), @@ -11513,6 +11536,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.run_once(ctx), Self::TypescriptConsistentGenericConstructors(rule) => rule.run_once(ctx), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.run_once(ctx), + Self::TypescriptConsistentTypeAssertions(rule) => rule.run_once(ctx), Self::TypescriptConsistentTypeDefinitions(rule) => rule.run_once(ctx), Self::TypescriptConsistentTypeImports(rule) => rule.run_once(ctx), Self::TypescriptExplicitFunctionReturnType(rule) => rule.run_once(ctx), @@ -12194,6 +12218,7 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(rule) => { rule.run_on_jest_node(jest_node, ctx) } + Self::TypescriptConsistentTypeAssertions(rule) => rule.run_on_jest_node(jest_node, ctx), Self::TypescriptConsistentTypeDefinitions(rule) => { rule.run_on_jest_node(jest_node, ctx) } @@ -12943,6 +12968,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.should_run(ctx), Self::TypescriptConsistentGenericConstructors(rule) => rule.should_run(ctx), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.should_run(ctx), + Self::TypescriptConsistentTypeAssertions(rule) => rule.should_run(ctx), Self::TypescriptConsistentTypeDefinitions(rule) => rule.should_run(ctx), Self::TypescriptConsistentTypeImports(rule) => rule.should_run(ctx), Self::TypescriptExplicitFunctionReturnType(rule) => rule.should_run(ctx), @@ -13648,6 +13674,9 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::IS_TSGOLINT_RULE } + Self::TypescriptConsistentTypeAssertions(_) => { + TypescriptConsistentTypeAssertions::IS_TSGOLINT_RULE + } Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::IS_TSGOLINT_RULE } @@ -14566,6 +14595,9 @@ impl RuleEnum { Self::TypescriptConsistentIndexedObjectStyle(_) => { TypescriptConsistentIndexedObjectStyle::HAS_CONFIG } + Self::TypescriptConsistentTypeAssertions(_) => { + TypescriptConsistentTypeAssertions::HAS_CONFIG + } Self::TypescriptConsistentTypeDefinitions(_) => { TypescriptConsistentTypeDefinitions::HAS_CONFIG } @@ -15369,6 +15401,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.types_info(), Self::TypescriptConsistentGenericConstructors(rule) => rule.types_info(), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.types_info(), + Self::TypescriptConsistentTypeAssertions(rule) => rule.types_info(), Self::TypescriptConsistentTypeDefinitions(rule) => rule.types_info(), Self::TypescriptConsistentTypeImports(rule) => rule.types_info(), Self::TypescriptExplicitFunctionReturnType(rule) => rule.types_info(), @@ -16040,6 +16073,7 @@ impl RuleEnum { Self::TypescriptBanTypes(rule) => rule.run_info(), Self::TypescriptConsistentGenericConstructors(rule) => rule.run_info(), Self::TypescriptConsistentIndexedObjectStyle(rule) => rule.run_info(), + Self::TypescriptConsistentTypeAssertions(rule) => rule.run_info(), Self::TypescriptConsistentTypeDefinitions(rule) => rule.run_info(), Self::TypescriptConsistentTypeImports(rule) => rule.run_info(), Self::TypescriptExplicitFunctionReturnType(rule) => rule.run_info(), @@ -16739,6 +16773,7 @@ pub static RULES: std::sync::LazyLock> = std::sync::LazyLock::new( RuleEnum::TypescriptConsistentIndexedObjectStyle( TypescriptConsistentIndexedObjectStyle::default(), ), + RuleEnum::TypescriptConsistentTypeAssertions(TypescriptConsistentTypeAssertions::default()), RuleEnum::TypescriptConsistentTypeDefinitions( TypescriptConsistentTypeDefinitions::default(), ), diff --git a/crates/oxc_linter/src/rules.rs b/crates/oxc_linter/src/rules.rs index e4d959c864f41..01b49083ed02e 100644 --- a/crates/oxc_linter/src/rules.rs +++ b/crates/oxc_linter/src/rules.rs @@ -218,6 +218,7 @@ pub(crate) mod typescript { pub mod ban_types; pub mod consistent_generic_constructors; pub mod consistent_indexed_object_style; + pub mod consistent_type_assertions; pub mod consistent_type_definitions; pub mod consistent_type_imports; pub mod explicit_function_return_type; diff --git a/crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs b/crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs new file mode 100644 index 0000000000000..81af92bfeb2d8 --- /dev/null +++ b/crates/oxc_linter/src/rules/typescript/consistent_type_assertions.rs @@ -0,0 +1,1700 @@ +use std::ops::Deref; + +use oxc_ast::{ + AstKind, + ast::{Expression, TSType, TSTypeName}, +}; +use oxc_diagnostics::OxcDiagnostic; +use oxc_macros::declare_oxc_lint; +use oxc_span::{GetSpan, Span}; +use schemars::JsonSchema; +use serde::Deserialize; + +use crate::{ + AstNode, + ast_util::outermost_paren_parent, + context::{ContextHost, LintContext}, + fixer::{RuleFix, RuleFixer}, + rule::{DefaultRuleConfig, Rule}, +}; + +fn use_angle_bracket_diagnostic(cast: &str, span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn(format!("Use `<{cast}>` instead of `as {cast}`.")).with_label(span) +} + +fn use_as_diagnostic(cast: &str, span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn(format!("Use `as {cast}` instead of `<{cast}>`.")).with_label(span) +} + +fn never_diagnostic(span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn("Do not use any type assertions.").with_label(span) +} + +fn unexpected_object_type_assertion_diagnostic(span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn("Always prefer `const x: T = { ... }`.").with_label(span) +} + +fn unexpected_array_type_assertion_diagnostic(span: Span) -> OxcDiagnostic { + OxcDiagnostic::warn("Always prefer `const x: T[] = [ ... ]`.").with_label(span) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] +#[serde(rename_all = "kebab-case")] +enum AssertionStyle { + As, + AngleBracket, + Never, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] +#[serde(rename_all = "kebab-case")] +enum AssertionStyleNonNever { + #[default] + As, + AngleBracket, +} + +impl From for AssertionStyle { + fn from(value: AssertionStyleNonNever) -> Self { + match value { + AssertionStyleNonNever::As => Self::As, + AssertionStyleNonNever::AngleBracket => Self::AngleBracket, + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] +#[serde(rename_all = "kebab-case")] +enum AssertionStyleNever { + Never, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)] +#[serde(rename_all = "kebab-case")] +enum LiteralAssertionOption { + #[default] + Allow, + AllowAsParameter, + Never, +} + +#[derive(Debug, Clone, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct ConsistentTypeAssertionsNeverConfig { + assertion_style: AssertionStyleNever, +} + +#[derive(Debug, Clone, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct ConsistentTypeAssertionsStyleConfig { + /// Which assertion syntax is enforced when type assertions are allowed. + /// + /// - `"as"` (default) + /// - `"angle-bracket"` + #[serde(default)] + assertion_style: AssertionStyleNonNever, + /// Whether object literal type assertions are allowed, allowed only as parameters, or disallowed. + /// + /// - `"allow"` (default) + /// - `"allow-as-parameter"` + /// - `"never"` + #[serde(default)] + object_literal_type_assertions: LiteralAssertionOption, + /// Whether array literal type assertions are allowed, allowed only as parameters, or disallowed. + /// + /// - `"allow"` (default) + /// - `"allow-as-parameter"` + /// - `"never"` + #[serde(default)] + array_literal_type_assertions: LiteralAssertionOption, +} + +impl Default for ConsistentTypeAssertionsStyleConfig { + fn default() -> Self { + Self { + assertion_style: AssertionStyleNonNever::As, + object_literal_type_assertions: LiteralAssertionOption::Allow, + array_literal_type_assertions: LiteralAssertionOption::Allow, + } + } +} + +#[derive(Debug, Clone, Deserialize, JsonSchema)] +#[serde(untagged)] +pub enum ConsistentTypeAssertionsConfig { + Never(ConsistentTypeAssertionsNeverConfig), + Style(ConsistentTypeAssertionsStyleConfig), +} + +impl Default for ConsistentTypeAssertionsConfig { + fn default() -> Self { + Self::Style(ConsistentTypeAssertionsStyleConfig::default()) + } +} + +impl ConsistentTypeAssertionsConfig { + fn assertion_style(&self) -> AssertionStyle { + match self { + Self::Never(config) => match config.assertion_style { + AssertionStyleNever::Never => AssertionStyle::Never, + }, + Self::Style(config) => config.assertion_style.into(), + } + } + + fn object_literal_type_assertions(&self) -> LiteralAssertionOption { + match self { + Self::Style(config) => config.object_literal_type_assertions, + Self::Never(_) => LiteralAssertionOption::Allow, + } + } + + fn array_literal_type_assertions(&self) -> LiteralAssertionOption { + match self { + Self::Style(config) => config.array_literal_type_assertions, + Self::Never(_) => LiteralAssertionOption::Allow, + } + } +} + +#[derive(Debug, Default, Clone, Deserialize)] +pub struct ConsistentTypeAssertions(Box); + +impl Deref for ConsistentTypeAssertions { + type Target = ConsistentTypeAssertionsConfig; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +declare_oxc_lint!( + /// ### What it does + /// + /// Enforce consistent usage of TypeScript type assertions. + /// + /// ### Why is this bad? + /// + /// Mixing assertion styles (`as` vs angle-bracket) makes code harder to read and maintain. + /// In some codebases, type assertions are banned in favor of safer alternatives like + /// type annotations or `satisfies`. + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule (default: `assertionStyle: "as"`): + /// ```ts + /// const value = bar; + /// ``` + /// + /// Examples of **correct** code for this rule (default: `assertionStyle: "as"`): + /// ```ts + /// const value = bar as Foo; + /// ``` + /// + /// Examples of **incorrect** code for this rule with `assertionStyle: "angle-bracket"`: + /// ```ts + /// const value = bar as Foo; + /// ``` + /// + /// Examples of **correct** code for this rule with `assertionStyle: "angle-bracket"`: + /// ```ts + /// const value = bar; + /// ``` + /// + /// Examples of **incorrect** code for this rule with `assertionStyle: "never"`: + /// ```ts + /// const value = bar as Foo; + /// ``` + /// + /// Examples of **correct** code for this rule with `assertionStyle: "never"`: + /// ```ts + /// const value: Foo = bar; + /// const value = bar satisfies Foo; + /// ``` + /// + /// When object/array literal assertions are disallowed, prefer annotations or `satisfies`: + /// ```ts + /// // incorrect (when `objectLiteralTypeAssertions: "never"`) + /// const obj = { a: 1 } as Foo; + /// + /// // correct + /// const obj: Foo = { a: 1 }; + /// const obj = { a: 1 } satisfies Foo; + /// ``` + ConsistentTypeAssertions, + typescript, + style, + conditional_fix_suggestion, + config = ConsistentTypeAssertionsConfig, +); + +impl Rule for ConsistentTypeAssertions { + fn from_configuration(value: serde_json::Value) -> Result { + serde_json::from_value::>(value).map(DefaultRuleConfig::into_inner) + } + + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { + match node.kind() { + AstKind::TSAsExpression(as_expression) => match self.assertion_style() { + AssertionStyle::As => { + check_expression_for_object_assertion( + node, + &as_expression.expression, + &as_expression.type_annotation, + ctx, + self, + ); + check_expression_for_array_assertion( + node, + &as_expression.expression, + &as_expression.type_annotation, + ctx, + self, + ); + } + AssertionStyle::AngleBracket => { + let cast = ctx.source_range(as_expression.type_annotation.span()); + ctx.diagnostic(use_angle_bracket_diagnostic(cast, as_expression.span)); + } + AssertionStyle::Never => { + if is_const(&as_expression.type_annotation) { + return; + } + ctx.diagnostic(never_diagnostic(as_expression.span)); + } + }, + AstKind::TSTypeAssertion(type_assertion) => match self.assertion_style() { + AssertionStyle::AngleBracket => { + check_expression_for_object_assertion( + node, + &type_assertion.expression, + &type_assertion.type_annotation, + ctx, + self, + ); + check_expression_for_array_assertion( + node, + &type_assertion.expression, + &type_assertion.type_annotation, + ctx, + self, + ); + } + AssertionStyle::As => { + let cast = ctx.source_range(type_assertion.type_annotation.span()); + let is_parenthesized = is_parenthesized(node, ctx); + let needs_parentheses = !is_parenthesized && needs_parens_for_parent(node, ctx); + ctx.diagnostic_with_fix( + use_as_diagnostic(cast, type_assertion.span), + |fixer| { + let mut expression_text = expression_text_for_as( + &type_assertion.expression, + fixer.source_text(), + ); + if !needs_parentheses + && !matches!( + type_assertion.expression, + Expression::ParenthesizedExpression(_) + ) + && matches!( + type_assertion.expression.without_parentheses(), + Expression::ObjectExpression(_) + ) + && needs_parens_for_object_literal_replacement(node, ctx) + { + expression_text = format!("({expression_text})"); + } + let type_text = + fixer.source_range(type_assertion.type_annotation.span()); + let mut replacement = format!("{expression_text} as {type_text}"); + if needs_parentheses { + replacement = format!("({replacement})"); + } + fixer.replace(type_assertion.span, replacement) + }, + ); + } + AssertionStyle::Never => { + if is_const(&type_assertion.type_annotation) { + return; + } + ctx.diagnostic(never_diagnostic(type_assertion.span)); + } + }, + _ => {} + } + } + + fn should_run(&self, ctx: &ContextHost) -> bool { + ctx.source_type().is_typescript() + } +} + +fn is_const(type_annotation: &TSType) -> bool { + if let TSType::TSTypeReference(type_reference) = type_annotation + && let TSTypeName::IdentifierReference(ident) = &type_reference.type_name + { + return ident.name.as_str() == "const"; + } + + false +} + +fn check_type(type_annotation: &TSType) -> bool { + match type_annotation { + TSType::TSAnyKeyword(_) | TSType::TSUnknownKeyword(_) => false, + TSType::TSTypeReference(type_reference) => { + if let TSTypeName::IdentifierReference(ident) = &type_reference.type_name { + return ident.name.as_str() != "const"; + } + true + } + _ => true, + } +} + +fn expression_text_for_as(expression: &Expression, source_text: &str) -> String { + let text = expression.span().source_text(source_text); + if matches!(expression, Expression::ParenthesizedExpression(_)) { + return text.to_string(); + } + if expression_needs_parens_for_as(expression) { format!("({text})") } else { text.to_string() } +} + +fn expression_needs_parens_for_as(expression: &Expression) -> bool { + matches!( + expression.without_parentheses(), + Expression::SequenceExpression(_) + | Expression::AssignmentExpression(_) + | Expression::ConditionalExpression(_) + | Expression::YieldExpression(_) + | Expression::ArrowFunctionExpression(_) + | Expression::TSAsExpression(_) + | Expression::TSSatisfiesExpression(_) + | Expression::TSTypeAssertion(_) + | Expression::TSInstantiationExpression(_) + ) +} + +fn is_parenthesized(node: &AstNode, ctx: &LintContext) -> bool { + matches!(ctx.nodes().parent_kind(node.id()), AstKind::ParenthesizedExpression(_)) +} + +fn needs_parens_for_parent(node: &AstNode, ctx: &LintContext) -> bool { + let parent = ctx.nodes().parent_node(node.id()); + let node_span = node.kind().span(); + + match parent.kind() { + AstKind::BinaryExpression(_) + | AstKind::LogicalExpression(_) + | AstKind::ConditionalExpression(_) + | AstKind::UnaryExpression(_) + | AstKind::UpdateExpression(_) + | AstKind::AwaitExpression(_) + | AstKind::YieldExpression(_) + | AstKind::AssignmentExpression(_) + | AstKind::SequenceExpression(_) + | AstKind::TSAsExpression(_) + | AstKind::TSSatisfiesExpression(_) + | AstKind::TSTypeAssertion(_) => true, + AstKind::CallExpression(call_expr) => call_expr.callee.span() == node_span, + AstKind::NewExpression(new_expr) => new_expr.callee.span() == node_span, + AstKind::StaticMemberExpression(member) => member.object.span() == node_span, + AstKind::ComputedMemberExpression(member) => member.object.span() == node_span, + AstKind::TaggedTemplateExpression(tagged) => tagged.tag.span() == node_span, + AstKind::ArrowFunctionExpression(arrow) => { + arrow.get_expression().is_some_and(|expr| expr.span() == node_span) + } + AstKind::ExpressionStatement(expr_stmt) => { + let mut ancestor = ctx.nodes().parent_node(parent.id()); + if matches!(ancestor.kind(), AstKind::FunctionBody(_)) { + ancestor = ctx.nodes().parent_node(ancestor.id()); + } + if let AstKind::ArrowFunctionExpression(arrow) = ancestor.kind() { + return arrow + .get_expression() + .is_some_and(|expr| expr.span() == expr_stmt.expression.span()); + } + false + } + _ => false, + } +} + +fn is_as_parameter<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bool { + let Some(parent) = outermost_paren_parent(node, ctx.semantic()) else { + return false; + }; + + match parent.kind() { + AstKind::NewExpression(_) + | AstKind::CallExpression(_) + | AstKind::ThrowStatement(_) + | AstKind::AssignmentPattern(_) + | AstKind::FormalParameter(_) + | AstKind::JSXExpressionContainer(_) => true, + AstKind::TemplateLiteral(_) => { + outermost_paren_parent(parent, ctx.semantic()).is_some_and(|grandparent| { + matches!(grandparent.kind(), AstKind::TaggedTemplateExpression(_)) + }) + } + _ => false, + } +} + +fn expression_text_for_replacement<'a>( + node: &AstNode<'a>, + expression: &Expression<'a>, + ctx: &LintContext<'a>, +) -> String { + let text = ctx.source_range(expression.span()); + if matches!(expression, Expression::ParenthesizedExpression(_)) { + return text.to_string(); + } + if matches!(expression.without_parentheses(), Expression::ObjectExpression(_)) + && needs_parens_for_object_literal_replacement(node, ctx) + { + return format!("({text})"); + } + text.to_string() +} + +fn needs_parens_for_object_literal_replacement<'a>( + node: &AstNode<'a>, + ctx: &LintContext<'a>, +) -> bool { + let Some(parent) = outermost_paren_parent(node, ctx.semantic()) else { + return false; + }; + match parent.kind() { + AstKind::ExpressionStatement(_) => true, + AstKind::ArrowFunctionExpression(arrow) => { + let node_span = node.kind().span(); + arrow.get_expression().is_some_and(|expr| expr.span() == node_span) + } + _ => false, + } +} + +#[derive(Debug, Clone, Copy)] +enum LiteralKind { + Object, + Array, +} + +impl LiteralKind { + fn example(self) -> &'static str { + match self { + Self::Object => "{ ... }", + Self::Array => "[ ... ]", + } + } +} + +fn get_suggestions<'a>( + node: &AstNode<'a>, + expression: &Expression<'a>, + type_annotation: &TSType<'a>, + ctx: &LintContext<'a>, + literal_kind: LiteralKind, +) -> Vec { + let type_text = ctx.source_range(type_annotation.span()); + let expression_text = expression_text_for_replacement(node, expression, ctx); + let mut suggestions = Vec::new(); + let literal = literal_kind.example(); + + if let Some(parent) = outermost_paren_parent(node, ctx.semantic()) + && let AstKind::VariableDeclarator(var_decl) = parent.kind() + && var_decl.type_annotation.is_none() + { + let fixer = RuleFixer::new(FixKind::Suggestion, ctx).for_multifix(); + let mut fix = fixer.new_fix_with_capacity(2); + fix.push(fixer.insert_text_after(&var_decl.id, format!(": {type_text}"))); + fix.push(fixer.replace(node.kind().span(), expression_text.clone())); + suggestions + .push(fix.with_message(format!("Use const x: {type_text} = {literal} instead."))); + } + + let fixer = RuleFixer::new(FixKind::Suggestion, ctx).for_multifix(); + let mut fix = fixer.new_fix_with_capacity(2); + fix.push(fixer.replace(node.kind().span(), expression_text)); + fix.push(fixer.insert_text_after_range(node.kind().span(), format!(" satisfies {type_text}"))); + suggestions + .push(fix.with_message(format!("Use const x = {literal} satisfies {type_text} instead."))); + + suggestions +} + +fn check_expression_for_object_assertion<'a>( + node: &AstNode<'a>, + expression: &Expression<'a>, + type_annotation: &TSType<'a>, + ctx: &LintContext<'a>, + config: &ConsistentTypeAssertionsConfig, +) { + if matches!(config.assertion_style(), AssertionStyle::Never) + || matches!(config.object_literal_type_assertions(), LiteralAssertionOption::Allow) + { + return; + } + + if !matches!(expression.without_parentheses(), Expression::ObjectExpression(_)) { + return; + } + + if matches!(config.object_literal_type_assertions(), LiteralAssertionOption::AllowAsParameter) + && is_as_parameter(node, ctx) + { + return; + } + + if check_type(type_annotation) { + let suggestions = + get_suggestions(node, expression, type_annotation, ctx, LiteralKind::Object); + ctx.diagnostic_with_suggestions( + unexpected_object_type_assertion_diagnostic(node.kind().span()), + suggestions, + ); + } +} + +fn check_expression_for_array_assertion<'a>( + node: &AstNode<'a>, + expression: &Expression<'a>, + type_annotation: &TSType<'a>, + ctx: &LintContext<'a>, + config: &ConsistentTypeAssertionsConfig, +) { + if matches!(config.assertion_style(), AssertionStyle::Never) + || matches!(config.array_literal_type_assertions(), LiteralAssertionOption::Allow) + { + return; + } + + if !matches!(expression.without_parentheses(), Expression::ArrayExpression(_)) { + return; + } + + if matches!(config.array_literal_type_assertions(), LiteralAssertionOption::AllowAsParameter) + && is_as_parameter(node, ctx) + { + return; + } + + if check_type(type_annotation) { + let suggestions = + get_suggestions(node, expression, type_annotation, ctx, LiteralKind::Array); + ctx.diagnostic_with_suggestions( + unexpected_array_type_assertion_diagnostic(node.kind().span()), + suggestions, + ); + } +} + +#[test] +fn test() { + use std::path::PathBuf; + + use crate::tester::{TestCase, Tester}; + + let pass = vec![ + ( + "const x = new Generic() as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = b as A;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = [1] as readonly number[];", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = 'string' as a | b;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = !'string' as A;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = (a as A) + b;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new Generic() as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new (Generic as Foo)();", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new (Generic as Foo)('string');", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = () => ({ bar: 5 }) as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = () => bar as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = bar`${'baz'}` as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = { key: 'value' } as const;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new Generic();", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = b;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = [1];", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = 'string';", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = !'string';", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = a + b;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new Generic();", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new (Generic)();", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = new (Generic)('string');", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = () => { bar: 5 };", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = () => bar;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = bar`${'baz'}`;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = { key: 'value' };", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = {} as Foo;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "const x = {} as a | b;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "const x = ({} as A) + b;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "print({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "new print({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + " + function foo() { + throw { bar: 5 } as Foo; + } + ", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "function b(x = {} as Foo.Bar) {}", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "function c(x = {} as Foo) {}", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "print?.({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "print?.call({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "print`${{ bar: 5 } as Foo}`;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow" }]), + ), + ), + ( + "const x = >{};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = {};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "const x = {} + b;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "new print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + " + function foo() { + throw { bar: 5 }; + } + ", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "print?.({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "print?.call({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "print`${{ bar: 5 }}`;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow", }, ]), + ), + ), + ( + "print({ bar: 5 } as Foo);", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "new print({ bar: 5 } as Foo);", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + " + function foo() { + throw { bar: 5 } as Foo; + } + ", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "function b(x = {} as Foo.Bar) {}", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "function c(x = {} as Foo) {}", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print?.({ bar: 5 } as Foo);", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print?.call({ bar: 5 } as Foo);", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print`${{ bar: 5 } as Foo}`;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "new print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + " + function foo() { + throw { bar: 5 }; + } + ", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print?.({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print?.call({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "print`${{ bar: 5 }}`;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ("const x = [] as string[];", Some(serde_json::json!([ { "assertionStyle": "as", }, ]))), + ( + "const x = ['a'] as Array;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const x = [];", + Some(serde_json::json!([ { "assertionStyle": "angle-bracket", }, ])), + ), + ( + "const x = >[];", + Some(serde_json::json!([ { "assertionStyle": "angle-bracket", }, ])), + ), + ( + "print([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + " + function foo() { + throw [5] as Foo; + } + ", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "function b(x = [5] as Foo.Bar) {}", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "print?.([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "print?.call([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "print`${[5] as Foo}`;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "new Print([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "print([5]);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + " + function foo() { + throw [5]; + } + ", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "function b(x = [5]) {}", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "print?.([5]);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "print?.call([5]);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "print`${[5]}`;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "new Print([5]);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ("const x = [1];", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ("const x = [1] as const;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + " + const x = { key: 'value' } as any; + ", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + " + const x = { key: 'value' } as unknown; + ", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ]; + + let mut pass: Vec = pass.into_iter().map(Into::into).collect(); + pass.push( + ( + "const bar = ;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + None, + Some(PathBuf::from("consistent_type_assertions.tsx")), + ) + .into(), + ); + pass.push( + ( + "const bar = ;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + None, + Some(PathBuf::from("consistent_type_assertions.tsx")), + ) + .into(), + ); + + let fail = vec![ + ( + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ("const x = b as A;", Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }]))), + ( + "const x = [1] as readonly number[];", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = 'string' as a | b;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = !'string' as A;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = (a as A) + b;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = new (Generic as Foo)();", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = new (Generic as Foo)('string');", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = () => ({ bar: 5 }) as Foo;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = () => bar as Foo;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = bar`${'baz'}` as Foo;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = { key: 'value' } as const;", + Some(serde_json::json!([{ "assertionStyle": "angle-bracket" }])), + ), + ( + "const x = new Generic();", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ("const x = b;", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ( + "const x = [1];", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ("const x = 'string';", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ("const x = !'string';", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ("const x = a + b;", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ( + "const x = new Generic();", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new (Generic)();", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new (Generic)('string');", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ("const x = () => { bar: 5 };", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ("const x = () => bar;", Some(serde_json::json!([{ "assertionStyle": "as" }]))), + ( + "const x = bar`${'baz'}`;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = { key: 'value' };", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = b as A;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = [1] as readonly number[];", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = 'string' as a | b;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ("const x = !'string' as A;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ("const x = (a as A) + b;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = new (Generic as Foo)();", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = new (Generic as Foo)('string');", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = () => ({ bar: 5 }) as Foo;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = () => bar as Foo;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = bar`${'baz'}` as Foo;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = new Generic();", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = b;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = [1];", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = 'string';", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ("const x = !'string';", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ("const x = a + b;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = new Generic();", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = new (Generic)();", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = new (Generic)('string');", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = () => { bar: 5 };", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ("const x = () => bar;", Some(serde_json::json!([{ "assertionStyle": "never" }]))), + ( + "const x = bar`${'baz'}`;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + ), + ( + "const x = {} as Foo;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = {} as a | b;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = ({} as A) + b;", + Some( + serde_json::json!([ { "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = >{};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = {};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = {} + b;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "allow-as-parameter", }, ]), + ), + ), + ( + "const x = {} as Foo;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "const x = {} as a | b;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "const x = ({} as A) + b;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "print({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "new print({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + " + function foo() { + throw { bar: 5 } as Foo; + } + ", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "function b(x = {} as Foo.Bar) {}", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "function c(x = {} as Foo) {}", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "print?.({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "print?.call({ bar: 5 } as Foo);", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "print`${{ bar: 5 } as Foo}`;", + Some( + serde_json::json!([{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }]), + ), + ), + ( + "const x = >{};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "const x = {};", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "const x = {} + b;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "new print({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + " + function foo() { + throw { bar: 5 }; + } + ", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "print?.({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "print?.call({ bar: 5 });", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ( + "print`${{ bar: 5 }}`;", + Some( + serde_json::json!([ { "assertionStyle": "angle-bracket", "objectLiteralTypeAssertions": "never", }, ]), + ), + ), + ("const a = (b, c);", Some(serde_json::json!([ { "assertionStyle": "as", }, ]))), + ("const f = (() => {});", Some(serde_json::json!([ { "assertionStyle": "as", }, ]))), + ( + "const f = function () {};", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const f = (async () => {});", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + " + function* g() { + const y = (yield a); + } + ", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + " + declare let x: number, y: number; + const bs = (x <<= y); + ", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const ternary = (true ? x : y);", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ("const x = [] as string[];", Some(serde_json::json!([ { "assertionStyle": "never", }, ]))), + ("const x = [];", Some(serde_json::json!([ { "assertionStyle": "never", }, ]))), + ( + "const x = [] as string[];", + Some(serde_json::json!([ { "assertionStyle": "angle-bracket", }, ])), + ), + ("const x = [];", Some(serde_json::json!([ { "assertionStyle": "as", }, ]))), + ( + "const x = [] as string[];", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + "const x = [];", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "print([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + "new print([5] as Foo);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + "function b(x = [5] as Foo.Bar) {}", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + " + function foo() { + throw [5] as Foo; + } + ", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + "print`${[5] as Foo}`;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "as", }, ]), + ), + ), + ( + "const foo = () => [5] as Foo;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "as", }, ]), + ), + ), + ( + "new print([5]);", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "function b(x = [5]) {}", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + " + function foo() { + throw [5]; + } + ", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "print`${[5]}`;", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "never", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ( + "const foo = [5];", + Some( + serde_json::json!([ { "arrayLiteralTypeAssertions": "allow-as-parameter", "assertionStyle": "angle-bracket", }, ]), + ), + ), + ]; + let mut fail: Vec = fail.into_iter().map(Into::into).collect(); + fail.push( + ( + "const foo = ;", + Some(serde_json::json!([{ "assertionStyle": "never" }])), + None, + Some(PathBuf::from("consistent_type_assertions.tsx")), + ) + .into(), + ); + + let fix = vec![ + ( + "const x = new Generic();", + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = b;", + "const x = b as A;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = [1];", + "const x = [1] as readonly number[];", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = 'string';", + "const x = 'string' as a | b;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = !'string';", + "const x = !'string' as A;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = a + b;", + "const x = (a as A) + b;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new Generic();", + "const x = new Generic() as Foo;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new (Generic)();", + "const x = new ((Generic) as Foo)();", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = new (Generic)('string');", + "const x = new ((Generic) as Foo)('string');", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = () => { bar: 5 };", + "const x = () => ({ bar: 5 } as Foo);", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = () => bar;", + "const x = () => (bar as Foo);", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = bar`${'baz'}`;", + "const x = bar`${'baz'}` as Foo;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const x = { key: 'value' };", + "const x = { key: 'value' } as const;", + Some(serde_json::json!([{ "assertionStyle": "as" }])), + ), + ( + "const a = (b, c);", + "const a = (b, c) as any;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const f = (() => {});", + "const f = (() => {}) as any;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const f = function () {};", + "const f = function () {} as any;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const f = (async () => {});", + "const f = (async () => {}) as any;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + " + function* g() { + const y = (yield a); + } + ", + " + function* g() { + const y = (yield a) as any; + } + ", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + " + declare let x: number, y: number; + const bs = (x <<= y); + ", + " + declare let x: number, y: number; + const bs = (x <<= y) as any; + ", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const ternary = (true ? x : y);", + "const ternary = (true ? x : y) as any;", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ( + "const x = [];", + "const x = [] as string[];", + Some(serde_json::json!([ { "assertionStyle": "as", }, ])), + ), + ]; + + Tester::new(ConsistentTypeAssertions::NAME, ConsistentTypeAssertions::PLUGIN, pass, fail) + .change_rule_path_extension("ts") + .expect_fix(fix) + .test_and_snapshot(); +} diff --git a/crates/oxc_linter/src/snapshots/typescript_consistent_type_assertions.snap b/crates/oxc_linter/src/snapshots/typescript_consistent_type_assertions.snap new file mode 100644 index 0000000000000..71d24307a2fe3 --- /dev/null +++ b/crates/oxc_linter/src/snapshots/typescript_consistent_type_assertions.snap @@ -0,0 +1,642 @@ +--- +source: crates/oxc_linter/src/tester.rs +--- + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic() as Foo; + · ───────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as A`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = b as A; + · ────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as readonly number[]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [1] as readonly number[]; + · ──────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as a | b`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = 'string' as a | b; + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as A`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = !'string' as A; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as A`. + ╭─[consistent_type_assertions.ts:1:12] + 1 │ const x = (a as A) + b; + · ────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic() as Foo; + · ──────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic as Foo)(); + · ────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic as Foo)('string'); + · ────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => ({ bar: 5 }) as Foo; + · ─────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => bar as Foo; + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as Foo`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = bar`${'baz'}` as Foo; + · ──────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as const`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = { key: 'value' } as const; + · ───────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic(); + · ─────────────────────── + ╰──── + help: Replace `new Generic()` with `new Generic() as Foo`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as A` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = b; + · ──── + ╰──── + help: Replace `b` with `b as A`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as readonly number[]` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [1]; + · ────────────────────── + ╰──── + help: Replace `[1]` with `[1] as readonly number[]`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as a | b` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = 'string'; + · ─────────────── + ╰──── + help: Replace `'string'` with `'string' as a | b`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as A` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = !'string'; + · ──────────── + ╰──── + help: Replace `!'string'` with `!'string' as A`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as A` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = a + b; + · ──── + ╰──── + help: Replace `a` with `(a as A)`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic(); + · ────────────────────────── + ╰──── + help: Replace `new Generic()` with `new Generic() as Foo`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic)(); + · ──────────────────── + ╰──── + help: Replace `Generic` with `(Generic) as Foo`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic)('string'); + · ──────────────────── + ╰──── + help: Replace `Generic` with `(Generic) as Foo`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => { bar: 5 }; + · ─────────────── + ╰──── + help: Replace `{ bar: 5 }` with `({ bar: 5 } as Foo)`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => bar; + · ──────── + ╰──── + help: Replace `bar` with `(bar as Foo)`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as Foo` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = bar`${'baz'}`; + · ────────────────────────── + ╰──── + help: Replace `bar`${'baz'}`` with `bar`${'baz'}` as Foo`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as const` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = { key: 'value' }; + · ─────────────────────── + ╰──── + help: Replace `{ key: 'value' }` with `{ key: 'value' } as const`. + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic() as Foo; + · ───────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = b as A; + · ────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [1] as readonly number[]; + · ──────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = 'string' as a | b; + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = !'string' as A; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:12] + 1 │ const x = (a as A) + b; + · ────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic() as Foo; + · ──────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic as Foo)(); + · ────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic as Foo)('string'); + · ────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => ({ bar: 5 }) as Foo; + · ─────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => bar as Foo; + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = bar`${'baz'}` as Foo; + · ──────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic(); + · ─────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = b; + · ──── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [1]; + · ────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = 'string'; + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = !'string'; + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = a + b; + · ──── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = new Generic(); + · ────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic)(); + · ──────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ const x = new (Generic)('string'); + · ──────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => { bar: 5 }; + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const x = () => bar; + · ──────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = bar`${'baz'}`; + · ────────────────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} as Foo; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} as a | b; + · ─────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:12] + 1 │ const x = ({} as A) + b; + · ─────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = >{}; + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {}; + · ───────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} + b; + · ───── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} as Foo; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} as a | b; + · ─────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:12] + 1 │ const x = ({} as A) + b; + · ─────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:7] + 1 │ print({ bar: 5 } as Foo); + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ new print({ bar: 5 } as Foo); + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:3:21] + 2 │ function foo() { + 3 │ throw { bar: 5 } as Foo; + · ───────────────── + 4 │ } + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ function b(x = {} as Foo.Bar) {} + · ───────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ function c(x = {} as Foo) {} + · ───────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print?.({ bar: 5 } as Foo); + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:13] + 1 │ print?.call({ bar: 5 } as Foo); + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print`${{ bar: 5 } as Foo}`; + · ───────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = >{}; + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {}; + · ───────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = {} + b; + · ───── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:7] + 1 │ print({ bar: 5 }); + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ new print({ bar: 5 }); + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:3:21] + 2 │ function foo() { + 3 │ throw { bar: 5 }; + · ─────────────── + 4 │ } + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print?.({ bar: 5 }); + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:13] + 1 │ print?.call({ bar: 5 }); + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T = { ... }`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print`${{ bar: 5 }}`; + · ─────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const a = (b, c); + · ─────────── + ╰──── + help: Replace `(b, c)` with `(b, c) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const f = (() => {}); + · ─────────────── + ╰──── + help: Replace `(() => {})` with `(() => {}) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const f = function () {}; + · ─────────────────── + ╰──── + help: Replace `function () {}` with `function () {} as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const f = (async () => {}); + · ───────────────────── + ╰──── + help: Replace `(async () => {})` with `(async () => {}) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:3:25] + 2 │ function* g() { + 3 │ const y = (yield a); + · ────────────── + 4 │ } + ╰──── + help: Replace `(yield a)` with `(yield a) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:3:24] + 2 │ declare let x: number, y: number; + 3 │ const bs = (x <<= y); + · ────────────── + 4 │ + ╰──── + help: Replace `(x <<= y)` with `(x <<= y) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Use `as any` instead of ``. + ╭─[consistent_type_assertions.ts:1:17] + 1 │ const ternary = (true ? x : y); + · ─────────────────── + ╰──── + help: Replace `(true ? x : y)` with `(true ? x : y) as any`. + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [] as string[]; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = []; + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `` instead of `as string[]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [] as string[]; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Use `as string[]` instead of ``. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = []; + · ──────────── + ╰──── + help: Replace `[]` with `[] as string[]`. + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = [] as string[]; + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ const x = []; + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:7] + 1 │ print([5] as Foo); + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ new print([5] as Foo); + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ function b(x = [5] as Foo.Bar) {} + · ────────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:3:21] + 2 │ function foo() { + 3 │ throw [5] as Foo; + · ────────── + 4 │ } + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print`${[5] as Foo}`; + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:19] + 1 │ const foo = () => [5] as Foo; + · ────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:11] + 1 │ new print([5]); + · ──────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:16] + 1 │ function b(x = [5]) {} + · ──────────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:3:21] + 2 │ function foo() { + 3 │ throw [5]; + · ──────── + 4 │ } + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:9] + 1 │ print`${[5]}`; + · ──────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Always prefer `const x: T[] = [ ... ]`. + ╭─[consistent_type_assertions.ts:1:13] + 1 │ const foo = [5]; + · ──────── + ╰──── + + ⚠ typescript-eslint(consistent-type-assertions): Do not use any type assertions. + ╭─[consistent_type_assertions.ts:1:25] + 1 │ const foo = ; + · ───────────────── + ╰────