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

💅 noTypeOnlyImportAttributes errors are flagged when linter is diabled #4361

Closed
1 task done
JacobLey opened this issue Oct 21, 2024 · 2 comments · Fixed by #4364
Closed
1 task done

💅 noTypeOnlyImportAttributes errors are flagged when linter is diabled #4361

JacobLey opened this issue Oct 21, 2024 · 2 comments · Fixed by #4364
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

@JacobLey
Copy link

JacobLey commented Oct 21, 2024

Environment information

CLI:
  Version:                      1.9.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.7.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

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

Linter:
  JavaScript enabled:           false
  JSON enabled:                 false
  CSS enabled:                  true
  GraphQL enabled:              false
  Recommended:                  false
  All:                          false
  Enabled rules:
  performance/noDelete
  suspicious/noCatchAssign
  suspicious/noUnsafeNegation
  complexity/useLiteralKeys
  style/useImportType
  complexity/noMultipleSpacesInRegularExpressionLiterals
  a11y/useValidLang
  complexity/noUselessEmptyExport
  suspicious/useNamespaceKeyword
  suspicious/useValidTypeof
  a11y/useValidAriaRole
  correctness/noConstantCondition
  a11y/useAriaActivedescendantWithTabindex
  suspicious/noAssignInExpressions
  style/useDefaultParameterLast
  complexity/noEmptyTypeParameters
  correctness/noConstructorReturn
  style/useSelfClosingElements
  suspicious/noDuplicateParameters
  suspicious/noDuplicateSelectorsKeyframeBlock
  correctness/noUnknownProperty
  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
  a11y/noLabelWithoutControl
  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
  style/noParameterAssign
  suspicious/noDuplicateCase
  a11y/useValidAnchor
  complexity/useRegexLiterals
  correctness/noSelfAssign
  correctness/noInvalidBuiltinInstantiation
  style/noUselessElse
  style/useShorthandFunctionType
  suspicious/noShadowRestrictedNames
  correctness/noInvalidDirectionInLinearGradient
  suspicious/noImportantInKeyframe
  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
  correctness/noUnknownUnit
  suspicious/noSparseArray
  a11y/useIframeTitle
  complexity/noBannedTypes
  a11y/noSvgWithoutTitle
  correctness/noVoidElementsWithChildren
  style/useAsConstAssertion
  correctness/useJsxKeyInIterable
  style/useExportType
  complexity/noUselessLoneBlockStatements
  style/noArguments
  suspicious/noDebugger
  a11y/useValidAriaValues
  suspicious/noCommentText
  a11y/useFocusableInteractive
  correctness/noUnmatchableAnbSelector
  suspicious/noGlobalAssign
  suspicious/noDuplicateJsxProps
  suspicious/noMisleadingInstantiator
  a11y/noPositiveTabindex
  correctness/noEmptyPattern
  complexity/noExcessiveNestedTestSuites
  security/noDangerouslySetInnerHtmlWithChildren
  a11y/useKeyWithMouseEvents
  suspicious/noExtraNonNullAssertion
  suspicious/noShorthandPropertyOverrides
  correctness/noRenderReturnValue
  correctness/useExhaustiveDependencies
  security/noGlobalEval
  style/noNonNullAssertion
  a11y/noRedundantRoles
  complexity/useFlatMap
  correctness/useIsNan
  style/useConst
  suspicious/noGlobalIsFinite
  suspicious/noSelfCompare
  suspicious/noThenProperty
  suspicious/noAsyncPromiseExecutor
  suspicious/noDuplicateFontNames
  suspicious/useGetterReturn
  security/noDangerouslySetInnerHtml
  style/useNodejsImportProtocol
  a11y/noDistractingElements
  suspicious/noArrayIndexKey
  complexity/noWith
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  performance/noAccumulatingSpread
  a11y/useValidAriaProps
  a11y/noRedundantAlt
  correctness/noChildrenProp
  correctness/noUnknownFunction
  correctness/noInvalidPositionAtImportRule
  suspicious/noConfusingLabels
  suspicious/noPrototypeBuiltins
  suspicious/noConfusingVoidType
  suspicious/noFocusedTests
  a11y/useButtonType
  a11y/useSemanticElements
  a11y/noAriaUnsupportedElements
  correctness/noInvalidGridAreas
  correctness/noFlatMapIdentity
  suspicious/noSuspiciousSemicolonInJsx
  a11y/noBlankTarget
  a11y/useHeadingContent
  correctness/useValidForDirection
  correctness/noVoidTypeReturn
  correctness/noInvalidUseBeforeDeclaration
  a11y/noAriaHiddenOnFocusable
  a11y/useGenericFontNames
  correctness/noUnknownMediaFeatureName
  a11y/useAnchorContent
  complexity/noUselessRename
  style/useNumberNamespace
  complexity/noUselessConstructor
  a11y/noAccessKey
  style/useExponentiationOperator
  style/noUnusedTemplateLiteral
  complexity/noUselessSwitchCase
  style/useSingleVarDeclarator
  suspicious/noExportsInTest
  a11y/noNoninteractiveElementToInteractiveRole
  style/noCommaOperator
  suspicious/noDuplicateAtImportRules
  suspicious/useIsArray
  a11y/noHeaderScope
  complexity/noUselessFragments
  suspicious/noMisrefactoredShorthandAssign
  complexity/noForEach
  suspicious/noClassAssign
  suspicious/noEmptyBlock
  suspicious/noFunctionAssign

Workspace:
  Open Documents:               0

Rule name

noTypeOnlyImportAttributes

Playground link

https://biomejs.dev/playground/?enabledLinting=false&code=aQBtAHAAbwByAHQAIAB0AHkAcABlACAAKgAgAGEAcwAgAEYAbwBvACAAZgByAG8AbQAgACcAZgBvAG8AJwAgAHcAaQB0AGgAIAB7ACAAJwByAGUAcwBvAGwAdQB0AGkAbwBuAC0AbQBvAGQAZQAnADoAIAAnAGkAbQBwAG8AcgB0ACcAIAB9ADsACgAKAC8ALwAgAGIAaQBvAG0AZQAtAGkAZwBuAG8AcgBlACAAbABpAG4AdAA6ACAARABvAGUAcwBuACcAdAAgAHMAdQBwAHAAbwByAHQAIABiAGUAaQBuAGcAIABkAGkAcwBhAGIAbABlAGQAIABkAGkAcgBlAGMAdABsAHkACgBpAG0AcABvAHIAdAAgAHQAeQBwAGUAIAAqACAAYQBzACAAQgBhAHIAIABmAHIAbwBtACAAJwBiAGEAcgAnACAAdwBpAHQAaAAgAHsAIAAnAHIAZQBzAG8AbAB1AHQAaQBvAG4ALQBtAG8AZABlACcAOgAgACcAaQBtAHAAbwByAHQAJwAgAH0AOwA%3D

Expected result

The linter error

Import attributes cannot be used with a type-only import

should not be flagged on this file because linting has been disabled.
See the "linter enabled" checkbox on the side of playground, which to my knowledge is the equivalent to

{
  "javascript": {
    "linter": {
      "enabled": false
    }
  },
  "linter": {
    "enabled": false
  }
}

setting in a biome.json file.

Note that it is a linter error (not a formatter) because it can be manually disabled via an ignore lint comment.

I'm not sure if related, but this rule does not show up in the config: https://github.com/biomejs/biome/blob/main/packages/%40biomejs/biome/configuration_schema.json#L720 so I'm also not able to explicitly disable it in biome.json (although again I would expect a global enabled=false to cover it already)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

As far as I am concerned, simply allowing me to disable this rule alongside the rest of linting is good enough for me.

That being said, I would also disagree with the logic of this rule for certain use cases

When writing a CJS file and importing from an ESM file, typescript requires this annotation:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("package-name")' call instead.

See a similar discussion in a previous issue: #2115
Where I actually moved over to this approach as a workaround initially.

This would require biome to have typescript knowledge of "this is CJS and target is ESM", which I'm not sure it is capable of today...

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@JacobLey JacobLey added the S-Needs triage Status: this issue needs to be triaged label Oct 21, 2024
@Conaclos
Copy link
Member

This is a syntax rule that cannot be disabled because it is considered as a syntax error. Have you some evidence that TypeScript allows this?

@Conaclos Conaclos added S-Needs response Status: await response from OP and removed S-Needs triage Status: this issue needs to be triaged labels Oct 21, 2024
@JacobLey
Copy link
Author

Have you some evidence that TypeScript allows this?

Yes this is a relatively new feature in Typescript, but it is officially supported.
Its tricky to replicate in TS Playground (because you can't explicitly flag your file as CJS) but I can point to the actual file where I am using this in my codebase: https://github.com/JacobLey/leyman/blob/194f88d69e4c1bc7d1dd5696736357765caa1b18/tools/common-proxy/src/common-proxy.cts#L1

Probably the best documentation right now is the conversations on the Typescript Github

@Conaclos Conaclos self-assigned this Oct 22, 2024
@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 and removed S-Needs response Status: await response from OP labels Oct 22, 2024
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.

2 participants