-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Require explicit heading level on `<Heading>` component | ||
|
||
The `Heading` component does not require you to use `as` to specify the heading level, as it will default to an `h2` if one isn't specified. This may lead to inaccessible usage if the default is out of order in the existing heading hierarchy. | ||
|
||
## Rule Details | ||
|
||
This rule enforces using `as` on the `<Heading>` component to specify a heading level (`h1`-`h6`). In addition, it enforces `as` usage to only be used for headings. | ||
|
||
👎 Examples of **incorrect** code for this rule | ||
|
||
```jsx | ||
import {Heading} from '@primer/react' | ||
|
||
<Heading>Heading without explicit heading level</Heading> | ||
``` | ||
|
||
`as` must only be for headings (`h1`-`h6`) | ||
|
||
```jsx | ||
import {Heading} from '@primer/react' | ||
|
||
<Heading as="span">Heading component used as "span"</Heading> | ||
``` | ||
|
||
👍 Examples of **correct** code for this rule: | ||
|
||
```jsx | ||
import {Heading} from '@primer/react'; | ||
|
||
<Heading as="h2">Heading level 2</Heading> | ||
``` | ||
|
||
## Options | ||
|
||
- `skipImportCheck` (default: `false`) | ||
|
||
By default, the `explicit-heading` rule will only check for `<Heading>` components imported directly from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. |