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

💅 noUnusedImports warns used types in declaring modules #3895

Closed
1 task done
AhmedBaset opened this issue Sep 14, 2024 · 8 comments · Fixed by #4597
Closed
1 task done

💅 noUnusedImports warns used types in declaring modules #3895

AhmedBaset opened this issue Sep 14, 2024 · 8 comments · Fixed by #4597
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

@AhmedBaset
Copy link

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

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

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
  complexity/noMultipleSpacesInRegularExpressionLiterals
  a11y/useValidLang
  complexity/noUselessEmptyExport
  suspicious/useNamespaceKeyword
  nursery/noConsole
  a11y/useValidAriaRole
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  suspicious/noAssignInExpressions
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  suspicious/noDuplicateParameters
  suspicious/useValidTypeof
  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
  suspicious/noUnsafeDeclarationMerging
  correctness/noUnreachable
  a11y/useKeyWithClickEvents
  suspicious/noDuplicateObjectKeys
  complexity/noUselessThisAlias
  complexity/noThisInStatic
  complexity/useOptionalChain
  correctness/noInnerDeclarations
  suspicious/noDuplicateCase
  a11y/useValidAnchor
  complexity/useRegexLiterals
  correctness/noSelfAssign
  style/useShorthandFunctionType
  suspicious/noShadowRestrictedNames
  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
  correctness/noVoidElementsWithChildren
  suspicious/noPrototypeBuiltins
  style/useAsConstAssertion
  correctness/useJsxKeyInIterable
  style/useExportType
  complexity/noUselessLoneBlockStatements
  suspicious/noMisleadingInstantiator
  suspicious/noDebugger
  style/noArguments
  a11y/useValidAriaValues
  suspicious/noCommentText
  suspicious/noGlobalAssign
  suspicious/noThenProperty
  suspicious/noDuplicateJsxProps
  suspicious/useGetterReturn
  a11y/noPositiveTabindex
  correctness/noEmptyPattern
  complexity/noExcessiveNestedTestSuites
  security/noDangerouslySetInnerHtmlWithChildren
  a11y/useKeyWithMouseEvents
  suspicious/noExtraNonNullAssertion
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  style/useConst
  a11y/noRedundantRoles
  complexity/useFlatMap
  correctness/useIsNan
  suspicious/noGlobalIsFinite
  suspicious/noSelfCompare
  suspicious/noAsyncPromiseExecutor
  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
  style/useExponentiationOperator
  style/noUnusedTemplateLiteral
  complexity/noUselessSwitchCase
  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

Rule name

noUnusedImports

Playground link

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

Expected result

declare module "package" {
  import type { Type } from "dep";
  //                      ^^^^ This import is unused. lint/correctness/noUnusedImports

  export const x: {
    y: Type
  }
}

This shouldn't error

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@AhmedBaset
Copy link
Author

What?!

Screencast.from.15-09-24.00.59.58.webm

It happens with both CLI and the VSCode extension

@Conaclos
Copy link
Member

As a workaround, you can move the import type in the global scope:

import type { Linter } from "eslint";

declare module "eslint-plugin-jsx-a11y" {
  export const flatConfigs: {
    readonly recommended: { readonly rules: Readonly<Linter.RulesRecord> };
    readonly strict: { readonly rules: Readonly<Linter.RulesRecord> };
  };
}

@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 15, 2024
@fireairforce
Copy link
Member

it looks like a semantic bug

@Conaclos
Copy link
Member

Yes, it is a bug in the semantic model. Unfortunately it is a complex one. I didn't find an easy way to address this bug. It is low priority.

@stavalfi
Copy link

@Conaclos the autofix of this is to eliminate the import which causes a compilation error. Can you give it a quick try again?

awasome project, really! thanks!

@ematipico
Copy link
Member

@Conaclos the autofix of this is to eliminate the import which causes a compilation error. Can you give it a quick try again?

awasome project, really! thanks!

Your concern is addressed in another issue and it's unrelated to this issue. It's not a bug and we plan to address it in v2

@stavalfi
Copy link

stavalfi commented Feb 3, 2025

@ematipico
i took the nightly build (1.9.5-nightly.81fdedb) and when there is a js syntax error and i save the file, some imports are deleted. when i disable this rule, all works.

I couldn't find a newer version.

import { Logger } from "@p/observability";
import {
  closeDependencies,
  initDependencies,
} from "@/app/clients/ApiClient.Utils";
import { Redis } from "@p/redis";
const log = new Logger();

const main = async () => {
  log.info(`
sssssssss
  `);
...................
import { Logger } from "@p/observability";
const log = new Logger();

const main = async () => {
  log.info(
sssssssss
  `);
..........................

the following lines were deleted:

import {
  closeDependencies,
  initDependencies,
} from "@/app/clients/ApiClient.Utils";
import { Redis } from "@p/redis";

@Conaclos
Copy link
Member

Conaclos commented Feb 3, 2025

@stavalfi If the issue is different from the current one, could you open a new issue?
Also, could you share a reproduction?

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
Development

Successfully merging a pull request may close this issue.

5 participants