biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.

Home Page:https://biomejs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ’… [nursery/useDateNow] Incorrect applying to Date.now() to all Date.prototype.getTime

motss opened this issue Β· comments

Environment information

CLI:
  Version:                      1.8.0
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.1.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/9.1.4"

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

Linter:
  JavaScript enabled:           true
  JSON enabled:                 true
  CSS enabled:                  true
  Recommended:                  true
  All:                          false
  Enabled rules:
  style/useImportType
  suspicious/noCatchAssign
  complexity/useLiteralKeys
  nursery/useThrowOnlyError
  suspicious/useNamespaceKeyword
  complexity/noMultipleSpacesInRegularExpressionLiterals
  complexity/noUselessEmptyExport
  suspicious/noAssignInExpressions
  nursery/noYodaExpression
  suspicious/noDuplicateParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  style/useTemplate
  correctness/noUnusedLabels
  correctness/noUnreachableSuper
  suspicious/noCompareNegZero
  a11y/noAutofocus
  correctness/noUnsafeOptionalChaining
  correctness/noConstAssign
  nursery/noMisplacedAssertion
  suspicious/noControlCharactersInRegex
  style/noVar
  suspicious/noDoubleEquals
  suspicious/noEmptyInterface
  suspicious/noConstEnum
  nursery/noDuplicateElseIf
  correctness/noPrecisionLoss
  nursery/noRestrictedImports
  nursery/noUnknownFunction
  correctness/noSetterReturn
  correctness/noInvalidConstructorSuper
  suspicious/noImplicitAnyLet
  a11y/useKeyWithClickEvents
  suspicious/noDuplicateObjectKeys
  suspicious/noUnsafeDeclarationMerging
  correctness/noInnerDeclarations
  correctness/useArrayLiterals
  style/noUselessElse
  complexity/noUselessLabel
  complexity/noUselessCatch
  a11y/useAriaPropsForRole
  style/useCollapsedElseIf
  correctness/noNonoctalDecimalEscape
  suspicious/noDuplicateTestHooks
  nursery/noUnknownMediaFeatureName
  a11y/noInteractiveElementToNoninteractiveRole
  nursery/noEmptyBlock
  suspicious/noLabelVar
  suspicious/noApproximativeNumericConstant
  correctness/noNodejsModules
  correctness/noUnnecessaryContinue
  correctness/noEmptyCharacterClassInRegex
  suspicious/noSparseArray
  a11y/useIframeTitle
  nursery/useDefaultSwitchClause
  a11y/noSvgWithoutTitle
  correctness/noVoidElementsWithChildren
  correctness/useJsxKeyInIterable
  style/useExportType
  complexity/noUselessLoneBlockStatements
  style/noArguments
  a11y/useValidAriaValues
  suspicious/noGlobalAssign
  suspicious/noCommentText
  suspicious/noThenProperty
  suspicious/useGetterReturn
  style/useFragmentSyntax
  a11y/noPositiveTabindex
  style/useNamingConvention
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  a11y/noRedundantRoles
  correctness/noUnusedVariables
  suspicious/noSelfCompare
  nursery/useErrorMessage
  suspicious/noAsyncPromiseExecutor
  security/noDangerouslySetInnerHtml
  style/useNodejsImportProtocol
  suspicious/noArrayIndexKey
  complexity/noWith
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  performance/noAccumulatingSpread
  suspicious/noConfusingLabels
  correctness/noChildrenProp
  nursery/noDuplicateSelectorsKeyframeBlock
  nursery/useImportExtensions
  a11y/noAriaUnsupportedElements
  style/noShoutyConstants
  correctness/noFlatMapIdentity
  a11y/noBlankTarget
  a11y/useHeadingContent
  correctness/useValidForDirection
  nursery/noDoneCallback
  correctness/noInvalidUseBeforeDeclaration
  a11y/noAriaHiddenOnFocusable
  style/useBlockStatements
  correctness/noInvalidNewBuiltin
  style/noNegationElse
  complexity/useSimplifiedLogicExpression
  nursery/useSortedClasses
  style/noRestrictedGlobals
  style/noNamespaceImport
  style/noUnusedTemplateLiteral
  correctness/noUndeclaredVariables
  style/useExponentiationOperator
  nursery/useAdjacentOverloadSignatures
  nursery/noUnknownProperty
  nursery/noReactSpecificProps
  style/noNamespace
  complexity/noUselessFragments
  nursery/noDuplicateAtImportRules
  correctness/noUnusedImports
  suspicious/noFunctionAssign
  performance/noDelete
  suspicious/noUnsafeNegation
  a11y/useValidLang
  nursery/noUndeclaredDependencies
  suspicious/useValidTypeof
  a11y/useValidAriaRole
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  complexity/noUselessTernary
  suspicious/noExplicitAny
  correctness/noSwitchDeclarations
  complexity/noUselessTypeConstraint
  suspicious/noRedundantUseStrict
  style/useLiteralEnumMembers
  nursery/noUselessUndefinedInitialization
  suspicious/noGlobalIsNan
  nursery/noInvalidPositionAtImportRule
  suspicious/noSkippedTests
  suspicious/noMisleadingCharacterClass
  nursery/noUnmatchableAnbSelector
  nursery/noUnknownSelectorPseudoElement
  correctness/noStringCaseMismatch
  suspicious/noRedeclare
  suspicious/noFallthroughSwitchClause
  nursery/useExplicitLengthCheck
  complexity/noUselessThisAlias
  correctness/noUnreachable
  nursery/noImportantInKeyframe
  nursery/noUselessStringConcat
  complexity/noThisInStatic
  complexity/useOptionalChain
  suspicious/noDuplicateCase
  style/noParameterAssign
  nursery/noLabelWithoutControl
  a11y/useValidAnchor
  complexity/useRegexLiterals
  correctness/noSelfAssign
  nursery/useThrowNewError
  style/useShorthandFunctionType
  style/useSingleCaseStatement
  nursery/noUnusedFunctionParameters
  suspicious/noEmptyBlockStatements
  suspicious/noShadowRestrictedNames
  a11y/useMediaCaption
  nursery/noDuplicateFontNames
  correctness/noUnsafeFinally
  style/useNodeAssertStrict
  style/useEnumInitializers
  a11y/useHtmlLang
  style/useWhile
  complexity/useArrowFunction
  style/noInferrableTypes
  a11y/noNoninteractiveTabindex
  complexity/useSimpleNumberKeys
  correctness/useYield
  nursery/useTopLevelRegex
  style/useNumericLiterals
  suspicious/noImportAssign
  suspicious/useDefaultSwitchClauseLast
  correctness/noGlobalObjectCalls
  style/noParameterProperties
  a11y/useAltText
  nursery/useNumberToFixedDigitsArgument
  performance/noBarrelFile
  suspicious/noSuspiciousSemicolonInJsx
  complexity/noBannedTypes
  suspicious/noPrototypeBuiltins
  style/useAsConstAssertion
  suspicious/noDebugger
  suspicious/noMisleadingInstantiator
  complexity/noVoid
  suspicious/noDuplicateJsxProps
  correctness/noEmptyPattern
  nursery/noDuplicateJsonKeys
  complexity/noExcessiveNestedTestSuites
  performance/noReExportAll
  a11y/useKeyWithMouseEvents
  nursery/useConsistentBuiltinInstantiation
  security/noDangerouslySetInnerHtmlWithChildren
  suspicious/noExtraNonNullAssertion
  style/useConst
  style/noNonNullAssertion
  complexity/useFlatMap
  correctness/useHookAtTopLevel
  correctness/useIsNan
  suspicious/noGlobalIsFinite
  a11y/noDistractingElements
  style/useConsistentArrayType
  nursery/useFocusableInteractive
  style/useForOf
  a11y/useValidAriaProps
  a11y/noRedundantAlt
  nursery/useSemanticElements
  nursery/useGenericFontNames
  suspicious/noConfusingVoidType
  suspicious/noFocusedTests
  a11y/useButtonType
  nursery/useDateNow
  style/useFilenamingConvention
  style/useShorthandArrayType
  style/useShorthandAssign
  correctness/noConstantMathMinMaxClamp
  correctness/noUnusedPrivateClassMembers
  correctness/noVoidTypeReturn
  a11y/useAnchorContent
  complexity/noUselessRename
  style/useNumberNamespace
  complexity/noUselessConstructor
  a11y/noAccessKey
  nursery/noUnknownUnit
  style/noDefaultExport
  style/useSingleVarDeclarator
  suspicious/noExportsInTest
  a11y/noNoninteractiveElementToInteractiveRole
  style/noCommaOperator
  suspicious/noConsoleLog
  suspicious/useIsArray
  a11y/noHeaderScope
  correctness/noNewSymbol
  suspicious/noMisrefactoredShorthandAssign
  complexity/noForEach
  suspicious/noClassAssign
  style/noImplicitBoolean
  nursery/noEvolvingTypes

Workspace:
  Open Documents:               0

Rule name

nursery/useDateNow

Playground link

https://biomejs.dev/playground/?lintRules=all&code=WwAnADIAMAAyADAALQAwADIALQAwADIAJwBdAC4AbQBhAHAAKABuACAAPQA%2BACAAbgBlAHcAIABEAGEAdABlACgAbgApAC4AZwBlAHQAVABpAG0AZQAoACkAKQA%3D

Expected result

The use of Date.prototype.getTime in the code below should be valid without any warning:

['2020-02-02'].map(n => new Date(n).getTime()); // no warning or fix is needed

Actual result

The nursery/useDateNow incorrectly flags the code below as warning due to the use of Date.prototype.getTime:

['2020-02-02'].map(n => new Date(n).getTime()); // Use Date.now() instead of new Date().getTime.

// after unsafe fix it becomes `['2020-02-02'].map((_n) => Date.now());` which is totally incorrect

Code of Conduct

  • I agree to follow Biome's Code of Conduct

@minht11 Are you interested in fixing this issue?

Yeah, will look into it.