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

💅 false positive noStaticOnlyClass #3612

Closed
1 task done
kyptov opened this issue Aug 7, 2024 · 3 comments · Fixed by #3626
Closed
1 task done

💅 false positive noStaticOnlyClass #3612

kyptov opened this issue Aug 7, 2024 · 3 comments · Fixed by #3626
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

@kyptov
Copy link

kyptov commented Aug 7, 2024

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           "v20.16.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.8.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:                  false
  Recommended:                  false
  All:                          false
  Enabled rules:
  complexity/noBannedTypes
  suspicious/noCatchAssign
  suspicious/noPrototypeBuiltins
  complexity/useLiteralKeys
  suspicious/noMisleadingInstantiator
  suspicious/noDebugger
  complexity/noMultipleSpacesInRegularExpressionLiterals
  complexity/noUselessLoneBlockStatements
  complexity/noVoid
  suspicious/noGlobalAssign
  suspicious/noUnsafeNegation
  suspicious/useValidTypeof
  correctness/noConstantCondition
  suspicious/noDuplicateParameters
  correctness/noEmptyPattern
  suspicious/noExtraNonNullAssertion
  complexity/noUselessTernary
  style/useConst
  suspicious/noCompareNegZero
  suspicious/noSelfCompare
  correctness/noUnreachableSuper
  security/noGlobalEval
  style/noNonNullAssertion
  correctness/noConstAssign
  correctness/noUnusedVariables
  correctness/useIsNan
  suspicious/noAsyncPromiseExecutor
  correctness/noSwitchDeclarations
  suspicious/noControlCharactersInRegex
  complexity/noUselessTypeConstraint
  style/noVar
  suspicious/noDoubleEquals
  style/useConsistentArrayType
  complexity/noWith
  suspicious/noDuplicateClassMembers
  complexity/noExtraBooleanCast
  suspicious/noMisleadingCharacterClass
  correctness/noPrecisionLoss
  suspicious/noRedeclare
  correctness/noInvalidConstructorSuper
  suspicious/noDuplicateObjectKeys
  suspicious/noFallthroughSwitchClause
  correctness/noUnreachable
  suspicious/noConfusingVoidType
  complexity/useOptionalChain
  suspicious/noDuplicateCase
  complexity/useRegexLiterals
  correctness/noSelfAssign
  style/useShorthandFunctionType
  suspicious/noEmptyBlockStatements
  suspicious/noShadowRestrictedNames
  complexity/noUselessCatch
  correctness/noInvalidUseBeforeDeclaration
  correctness/noUnsafeFinally
  style/useBlockStatements
  complexity/noUselessRename
  complexity/noUselessConstructor
  style/useEnumInitializers
  style/noDefaultExport
  complexity/noStaticOnlyClass
  style/useSingleVarDeclarator
  suspicious/noImportAssign
  style/noCommaOperator
  suspicious/useDefaultSwitchClauseLast
  style/noNamespace
  correctness/noGlobalObjectCalls
  correctness/noNewSymbol
  correctness/noEmptyCharacterClassInRegex
  suspicious/noClassAssign
  suspicious/noFunctionAssign

Workspace:
  Open Documents:               0

Rule name

noStaticOnlyClass

Playground link

https://biomejs.dev/playground/?lintRules=all&code=YQBiAHMAdAByAGEAYwB0ACAAYwBsAGEAcwBzACAARQBuAHQAaQB0AHkAPABUAD4AIAB7AAoAIAAgAHAAcgBvAHQAZQBjAHQAZQBkACAAYwBvAG4AcwB0AHIAdQBjAHQAbwByACgAcAByAGkAdgBhAHQAZQAgAHIAZQBhAGQAbwBuAGwAeQAgAHAAcgBvAHAAcwA6ACAAVAApACAAewB9AAoACgAgACAAZwBlAHQAIABwAHIAbwBwAHMAKAApADoAIABUACAAewAKACAAIAAgACAAcgBlAHQAdQByAG4AIAB0AGgAaQBzAC4AcAByAG8AcABzAAoAIAAgAH0ACgB9AAoACgBjAGwAYQBzAHMAIABNAHkAQwBsAGEAcwBzACAAZQB4AHQAZQBuAGQAcwAgAEUAbgB0AGkAdAB5ADwAewB2AGEAbAB1AGUAOgAgAHMAdAByAGkAbgBnAH0APgAgAHsACgAgACAAcwB0AGEAdABpAGMAIABjAHIAZQBhAHQAZQAoAHYAYQBsAHUAZQA6ACAAcwB0AHIAaQBuAGcAKQA6ACAATQB5AEMAbABhAHMAcwAgAHsACgAgACAAIAAgACAAIAByAGUAdAB1AHIAbgAgAG4AZQB3ACAATQB5AEMAbABhAHMAcwAoAHsAIAB2AGEAbAB1AGUAIAB9ACkACgAgACAAfQAKAH0ACgAKAGMAbwBuAHMAdAAgAG0AeQBDAGwAYQBzAHMAIAA9ACAATQB5AEMAbABhAHMAcwAuAGMAcgBlAGEAdABlACgAJwBtAHkALQBjAGwAYQBzAHMAJwApAAoACgBjAG8AbgBzAG8AbABlAC4AbABvAGcAKABtAHkAQwBsAGEAcwBzAC4AcAByAG8AcABzACkA

Expected result

I have a class with only static methods, but this class extends another class with non-static methods. Biome proposes that I replace my static method with a function. I expect no errors here as my class has non-static methods via inheritance.

Code of Conduct

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

A possible fix could be to ignore classes that inherit other classes.

@ematipico ematipico 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 Aug 7, 2024
@Conaclos
Copy link
Member

Conaclos commented Aug 8, 2024

kyptov just wondering: there is any practical code doing this?

A possible fix could be to ignore classes that inherit other classes.

Yeah, this looks like a fair fix.

@kyptov
Copy link
Author

kyptov commented Aug 8, 2024

kyptov just wondering: there is any practical code doing this?

  • Having an empty class with different props? Yes, it helps to distinguish one type from another. But most of them are not empty.
  • A static method for creating a class? Yes, it allows you to make the constructor protected, which forces the use of the static method where some validation can be added. I like when the class and its validation reside in one place. Also, we are injecting this static method as a function, which allows us to mock it in unit tests.
  • Parent Entity class? Yes, it simplifies database interactions.

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