JavaScript Rules
このコンテンツはまだ日本語訳がありません。
Below the list of rules supported by Biome, divided by group. Here’s a legend of the emojis:
- The icon indicates that the rule is part of the recommended rules.
- The icon indicates that the rule provides a code action (fix) that is safe to apply.
- The icon indicates that the rule provides a code action (fix) that is unsafe to apply.
- The icon indicates that the rule has been implemented and scheduled for the next release.
| Rule name | Description | Properties |
|---|---|---|
| noAccessKey | Enforce that the accessKey attribute is not used on any HTML element. | |
| noAriaHiddenOnFocusable | Enforce that aria-hidden=“true” is not set on focusable elements. | |
| noAriaUnsupportedElements | Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes. | |
| noAutofocus | Enforce that autoFocus prop is not used on elements. | |
| noDistractingElements | Enforces that no distracting elements are used. | |
| noHeaderScope | The scope prop should be used only on <th> elements. | |
| noInteractiveElementToNoninteractiveRole | Enforce that non-interactive ARIA roles are not assigned to interactive HTML elements. | |
| noLabelWithoutControl | Enforce that a label element or component has a text label and an associated input. | |
| noNoninteractiveElementInteractions | Disallow use event handlers on non-interactive elements. | |
| noNoninteractiveElementToInteractiveRole | Enforce that interactive ARIA roles are not assigned to non-interactive HTML elements. | |
| noNoninteractiveTabindex | Enforce that tabIndex is not assigned to non-interactive HTML elements. | |
| noPositiveTabindex | Prevent the usage of positive integers on tabIndex property | |
| noRedundantAlt | Enforce img alt prop does not contain the word “image”, “picture”, or “photo”. | |
| noRedundantRoles | Enforce explicit role property is not the same as implicit/default role property on an element. | |
| noStaticElementInteractions | Enforce that static, visible elements (such as <div>) that have click handlers use the valid role attribute. | |
| noSvgWithoutTitle | Enforces the usage of the title element for the svg element. | |
| useAltText | Enforce that all elements that require alternative text have meaningful information to relay back to the end user. | |
| useAnchorContent | Enforce that anchors have content and that the content is accessible to screen readers. | |
| useAriaActivedescendantWithTabindex | Enforce that tabIndex is assigned to non-interactive HTML elements with aria-activedescendant. | |
| useAriaPropsForRole | Enforce that elements with ARIA roles must have all required ARIA attributes for that role. | |
| useAriaPropsSupportedByRole | Enforce that ARIA properties are valid for the roles that are supported by the element. | |
| useButtonType | Enforces the usage of the attribute type for the element button | |
| useFocusableInteractive | Elements with an interactive role and interaction handlers must be focusable. | |
| useHeadingContent | Enforce that heading elements (h1, h2, etc.) have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the aria-hidden prop. | |
| useHtmlLang | Enforce that html element has lang attribute. | |
| useIframeTitle | Enforces the usage of the attribute title for the element iframe. | |
| useKeyWithClickEvents | Enforce onClick is accompanied by at least one of the following: onKeyUp, onKeyDown, onKeyPress. | |
| useKeyWithMouseEvents | Enforce onMouseOver / onMouseOut are accompanied by onFocus / onBlur. | |
| useMediaCaption | Enforces that audio and video elements must have a track for captions. | |
| useSemanticElements | It detects the use of role attributes in JSX elements and suggests using semantic elements instead. | |
| useValidAnchor | Enforce that all anchors are valid, and they are navigable elements. | |
| useValidAriaProps | Ensures that ARIA properties aria-* are all valid. | |
| useValidAriaRole | Elements with ARIA roles must use a valid, non-abstract ARIA role. | |
| useValidAriaValues | Enforce that ARIA state and property values are valid. | |
| useValidAutocomplete | Use valid values for the autocomplete attribute on input elements. | |
| useValidLang | Ensure that the attribute passed to the lang attribute is a correct ISO language and/or country. |
complexity
Section titled “complexity”| Rule name | Description | Properties |
|---|---|---|
| noAdjacentSpacesInRegex | Disallow unclear usage of consecutive space characters in regular expression literals | |
| noArguments | Disallow the use of arguments. | |
| noBannedTypes | Disallow primitive type aliases and misleading types. | |
| noCommaOperator | Disallow comma operator. | |
| noEmptyTypeParameters | Disallow empty type parameters in type aliases and interfaces. | |
| noExcessiveCognitiveComplexity | Disallow functions that exceed a given Cognitive Complexity score. | |
| noExcessiveLinesPerFunction | Restrict the number of lines of code in a function. | |
| noExcessiveNestedTestSuites | This rule enforces a maximum depth to nested describe() in test files. | |
| noExtraBooleanCast | Disallow unnecessary boolean casts | |
| noFlatMapIdentity | Disallow to use unnecessary callback on flatMap. | |
| noForEach | Prefer for...of statement instead of Array.forEach. | |
| noImplicitCoercions | Disallow shorthand type conversions. | |
| noStaticOnlyClass | This rule reports when a class has no non-static members, such as for a class used exclusively as a static namespace. | |
| noThisInStatic | Disallow this and super in static contexts. | |
| noUselessCatch | Disallow unnecessary catch clauses. | |
| noUselessConstructor | Disallow unnecessary constructors. | |
| noUselessContinue | Avoid using unnecessary continue. | |
| noUselessEmptyExport | Disallow empty exports that don’t change anything in a module file. | |
| noUselessEscapeInRegex | Disallow unnecessary escape sequence in regular expression literals. | |
| noUselessFragments | Disallow unnecessary fragments | |
| noUselessLabel | Disallow unnecessary labels. | |
| noUselessLoneBlockStatements | Disallow unnecessary nested block statements. | |
| noUselessRename | Disallow renaming import, export, and destructured assignments to the same name. | |
| noUselessStringConcat | Disallow unnecessary concatenation of string or template literals. | |
| noUselessStringRaw | Disallow unnecessary String.raw function in template string literals without any escape sequence. | |
| noUselessSwitchCase | Disallow useless case in switch statements. | |
| noUselessTernary | Disallow ternary operators when simpler alternatives exist. | |
| noUselessThisAlias | Disallow useless this aliasing. | |
| noUselessTypeConstraint | Disallow using any or unknown as type constraint. | |
| noUselessUndefinedInitialization | Disallow initializing variables to undefined. | |
| noVoid | Disallow the use of void operators, which is not a familiar operator. | |
| useArrowFunction | Use arrow functions over function expressions. | |
| useDateNow | Use Date.now() to get the number of milliseconds since the Unix Epoch. | |
| useFlatMap | Promotes the use of .flatMap() when map().flat() are used together. | |
| useIndexOf | Prefer Array#{indexOf,lastIndexOf}() over Array#{findIndex,findLastIndex}() when looking for the index of an item. | |
| useLiteralKeys | Enforce the usage of a literal access to properties over computed property access. | |
| useNumericLiterals | Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals | |
| useOptionalChain | Enforce using concise optional chain instead of chained logical expressions. | |
| useRegexLiterals | Enforce the use of the regular expression literals instead of the RegExp constructor if possible. | |
| useSimpleNumberKeys | Disallow number literal object member names which are not base 10 or use underscore as separator. | |
| useSimplifiedLogicExpression | Discard redundant terms from logical expressions. | |
| useWhile | Enforce the use of while loops instead of for loops when the initializer and update expressions are not needed. |
correctness
Section titled “correctness”| Rule name | Description | Properties |
|---|---|---|
| noChildrenProp | Prevent passing of children as props. | |
| noConstAssign | Prevents from having const variables being re-assigned. | |
| noConstantCondition | Disallow constant expressions in conditions | |
| noConstantMathMinMaxClamp | Disallow the use of Math.min and Math.max to clamp a value where the result itself is constant. | |
| noConstructorReturn | Disallow returning a value from a constructor. | |
| noEmptyCharacterClassInRegex | Disallow empty character classes in regular expression literals. | |
| noEmptyPattern | Disallows empty destructuring patterns. | |
| noGlobalDirnameFilename | Disallow the use of __dirname and __filename in the global scope. | |
| noGlobalObjectCalls | Disallow calling global object properties as functions | |
| noInnerDeclarations | Disallow function and var declarations that are accessible outside their block. | |
| noInvalidBuiltinInstantiation | Ensure that builtins are correctly instantiated. | |
| noInvalidConstructorSuper | Prevents the incorrect use of super() inside classes. It also checks whether a call super() is missing from classes that extends other constructors. | |
| noInvalidUseBeforeDeclaration | Disallow the use of variables, function parameters, classes, and enums before their declaration | |
| noNestedComponentDefinitions | Disallows defining React components inside other components. | |
| noNodejsModules | Forbid the use of Node.js builtin modules. | |
| noNonoctalDecimalEscape | Disallow \8 and \9 escape sequences in string literals. | |
| noPrecisionLoss | Disallow literal numbers that lose precision | |
| noPrivateImports | Restrict imports of private exports. | |
| noProcessGlobal | Disallow the use of process global. | |
| noQwikUseVisibleTask | Disallow useVisibleTask$() functions in Qwik components. | |
| noReactPropAssignments | Disallow assigning to React component props. | |
| noRenderReturnValue | Prevent the usage of the return value of React.render. | |
| noRestrictedElements | Disallow the use of configured elements. | |
| noSelfAssign | Disallow assignments where both sides are exactly the same. | |
| noSetterReturn | Disallow returning a value from a setter | |
| noSolidDestructuredProps | Disallow destructuring props inside JSX components in Solid projects. | |
| noStringCaseMismatch | Disallow comparison of expressions modifying the string case with non-compliant value. | |
| noSwitchDeclarations | Disallow lexical declarations in switch clauses. | |
| noUndeclaredDependencies | Disallow the use of dependencies that aren’t specified in the package.json. | |
| noUndeclaredVariables | Prevents the usage of variables that haven’t been declared inside the document. | |
| noUnreachable | Disallow unreachable code | |
| noUnreachableSuper | Ensures the super() constructor is called exactly once on every code path in a class constructor before this is accessed if the class has a superclass | |
| noUnsafeFinally | Disallow control flow statements in finally blocks. | |
| noUnsafeOptionalChaining | Disallow the use of optional chaining in contexts where the undefined value is not allowed. | |
| noUnusedFunctionParameters | Disallow unused function parameters. | |
| noUnusedImports | Disallow unused imports. | |
| noUnusedLabels | Disallow unused labels. | |
| noUnusedPrivateClassMembers | Disallow unused private class members | |
| noUnusedVariables | Disallow unused variables. | |
| noVoidElementsWithChildren | This rules prevents void elements (AKA self-closing elements) from having children. | |
| noVoidTypeReturn | Disallow returning a value from a function with the return type ‘void’ | |
| useExhaustiveDependencies | Enforce correct dependency usage within React hooks. | |
| useHookAtTopLevel | Enforce that all React hooks are being called from the Top Level component functions. | |
| useImageSize | Enforces that <img> elements have both width and height attributes. | |
| useImportExtensions | Enforce file extensions for relative imports. | |
| useIsNan | Require calls to isNaN() when checking for NaN. | |
| useJsonImportAttributes | Enforces the use of with { type: "json" } for JSON module imports. | |
| useJsxKeyInIterable | Disallow missing key props in iterators/collection literals. | |
| useParseIntRadix | Enforce the consistent use of the radix argument when using parseInt(). | |
| useQwikClasslist | Prefer using the class prop as a classlist over the classnames helper. | |
| useSingleJsDocAsterisk | Enforce JSDoc comment lines to start with a single asterisk, except for the first one. | |
| useUniqueElementIds | Prevent the usage of static string literal id attribute on elements. | |
| useValidForDirection | Enforce “for” loop update clause moving the counter in the right direction. | |
| useValidTypeof | This rule checks that the result of a typeof expression is compared to a valid value. | |
| useYield | Require generator functions to contain yield. |
nursery
Section titled “nursery”| Rule name | Description | Properties |
|---|---|---|
| noAmbiguousAnchorText | Disallow ambiguous anchor descriptions. | |
| noBeforeInteractiveScriptOutsideDocument | Prevent usage of next/script’s beforeInteractive strategy outside of pages/_document.js in a Next.js project. | |
| noContinue | Disallow continue statements. | |
| noDeprecatedImports | Restrict imports of deprecated exports. | |
| noDuplicateEnumValues | Disallow duplicate enum member values. | |
| noDuplicatedSpreadProps | Disallow JSX prop spreading the same identifier multiple times. | |
| noEmptySource | Disallow empty sources. | |
| noEqualsToNull | Require the use of === or !== for comparison with null. | |
| noExcessiveLinesPerFile | Restrict the number of lines in a file. | |
| noFloatingPromises | Require Promise-like statements to be handled appropriately. | |
| noForIn | Disallow iterating using a for-in loop. | |
| noImportCycles | Prevent import cycles. | |
| noIncrementDecrement | Disallows the usage of the unary operators ++ and —. | |
| noJsxLiterals | Disallow string literals inside JSX elements. | |
| noJsxPropsBind | Disallow .bind(), arrow functions, or function expressions in JSX props | |
| noLeakedRender | Prevent problematic leaked values from being rendered. | |
| noMisusedPromises | Disallow Promises to be used in places where they are almost certainly a | |
| noMultiAssign | Disallow use of chained assignment expressions | |
| noMultiStr | Disallow creating multiline strings by escaping newlines. | |
| noNextAsyncClientComponent | Prevent client components from being async functions. | |
| noParametersOnlyUsedInRecursion | Disallow function parameters that are only used in recursive calls. | |
| noProto | Disallow the use of the deprecated __proto__ object property. | |
| noReactForwardRef | Replaces usages of forwardRef with passing ref as a prop. | |
| noReturnAssign | Disallow assignments in return statements. | |
| noScriptUrl | Disallow javascript: URLs. | |
| noShadow | Disallow variable declarations from shadowing variables declared in the outer scope. | |
| noSyncScripts | Prevent the usage of synchronous scripts. | |
| noTernary | Disallow ternary operators. | |
| noUndeclaredEnvVars | Disallow the use of undeclared environment variables. | |
| noUnknownAttribute | Disallow unknown DOM properties. | |
| noUnnecessaryConditions | Disallow unnecessary type-based conditions that can be statically determined as redundant. | |
| noUnresolvedImports | Warn when importing non-existing exports. | |
| noUnusedExpressions | Disallow expression statements that are neither a function call nor an | |
| noUselessCatchBinding | Disallow unused catch bindings. | |
| noUselessUndefined | Disallow the use of useless undefined. | |
| noVueDataObjectDeclaration | Enforce that Vue component data options are declared as functions. | |
| noVueDuplicateKeys | Disallow duplicate keys in Vue component data, methods, computed properties, and other options. | |
| noVueOptionsApi | Disallow the use of Vue Options API. | |
| noVueReservedKeys | Disallow reserved keys in Vue component data and computed properties. | |
| noVueReservedProps | Disallow reserved names to be used as props. | |
| noVueSetupPropsReactivityLoss | Disallow destructuring of props passed to setup in Vue projects. | |
| useArraySortCompare | Require Array#sort and Array#toSorted calls to always provide a compareFunction. | |
| useAwaitThenable | Enforce that await is only used on Promise values. | |
| useConsistentArrowReturn | Enforce consistent arrow function bodies. | |
| useDestructuring | Require destructuring from arrays and/or objects | |
| useErrorCause | Enforce that new Error() is thrown with the original error as cause. | |
| useExhaustiveSwitchCases | Require switch-case statements to be exhaustive. | |
| useExplicitType | Enforce types in functions, methods, variables, and parameters. | |
| useFind | Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result. | |
| useMaxParams | Enforce a maximum number of parameters in function definitions. | |
| useQwikMethodUsage | Disallow use* hooks outside of component$ or other use* hooks in Qwik applications. | |
| useQwikValidLexicalScope | Disallow unserializable expressions in Qwik dollar ($) scopes. | |
| useRegexpExec | Enforce RegExp#exec over String#match if no global flag is provided. | |
| useSortedClasses | Enforce the sorting of CSS utility classes. | |
| useSpread | Enforce the use of the spread operator over .apply(). | |
| useVueConsistentDefinePropsDeclaration | Enforce consistent defineProps declaration style. | |
| useVueDefineMacrosOrder | Enforce specific order of Vue compiler macros. | |
| useVueMultiWordComponentNames | Enforce multi-word component names in Vue components. |
performance
Section titled “performance”| Rule name | Description | Properties |
|---|---|---|
| noAccumulatingSpread | Disallow the use of spread (...) syntax on accumulators. | |
| noAwaitInLoops | Disallow await inside loops. | |
| noBarrelFile | Disallow the use of barrel file. | |
| noDelete | Disallow the use of the delete operator. | |
| noDynamicNamespaceImportAccess | Disallow accessing namespace imports dynamically. | |
| noImgElement | Prevent usage of <img> element in a Next.js project. | |
| noNamespaceImport | Disallow the use of namespace imports. | |
| noReExportAll | Avoid re-export all. | |
| noUnwantedPolyfillio | Prevent duplicate polyfills from Polyfill.io. | |