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
15.12k stars 471 forks source link

💅 `useExhaustiveDependencies` incorrectly evaluates property access of non-null operator asserted object #3685

Open arnorhs opened 2 months ago

arnorhs commented 2 months ago

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.20.2"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           true
  Linter disabled:              false
  Organize imports disabled:    true
  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/noMultipleSpacesInRegularExpressionLiterals
  a11y/useValidLang
  complexity/noUselessEmptyExport
  suspicious/useNamespaceKeyword
  suspicious/useValidTypeof
  a11y/useValidAriaRole
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  suspicious/noDuplicateParameters
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  correctness/noUnusedLabels
  correctness/noUnreachableSuper
  suspicious/noCompareNegZero
  correctness/noUnsafeOptionalChaining
  correctness/noConstAssign
  suspicious/noControlCharactersInRegex
  suspicious/noRedundantUseStrict
  suspicious/noDoubleEquals
  style/useLiteralEnumMembers
  suspicious/noEmptyInterface
  suspicious/noConstEnum
  suspicious/noMisleadingCharacterClass
  correctness/noPrecisionLoss
  correctness/noStringCaseMismatch
  correctness/noSetterReturn
  correctness/noInvalidConstructorSuper
  suspicious/noDuplicateObjectKeys
  suspicious/noUnsafeDeclarationMerging
  correctness/noUnreachable
  suspicious/noFallthroughSwitchClause
  complexity/noUselessThisAlias
  complexity/noThisInStatic
  suspicious/noDuplicateCase
  complexity/useRegexLiterals
  correctness/noSelfAssign
  style/useShorthandFunctionType
  a11y/useMediaCaption
  complexity/noUselessLabel
  complexity/noUselessCatch
  correctness/noUnsafeFinally
  a11y/useAriaPropsForRole
  correctness/noNonoctalDecimalEscape
  style/useEnumInitializers
  a11y/useHtmlLang
  suspicious/noDuplicateTestHooks
  complexity/noStaticOnlyClass
  style/useWhile
  suspicious/noImportAssign
  style/useNumericLiterals
  a11y/noNoninteractiveTabindex
  complexity/useSimpleNumberKeys
  correctness/useYield
  a11y/noInteractiveElementToNoninteractiveRole
  suspicious/noLabelVar
  correctness/noUnnecessaryContinue
  suspicious/noApproximativeNumericConstant
  suspicious/useDefaultSwitchClauseLast
  correctness/noGlobalObjectCalls
  a11y/useAltText
  correctness/noEmptyCharacterClassInRegex
  suspicious/noSuspiciousSemicolonInJsx
  suspicious/noSparseArray
  a11y/useIframeTitle
  correctness/noVoidElementsWithChildren
  style/useAsConstAssertion
  suspicious/noDebugger
  style/useExportType
  complexity/noUselessLoneBlockStatements
  style/noArguments
  a11y/useValidAriaValues
  suspicious/noGlobalAssign
  suspicious/noCommentText
  suspicious/noMisleadingInstantiator
  suspicious/noThenProperty
  suspicious/useGetterReturn
  suspicious/noDuplicateJsxProps
  a11y/noPositiveTabindex
  correctness/noEmptyPattern
  complexity/noExcessiveNestedTestSuites
  suspicious/noExtraNonNullAssertion
  a11y/useKeyWithMouseEvents
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  a11y/noRedundantRoles
  suspicious/noSelfCompare
  correctness/useIsNan
  suspicious/noGlobalIsFinite
  suspicious/noAsyncPromiseExecutor
  style/useNodejsImportProtocol
  a11y/noDistractingElements
  complexity/noWith
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  performance/noAccumulatingSpread
  a11y/useValidAriaProps
  suspicious/noConfusingLabels
  suspicious/noConfusingVoidType
  suspicious/noFocusedTests
  a11y/noAriaUnsupportedElements
  correctness/noFlatMapIdentity
  a11y/useHeadingContent
  correctness/useValidForDirection
  correctness/noVoidTypeReturn
  correctness/noInvalidUseBeforeDeclaration
  a11y/noAriaHiddenOnFocusable
  a11y/useAnchorContent
  correctness/noInvalidNewBuiltin
  complexity/noUselessConstructor
  a11y/noAccessKey
  style/useExponentiationOperator
  complexity/noUselessSwitchCase
  style/useSingleVarDeclarator
  a11y/noNoninteractiveElementToInteractiveRole
  style/noCommaOperator
  suspicious/useIsArray
  a11y/noHeaderScope
  suspicious/noMisrefactoredShorthandAssign
  suspicious/noClassAssign
  suspicious/noFunctionAssign

Workspace:
  Open Documents:               0

Rule name

lint/correctness/useExhaustiveDependencies

Playground link

https://biomejs.dev/playground/?indentStyle=space&quoteStyle=single&jsxQuoteStyle=single&semicolons=as-needed&lintRules=all&code=aQBtAHAAbwByAHQAIAB7ACAAdQBzAGUATQBlAG0AbwAgAH0AIABmAHIAbwBtACAAJwByAGUAYQBjAHQAJwAKAAoALwAqACAAYwBvAG4AdABlAHgAdAA6AAoACgBTAG8AIAB0AGgAaQBzACAAbABpAG4AdAAgAHIAdQBsAGUAIABzAGUAZQBtAHMAIAB0AG8AIAB3AG8AcgBrACAAYwBvAHIAcgBlAGMAdABsAHkAIABmAG8AcgAgAG0AbwBzAHQAIABjAGEAcwBlAHMALAAgAGkAbgBjAGwAdQBkAGkAbgBnAAoAbwBwAHQAaQBvAG4AYQBsACAAYwBoAGEAaQBuAGUAZAAgAHYAYQBsAHUAZQBzACwAIABhAG4AZAAgAG4AdQBsAGwAIABjAG8AYQBsAGUAcwBjAGkAbgBnACAAZgBhAGwAbABiAGEAYwBrACAAdgBhAGwAdQBlAHMAIABlAHQAYwAKAGIAdQB0ACAAaQB0ACAAZABvAGUAcwAgAG4AbwB0ACAAdwBvAHIAawAgAHcAaABlAG4AIAB5AG8AdQAgAGgAYQB2AGUAIABhACAAbwBwAGUAc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BuAG8AdwAgAHQAaABhAHQALAAgAHMAbwAgAHcAZQAgAGEAcwBzAGUAcgB0ACAAaQB0ACAAdABvACAAYgBlACAAdAByAHUAZQAgAHcAaQB0AGgAIAB0AGgAZQAgAG8AcABlAHIAYQB0AG8AcgAKACAAIAByAGUAdAB1AHIAbgAgAHsAIAB4ADoAIAAnAGEAcwBkAGYAJwAgAH0AIABhAHMAIAB7ACAAeAA6ACAAcwB0AHIAaQBuAGcAIAB9ACAAfAAgAG4AdQBsAGwACgB9AA%3D%3D

Expected result

I expected the check to realize that the provided dependency is correct according to the function body, but instead it reports that i'm specifying both too many dependencies and also missing dependencies

Code of Conduct

h-a-n-a commented 1 month ago

I think this is a bug. You may temporarily put non-null assertion to:

// biome-ignore lint/style/noNonNullAssertion: allow here
const myObj = useMyObj()!;

until this is fixed.