biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
14.15k stars 434 forks source link

πŸ’… noDuplicateTestHooks should consider `context` blocks (Cypress and Mocha code) as well as `describe` #3602

Open bvandercar-vt opened 1 month ago

bvandercar-vt commented 1 month ago

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           "v18.19.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "yarn/1.22.2"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Linter:
  JavaScript enabled:           true
  JSON enabled:                 true
  CSS enabled:                  false
  Recommended:                  true
  All:                          false
  Enabled rules:
  performance/noDelete
  suspicious/noCatchAssign
  suspicious/noUnsafeNegation
  complexity/useLiteralKeys
  style/useImportType
  nursery/noEvolvingTypes
  complexity/noMultipleSpacesInRegularExpressionLiterals
  a11y/useValidLang
  complexity/noUselessEmptyExport
  suspicious/useNamespaceKeyword
  suspicious/useValidTypeof
  a11y/useValidAriaRole
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  nursery/noYodaExpression
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  suspicious/noAssignInExpressions
  suspicious/noDuplicateParameters
  style/useTemplate
  correctness/noUnusedLabels
  complexity/noUselessTernary
  correctness/noUnreachableSuper
  suspicious/noCompareNegZero
  suspicious/noExplicitAny
  correctness/noSwitchDeclarations
  a11y/noAutofocus
  correctness/noUnsafeOptionalChaining
  correctness/noConstAssign
  suspicious/noControlCharactersInRegex
  complexity/noUselessTypeConstraint
  style/noVar
  suspicious/noDoubleEquals
  suspicious/noRedundantUseStrict
  style/useLiteralEnumMembers
  suspicious/noGlobalIsNan
  suspicious/noEmptyInterface
  suspicious/noConstEnum
  suspicious/noMisleadingCharacterClass
  correctness/noPrecisionLoss
  suspicious/noRedeclare
  correctness/noStringCaseMismatch
  correctness/noSetterReturn
  correctness/noInvalidConstructorSuper
  suspicious/noImplicitAnyLet
  suspicious/noFallthroughSwitchClause
  a11y/useKeyWithClickEvents
  correctness/noUnreachable
  nursery/noUselessStringConcat
  suspicious/noDuplicateObjectKeys
  complexity/noUselessThisAlias
  complexity/noThisInStatic
  complexity/useOptionalChain
  correctness/noInnerDeclarations
  style/noParameterAssign
  suspicious/noDuplicateCase
  suspicious/noUnsafeDeclarationMerging
  a11y/useValidAnchor
  correctness/useArrayLiterals
  complexity/useRegexLiterals
  correctness/noSelfAssign
  style/noUselessElse
  style/useShorthandFunctionType
  suspicious/noShadowRestrictedNames
  nursery/noUnusedFunctionParameters
  suspicious/noEmptyBlockStatements
  a11y/useMediaCaption
  complexity/noUselessLabel
  complexity/noUselessCatch
  correctness/noUnsafeFinally
  a11y/useAriaPropsForRole
  correctness/noNonoctalDecimalEscape
  style/useEnumInitializers
  a11y/useHtmlLang
  suspicious/noDuplicateTestHooks
  complexity/noStaticOnlyClass
  style/useWhile
  complexity/useArrowFunction
  style/noInferrableTypes
  a11y/noNoninteractiveTabindex
  complexity/useSimpleNumberKeys
  correctness/useYield
  a11y/noInteractiveElementToNoninteractiveRole
  style/useNumericLiterals
  correctness/noUnnecessaryContinue
  suspicious/noApproximativeNumericConstant
  suspicious/noImportAssign
  suspicious/noLabelVar
  correctness/noGlobalObjectCalls
  suspicious/useDefaultSwitchClauseLast
  a11y/useAltText
  correctness/noEmptyCharacterClassInRegex
  suspicious/noSuspiciousSemicolonInJsx
  suspicious/noSparseArray
  a11y/useIframeTitle
  complexity/noBannedTypes
  a11y/noSvgWithoutTitle
  nursery/useDefaultSwitchClause
  style/useAsConstAssertion
  correctness/useJsxKeyInIterable
  correctness/noVoidElementsWithChildren
  complexity/noUselessLoneBlockStatements
  suspicious/noDebugger
  style/noArguments
  a11y/useValidAriaValues
  suspicious/noMisleadingInstantiator
  style/useExportType
  suspicious/noGlobalAssign
  suspicious/noCommentText
  suspicious/noDuplicateJsxProps
  suspicious/noPrototypeBuiltins
  a11y/noPositiveTabindex
  correctness/noEmptyPattern
  complexity/noExcessiveNestedTestSuites
  security/noDangerouslySetInnerHtmlWithChildren
  a11y/useKeyWithMouseEvents
  suspicious/noExtraNonNullAssertion
  suspicious/noThenProperty
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  style/noNonNullAssertion
  a11y/noRedundantRoles
  complexity/useFlatMap
  correctness/useIsNan
  correctness/useHookAtTopLevel
  style/useConst
  suspicious/noGlobalIsFinite
  suspicious/noSelfCompare
  suspicious/noAsyncPromiseExecutor
  suspicious/useGetterReturn
  complexity/noExcessiveCognitiveComplexity
  security/noDangerouslySetInnerHtml
  style/useNodejsImportProtocol
  a11y/noDistractingElements
  suspicious/noArrayIndexKey
  complexity/noWith
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  performance/noAccumulatingSpread
  a11y/useValidAriaProps
  a11y/noRedundantAlt
  correctness/noChildrenProp
  suspicious/noConfusingLabels
  suspicious/noConfusingVoidType
  suspicious/noFocusedTests
  a11y/useButtonType
  a11y/noAriaUnsupportedElements
  correctness/noFlatMapIdentity
  a11y/noBlankTarget
  a11y/useHeadingContent
  correctness/useValidForDirection
  correctness/noVoidTypeReturn
  correctness/noInvalidUseBeforeDeclaration
  a11y/noAriaHiddenOnFocusable
  a11y/useAnchorContent
  complexity/noUselessRename
  correctness/noInvalidNewBuiltin
  style/useNumberNamespace
  complexity/noUselessConstructor
  a11y/noAccessKey
  complexity/useSimplifiedLogicExpression
  nursery/useSortedClasses
  complexity/noUselessSwitchCase
  style/noUnusedTemplateLiteral
  style/useExponentiationOperator
  suspicious/useAwait
  style/useSingleVarDeclarator
  suspicious/noExportsInTest
  a11y/noNoninteractiveElementToInteractiveRole
  style/noCommaOperator
  suspicious/useIsArray
  a11y/noHeaderScope
  complexity/noUselessFragments
  suspicious/noMisrefactoredShorthandAssign
  complexity/noForEach
  correctness/noUnusedImports
  suspicious/noClassAssign
  suspicious/noFunctionAssign

Workspace:
  Open Documents:               0

Done in 0.16s.

Rule name

noDuplicateTestHooks

Playground link

https://biomejs.dev/playground/?code=ZABlAHMAYwByAGkAYgBlACgAIgBPAHUAdABlAHIAIABUAGkAdABsAGUAIgAsACAAKAApACAAPQA%2BACAAewAKAAkAYgBlAGYAbwByAGUARQBhAGMAaAAoACgAKQAgAD0APgAgAHsAfQApADsACgAKAAkAYwBvAG4AdABlAHgAdAAoACIASQBuAG4AZQByACAAVABpAHQAbABlACAAMQAiACwAIAAoACkAIAA9AD4AIAB7AAoACQAJAGIAZQBmAG8AcgBlAEUAYQBjAGgAKAAoACkAIAA9AD4AIAB7AH0AKQA7AAoACgAJAAkAaQB0ACgAIgB0AGUAcwB0ACAAMQAiACwAIAAoACkAIAA9AD4AIAB7AH0AKQA7AAoACgAJAAkAaQB0ACgAIgB0AGUAcwB0ACAAMgAiACwAIAAoACkAIAA9AD4AIAB7AH0AKQA7AAoACQB9ACkAOwAKAAoACQBjAG8AbgB0AGUAeAB0ACgAIgBJAG4AbgBlAHIAIABUAGkAdABsAGUAIAAyACIALAAgACgAKQAgAD0APgAgAHsACgAJAAkAYgBlAGYAbwByAGUARQBhAGMAaAAoACgAKQAgAD0APgAgAHsAfQApADsACgAKAAkACQBpAHQAKAAiAHQAZQBzAHQAIAAxACIALAAgACgAKQAgAD0APgAgAHsAfQApADsACgAKAAkACQBpAHQAKAAiAHQAZQBzAHQAIAAyACIALAAgACgAKQAgAD0APgAgAHsAfQApADsACgAJAH0AKQA7AAoAfQApADsACgA%3D

Expected result

It should not throw an error.

If I change context to describe, there is no error. Biome should account for context like it already does for describe; they are one in the same. context is used for Cypress testing, Mocha Testing, and likely others.

Code of Conduct

ematipico commented 1 month ago

Can you share the docs of these APIs? And how should the rule behave with this API when there's a describe with the same title?

bvandercar-vt commented 1 month ago

Can you share the docs of these APIs? And how should the rule behave with this API when there's a describe with the same title?

https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Test-Structure

"The test interface, borrowed from Mocha, provides describe(), context(), it() and specify()." "context() is identical to describe() and specify() is identical to it(), so choose whatever terminology works best for you."

And how should the rule behave with this API when there's a describe with the same title?

However it currently functions for describe-- they should be handled as being exact same, totally interchangeable.

ematipico commented 1 month ago

I've never heard and used these APIs. Let's see if other users bump into this issue.

However, considering the description, I feel describe and it should be favoured due to their widespread usage.

bvandercar-vt commented 1 month ago

I've never heard and used these APIs

describe and it should be favoured due to their widespread usage

These are incredibly common tools. MochaJs has 7,700,000+ weekly downloads on npm . Per their GitHub readme, "Mocha is one of the most-depended-upon modules on npm"

Then Cypress, which uses Mocha and Mocha's test wrapper names, has 5,300,000+ weekly downloads on npm

ematipico commented 1 month ago

I'm not talking about the libraries, I know them. I'm talking about the APIs context and specify