Linter
Biome’s linter statically analyzes your code to catch common errors and to help writing idiomatic code.
Biome's linter has a total of 209 rules
Use the linter via CLI
Section titled Use the linter via CLIYou can start by running the CLI to check for possible errors using the following command:
biome lint ./src
For more information about all the available options, check the CLI page
Rule pillars
Section titled Rule pillarsWe believe that rules should be informative and explain to the user why a rule is triggered and tell the user what they should to do fix the error. A rule should follow these pillars:
- Explain to the user the error. Generally, this is the message of the diagnostic.
- Explain to the user why the error is triggered. Generally, this is implemented with an additional node.
- Tell the user what they should do. Generally, this is implemented using a code action. If a code action is not applicable a note should tell the user what they should do to fix the error.
If you think a rule doesn’t follow these pillars, please file an issue.
Code fixes
Section titled Code fixesLint rules may provide automatic code fixes. Biome distinguishes between two types of fixes.
Safe fixes
Section titled Safe fixesSafe fixes are guaranteed to not change the semantic of your code. They can be applied without explicit review.
To apply safe fixes, use --apply
:
biome check --apply ./src
Unsafe fixes
Section titled Unsafe fixesUnsafe fixes may change the semantic of your program. Therefore, it’s advised to manually review the changes.
To apply unsafe fixes, use --apply-unsafe
:
biome check --apply-unsafe ./src
Recommended rules
Section titled Recommended rulesWhen the linter is enabled, it recommends a number of rules. Recommended rules will emit error diagnostics. Below the list of recommended rules:
- noAccessKey
- noAriaHiddenOnFocusable
- noAriaUnsupportedElements
- noAutofocus
- noBlankTarget
- noDistractingElements
- noHeaderScope
- noInteractiveElementToNoninteractiveRole
- noNoninteractiveElementToInteractiveRole
- noNoninteractiveTabindex
- noPositiveTabindex
- noRedundantAlt
- noRedundantRoles
- noSvgWithoutTitle
- useAltText
- useAnchorContent
- useAriaActivedescendantWithTabindex
- useAriaPropsForRole
- useButtonType
- useHeadingContent
- useHtmlLang
- useIframeTitle
- useKeyWithClickEvents
- useKeyWithMouseEvents
- useMediaCaption
- useValidAnchor
- useValidAriaProps
- useValidAriaRole
- useValidAriaValues
- useValidLang
- noBannedTypes
- noExtraBooleanCast
- noForEach
- noMultipleSpacesInRegularExpressionLiterals
- noStaticOnlyClass
- noThisInStatic
- noUselessCatch
- noUselessConstructor
- noUselessEmptyExport
- noUselessFragments
- noUselessLabel
- noUselessRename
- noUselessSwitchCase
- noUselessThisAlias
- noUselessTypeConstraint
- noWith
- useArrowFunction
- useFlatMap
- useLiteralKeys
- useOptionalChain
- useRegexLiterals
- useSimpleNumberKeys
- noChildrenProp
- noConstAssign
- noConstantCondition
- noConstructorReturn
- noEmptyCharacterClassInRegex
- noEmptyPattern
- noGlobalObjectCalls
- noInnerDeclarations
- noInvalidConstructorSuper
- noInvalidNewBuiltin
- noNonoctalDecimalEscape
- noPrecisionLoss
- noRenderReturnValue
- noSelfAssign
- noSetterReturn
- noStringCaseMismatch
- noSwitchDeclarations
- noUnnecessaryContinue
- noUnreachable
- noUnreachableSuper
- noUnsafeFinally
- noUnsafeOptionalChaining
- noUnusedLabels
- noVoidElementsWithChildren
- noVoidTypeReturn
- useExhaustiveDependencies
- useIsNan
- useValidForDirection
- useYield
- noAccumulatingSpread
- noDelete
- noDangerouslySetInnerHtml
- noDangerouslySetInnerHtmlWithChildren
- noArguments
- noCommaOperator
- noInferrableTypes
- noNonNullAssertion
- noParameterAssign
- noUnusedTemplateLiteral
- noUselessElse
- noVar
- useAsConstAssertion
- useConst
- useDefaultParameterLast
- useEnumInitializers
- useExponentiationOperator
- useLiteralEnumMembers
- useNumericLiterals
- useSelfClosingElements
- useSingleVarDeclarator
- useTemplate
- useWhile
- noArrayIndexKey
- noAssignInExpressions
- noAsyncPromiseExecutor
- noCatchAssign
- noClassAssign
- noCommentText
- noCompareNegZero
- noConfusingLabels
- noConfusingVoidType
- noConstEnum
- noControlCharactersInRegex
- noDebugger
- noDoubleEquals
- noDuplicateCase
- noDuplicateClassMembers
- noDuplicateJsxProps
- noDuplicateObjectKeys
- noDuplicateParameters
- noEmptyInterface
- noExplicitAny
- noExtraNonNullAssertion
- noFallthroughSwitchClause
- noFunctionAssign
- noGlobalIsFinite
- noGlobalIsNan
- noImplicitAnyLet
- noImportAssign
- noLabelVar
- noMisleadingInstantiator
- noPrototypeBuiltins
- noRedeclare
- noRedundantUseStrict
- noSelfCompare
- noShadowRestrictedNames
- noSparseArray
- noUnsafeDeclarationMerging
- noUnsafeNegation
- useDefaultSwitchClauseLast
- useGetterReturn
- useIsArray
- useNamespaceKeyword
- useValidTypeof
Ignoring Code
Section titled Ignoring CodeThere are times when a developer wants to ignore a lint rule for a specific line of the code. You can achieve this by adding a suppression comment above the line that emits the lint diagnostic.
Suppression comments have the following format:
// biome-ignore lint: <explanation>// biome-ignore lint/suspicious/noDebugger: <explanation>
Where
biome-ignore
is the start of a suppression comment;lint
suppresses the linter;/suspicious/noDebugger
: optional, group and name of the rule you want to suppress;<explanation>
explanation why the rule is disabled
Here’s an example:
// biome-ignore lint: reasondebugger;// biome-ignore lint/suspicious/noDebugger: reasondebugger;
Configuration
Section titled ConfigurationEnable a lint rule
Section titled Enable a lint ruleRecommended rules are enabled by default and emit diagnostics with the error severity. Rules that are not recommended are disabled by default, but they can be enabled via configuration. The diagnostics emitted by these rules are displayed with the warning severity in the documentation.
To enable rules, you need to change their diagnostic severity based on your needs:
{ "linter": { "enabled": true, "rules": { "style": { "useBlockStatements": "error", "useShorthandArrayType": "error", "noShoutyConstants": "warn" } } }}
Disable a lint rule
Section titled Disable a lint ruleJust add "off"
as value inside its configuration. For example:
{ "linter": { "enabled": true, "rules": { "suspicious": { "noCommentText": "off" }, "style": { "noUnusedTemplateLiteral": "off" } } }}
Change the diagnostic severity
Section titled Change the diagnostic severityMost of Biome’s rules will emit an error, but you are free to change their severity.
Just add "warn"
as value of the rule. Example:
{ "linter": { "enabled": true, "rules": { "suspicious": { "noCommentText": "warn" } } }}
This is useful in cases there’s being a refactor going on and there’s need to make the CI passing.
Rule options
Section titled Rule optionsA few rules have options. When they do accept some, you can pass them by shaping the value of the rule differently.
{ "linter": { "enabled": true, "rules": { "correctness": { "noCommentText": { "level": "warn", "options": {} } } } }}
level
will indicate the severity of the diagnostic, valid values are:"off"
,"warn"
and"error"
;options
will change based on the rule.
Migrating from other linters
Section titled Migrating from other lintersMany of Biome lint rules are inspired from other linters. If you want to migrate from other linters such as ESLint or typescript-eslint
, check the rules sources page