Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 noUndeclaredDependencies false positive with type-only imports #3872

Closed
1 task done
mrazauskas opened this issue Sep 13, 2024 · 3 comments · Fixed by #3893
Closed
1 task done

💅 noUndeclaredDependencies false positive with type-only imports #3872

mrazauskas opened this issue Sep 13, 2024 · 3 comments · Fixed by #3893
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@mrazauskas
Copy link
Contributor

Environment information

CLI:
  Version:                      1.9.0
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.17.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "yarn/4.4.1"

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:                  true
  GraphQL enabled:              false
  Recommended:                  true
  All:                          false
  Enabled rules:
  performance/noDelete
  suspicious/noCatchAssign
  suspicious/noUnsafeNegation
  complexity/noForEach
  correctness/noUnusedImports
  complexity/noUselessStringConcat
  complexity/noMultipleSpacesInRegularExpressionLiterals
  a11y/useValidLang
  complexity/noUselessEmptyExport
  suspicious/useNamespaceKeyword
  suspicious/useValidTypeof
  style/useExplicitLengthCheck
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  a11y/useValidAriaRole
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  suspicious/noAssignInExpressions
  suspicious/noDuplicateParameters
  suspicious/noDuplicateSelectorsKeyframeBlock
  correctness/noUnknownProperty
  style/useTemplate
  correctness/noUnusedLabels
  complexity/noUselessTernary
  suspicious/noExplicitAny
  correctness/noUnreachableSuper
  suspicious/noCompareNegZero
  correctness/noSwitchDeclarations
  a11y/noAutofocus
  correctness/noUnsafeOptionalChaining
  correctness/noConstAssign
  suspicious/noMisplacedAssertion
  suspicious/noControlCharactersInRegex
  complexity/noUselessTypeConstraint
  style/noVar
  suspicious/noDoubleEquals
  suspicious/noRedundantUseStrict
  style/useLiteralEnumMembers
  suspicious/noGlobalIsNan
  suspicious/noEmptyInterface
  suspicious/noSkippedTests
  style/useImportType
  suspicious/noMisleadingCharacterClass
  correctness/noPrecisionLoss
  a11y/noLabelWithoutControl
  suspicious/noRedeclare
  correctness/noStringCaseMismatch
  correctness/noSetterReturn
  correctness/noInvalidConstructorSuper
  suspicious/noImplicitAnyLet
  a11y/useKeyWithClickEvents
  suspicious/noDuplicateObjectKeys
  complexity/noUselessThisAlias
  correctness/noUnreachable
  suspicious/noFallthroughSwitchClause
  suspicious/noUnsafeDeclarationMerging
  complexity/noThisInStatic
  complexity/useOptionalChain
  correctness/noInnerDeclarations
  suspicious/noDuplicateCase
  a11y/useValidAnchor
  complexity/useRegexLiterals
  correctness/noSelfAssign
  correctness/noInvalidBuiltinInstantiation
  style/noUselessElse
  style/useShorthandFunctionType
  suspicious/noShadowRestrictedNames
  correctness/noInvalidDirectionInLinearGradient
  style/useThrowNewError
  suspicious/noImportantInKeyframe
  a11y/useMediaCaption
  complexity/noUselessLabel
  complexity/noUselessCatch
  correctness/noUnsafeFinally
  a11y/useAriaPropsForRole
  style/useCollapsedElseIf
  correctness/noNonoctalDecimalEscape
  style/useEnumInitializers
  a11y/useHtmlLang
  suspicious/noDuplicateTestHooks
  suspicious/noEvolvingTypes
  style/useWhile
  complexity/noUselessUndefinedInitialization
  complexity/useArrowFunction
  style/noInferrableTypes
  a11y/noNoninteractiveTabindex
  complexity/useSimpleNumberKeys
  correctness/useYield
  a11y/noInteractiveElementToNoninteractiveRole
  style/useNumericLiterals
  correctness/noUnnecessaryContinue
  suspicious/noApproximativeNumericConstant
  suspicious/noImportAssign
  suspicious/noLabelVar
  correctness/noGlobalObjectCalls
  style/noParameterProperties
  suspicious/useDefaultSwitchClauseLast
  correctness/noUnknownUnit
  correctness/useImportExtensions
  a11y/useAltText
  correctness/noEmptyCharacterClassInRegex
  a11y/useIframeTitle
  suspicious/noPrototypeBuiltins
  a11y/noSvgWithoutTitle
  correctness/noVoidElementsWithChildren
  style/useAsConstAssertion
  suspicious/noDebugger
  style/useExportType
  complexity/noUselessLoneBlockStatements
  style/noArguments
  a11y/useValidAriaValues
  suspicious/noGlobalAssign
  suspicious/noCommentText
  a11y/useFocusableInteractive
  correctness/noUnmatchableAnbSelector
  suspicious/noMisleadingInstantiator
  suspicious/noDuplicateJsxProps
  suspicious/noThenProperty
  a11y/noPositiveTabindex
  correctness/noEmptyPattern
  complexity/noExcessiveNestedTestSuites
  security/noDangerouslySetInnerHtmlWithChildren
  a11y/useKeyWithMouseEvents
  style/useNamingConvention
  suspicious/noExtraNonNullAssertion
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  style/noNonNullAssertion
  a11y/noRedundantRoles
  complexity/useFlatMap
  correctness/useIsNan
  correctness/noUnusedVariables
  style/useConst
  style/noYodaExpression
  suspicious/noGlobalIsFinite
  style/useConsistentBuiltinInstantiation
  suspicious/noAsyncPromiseExecutor
  suspicious/noDuplicateFontNames
  suspicious/noSelfCompare
  security/noDangerouslySetInnerHtml
  style/useNodejsImportProtocol
  a11y/noDistractingElements
  style/useConsistentArrayType
  complexity/noWith
  suspicious/noArrayIndexKey
  style/useForOf
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  performance/noAccumulatingSpread
  a11y/useValidAriaProps
  a11y/noRedundantAlt
  complexity/useDateNow
  correctness/noChildrenProp
  correctness/noInvalidPositionAtImportRule
  correctness/noUnknownFunction
  suspicious/noConfusingLabels
  suspicious/useGetterReturn
  suspicious/noConsole
  suspicious/noConfusingVoidType
  suspicious/noFocusedTests
  a11y/useButtonType
  a11y/useSemanticElements
  suspicious/noShorthandPropertyOverrides
  a11y/noAriaUnsupportedElements
  correctness/noInvalidGridAreas
  correctness/noFlatMapIdentity
  style/useShorthandAssign
  suspicious/useErrorMessage
  suspicious/noSuspiciousSemicolonInJsx
  a11y/noBlankTarget
  a11y/useHeadingContent
  suspicious/noSparseArray
  correctness/useValidForDirection
  correctness/noUnusedPrivateClassMembers
  correctness/noVoidTypeReturn
  correctness/noInvalidUseBeforeDeclaration
  a11y/noAriaHiddenOnFocusable
  a11y/useGenericFontNames
  correctness/noUnknownMediaFeatureName
  a11y/useAnchorContent
  complexity/noUselessRename
  style/useBlockStatements
  style/useNumberNamespace
  complexity/noUselessConstructor
  a11y/noAccessKey
  correctness/noUnusedFunctionParameters
  style/noUnusedTemplateLiteral
  complexity/noUselessSwitchCase
  style/useExponentiationOperator
  correctness/noUndeclaredVariables
  style/noNegationElse
  suspicious/useAwait
  style/useSingleVarDeclarator
  suspicious/noExportsInTest
  suspicious/useNumberToFixedDigitsArgument
  a11y/noNoninteractiveElementToInteractiveRole
  style/noCommaOperator
  suspicious/noDuplicateAtImportRules
  suspicious/useIsArray
  a11y/noHeaderScope
  complexity/noUselessFragments
  suspicious/noMisrefactoredShorthandAssign
  suspicious/noEmptyBlock
  suspicious/noClassAssign
  style/noImplicitBoolean
  suspicious/noFunctionAssign

Workspace:
  Open Documents:               0

Rule name

noUndeclaredDependencies

Playground link

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

Expected result

Type only imports should not be reported as errors by the noUndeclaredDependencies rule.

In the playground example you can see a type imported from react. Which is actually imported from @types/react. This means that the react package is not require and the code works correctly without installing it.

I have notice that for example noNodejsModules ignores type only imports. That sounds somewhat similar.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Conaclos
Copy link
Member

I have notice that for example noNodejsModules ignores type only imports. That sounds somewhat similar.

Or we should ensure that a type-only import has either the dependency with the same name or a dependency scoped with @types?

@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Sep 13, 2024
@mrazauskas
Copy link
Contributor Author

mrazauskas commented Sep 13, 2024

That sounds feasible. Only problem that sometimes instead of installing @types/* one can also:

declare module "react" {
  // ...
}

EDIT Hm.. Actually I am not sure if that influences imports. Sound like. I will try.

UPDATE I have added declare module "react" {} to ambient.d.ts file and import type React from "react" to index.ts. Here is what TypeScript thinks:

Screenshot 2024-09-13 at 14 27 56

@mrazauskas mrazauskas changed the title 💅 false positive noUndeclaredDependencies 💅 noUndeclaredDependencies false positive with type-only imports Sep 13, 2024
@QuentinLB
Copy link

Same issue while using @types/aws-lambda which a lot of people doing serverless import only to get type definitions without any aws-lambda package associated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
3 participants