Back to Biomejs

noHeaderScope

src/content/docs/linter/rules/no-header-scope.mdx

latest18.2 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/a11y/noHeaderScope`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`jsx-a11y/scope`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/scope.md)

How to configure

json
{
	"linter": {
		"rules": {
			"a11y": {
				"noHeaderScope": "error"
			}
		}
	}
}

Description

The scope prop should be used only on <th> elements.

Examples

Invalid

jsx
<div scope={scope} />
<pre class="language-text"><code class="language-text">code-block.jsx:1:6 <a href="https://biomejs.dev/linter/rules/no-header-scope">lint/a11y/noHeaderScope</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid using the </span><span style="color: Tomato;"><strong>scope</strong></span><span style="color: Tomato;"> attribute on elements other than </span><span style="color: Tomato;"><strong>th</strong></span><span style="color: Tomato;"> elements.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&lt;div scope=&#123;scope&#125; /&gt; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute is used to associate a data cell with its corresponding header cell in a data table, </span> <span style="color: lightgreen;"> so it should be placed on </span><span style="color: lightgreen;"><strong>th</strong></span><span style="color: lightgreen;"> elements to provide accessibility to screen readers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Follow the links for more information, </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships">WCAG 1.3.1</a></span><span style="color: lightgreen;"> </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/parsing">WCAG 4.1.1</a></span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unsafe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove the </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute.</span> <strong> 1 │ </strong>&lt;div<span style="opacity: 0.8;">·</span><span style="color: Tomato;">s</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">p</span><span style="color: Tomato;">e</span><span style="color: Tomato;">=</span><span style="color: Tomato;">&#123;</span><span style="color: Tomato;">s</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">p</span><span style="color: Tomato;">e</span><span style="color: Tomato;">&#125;</span><span style="opacity: 0.8;"><span style="color: Tomato;">·</span></span>/&gt; <strong> │ </strong> <span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span> </code></pre>
jsx
<div scope="col" />
<pre class="language-text"><code class="language-text">code-block.jsx:1:6 <a href="https://biomejs.dev/linter/rules/no-header-scope">lint/a11y/noHeaderScope</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid using the </span><span style="color: Tomato;"><strong>scope</strong></span><span style="color: Tomato;"> attribute on elements other than </span><span style="color: Tomato;"><strong>th</strong></span><span style="color: Tomato;"> elements.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&lt;div scope=&quot;col&quot; /&gt; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute is used to associate a data cell with its corresponding header cell in a data table, </span> <span style="color: lightgreen;"> so it should be placed on </span><span style="color: lightgreen;"><strong>th</strong></span><span style="color: lightgreen;"> elements to provide accessibility to screen readers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Follow the links for more information, </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships">WCAG 1.3.1</a></span><span style="color: lightgreen;"> </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/parsing">WCAG 4.1.1</a></span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unsafe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove the </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute.</span> <strong> 1 │ </strong>&lt;div<span style="opacity: 0.8;">·</span><span style="color: Tomato;">s</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">p</span><span style="color: Tomato;">e</span><span style="color: Tomato;">=</span><span style="color: Tomato;">&quot;</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">l</span><span style="color: Tomato;">&quot;</span><span style="opacity: 0.8;"><span style="color: Tomato;">·</span></span>/&gt; <strong> │ </strong> <span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span> </code></pre>

Valid

jsx
<th scope={scope}></th>
jsx
<th scope="col"></th>

Accessibility guidelines

</TabItem> <TabItem label="HTML" icon="seti:html"> ## Summary - Rule available since: `v2.3.0` - Diagnostic Category: [`lint/a11y/noHeaderScope`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`jsx-a11y/scope`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/scope.md)

How to configure

json
{
	"linter": {
		"rules": {
			"a11y": {
				"noHeaderScope": "error"
			}
		}
	}
}

Description

The scope prop should be used only on <th> elements.

Examples

Invalid

html
<div scope="col"></div>
<pre class="language-text"><code class="language-text">code-block.html:1:6 <a href="https://biomejs.dev/linter/rules/no-header-scope">lint/a11y/noHeaderScope</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid using the </span><span style="color: Tomato;"><strong>scope</strong></span><span style="color: Tomato;"> attribute on elements other than </span><span style="color: Tomato;"><strong>th</strong></span><span style="color: Tomato;"> elements.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&lt;div scope=&quot;col&quot;&gt;&lt;/div&gt; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute is used to associate a data cell with its corresponding header cell in a data table, </span> <span style="color: lightgreen;"> so it should be placed on </span><span style="color: lightgreen;"><strong>th</strong></span><span style="color: lightgreen;"> elements to provide accessibility to screen readers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Follow the links for more information, </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships">WCAG 1.3.1</a></span><span style="color: lightgreen;"> </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/parsing">WCAG 4.1.1</a></span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unsafe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove the </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute.</span> <strong> 1 │ </strong>&lt;div<span style="opacity: 0.8;">·</span><span style="color: Tomato;">s</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">p</span><span style="color: Tomato;">e</span><span style="color: Tomato;">=</span><span style="color: Tomato;">&quot;</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">l</span><span style="color: Tomato;">&quot;</span>&gt;&lt;/div&gt; <strong> │ </strong> <span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span> </code></pre>
html
<div scope></div>
<pre class="language-text"><code class="language-text">code-block.html:1:6 <a href="https://biomejs.dev/linter/rules/no-header-scope">lint/a11y/noHeaderScope</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid using the </span><span style="color: Tomato;"><strong>scope</strong></span><span style="color: Tomato;"> attribute on elements other than </span><span style="color: Tomato;"><strong>th</strong></span><span style="color: Tomato;"> elements.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&lt;div scope&gt;&lt;/div&gt; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute is used to associate a data cell with its corresponding header cell in a data table, </span> <span style="color: lightgreen;"> so it should be placed on </span><span style="color: lightgreen;"><strong>th</strong></span><span style="color: lightgreen;"> elements to provide accessibility to screen readers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Follow the links for more information, </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships">WCAG 1.3.1</a></span><span style="color: lightgreen;"> </span> <span style="color: lightgreen;"> </span><span style="color: lightgreen;"><a href="https://www.w3.org/WAI/WCAG21/Understanding/parsing">WCAG 4.1.1</a></span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unsafe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove the </span><span style="color: lightgreen;"><strong>scope</strong></span><span style="color: lightgreen;"> attribute.</span> <strong> 1 │ </strong>&lt;div<span style="opacity: 0.8;">·</span><span style="color: Tomato;">s</span><span style="color: Tomato;">c</span><span style="color: Tomato;">o</span><span style="color: Tomato;">p</span><span style="color: Tomato;">e</span>&gt;&lt;/div&gt; <strong> │ </strong> <span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span><span style="color: Tomato;">-</span> </code></pre>

Valid

html
<th scope="col"></th>
html
<th scope></th>

Accessibility guidelines

</TabItem> </Tabs>