Back to Biomejs

noSolidDestructuredProps

src/content/docs/linter/rules/no-solid-destructured-props.mdx

latest7.2 KB
Original Source

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

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/correctness/noSolidDestructuredProps`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`solid`](/linter/domains#solid) - Sources: - Inspired from [`solid/no-destructure`](https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-destructure.md)

How to configure

json
{
	"linter": {
		"rules": {
			"correctness": {
				"noSolidDestructuredProps": "error"
			}
		}
	}
}

Description

Disallow destructuring props inside JSX components in Solid projects.

In Solid, props must be used with property accesses (props.foo) to preserve reactivity.

Examples

Invalid

jsx
let Component = ({}) => <div />;
<pre class="language-text"><code class="language-text">code-block.jsx:1:18 <a href="https://biomejs.dev/linter/rules/no-solid-destructured-props">lint/correctness/noSolidDestructuredProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">You cannot destructure props.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let Component = (&#123;&#125;) =&gt; &lt;div /&gt;; <strong> │ </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;">In Solid, props must be used with property accesses (props.foo) to preserve reactivity.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the destructuring and use props.foo instead.</span> </code></pre>
jsx
let Component = ({ a: A }) => <div a={A} />;
<pre class="language-text"><code class="language-text">code-block.jsx:1:39 <a href="https://biomejs.dev/linter/rules/no-solid-destructured-props">lint/correctness/noSolidDestructuredProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This variable shouldn't be destructured.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let Component = (&#123; a: A &#125;) =&gt; &lt;div a=&#123;A&#125; /&gt;; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This is where the props were destructured.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let Component = (&#123; a: A &#125;) =&gt; &lt;div a=&#123;A&#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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">In Solid, props must be used with property accesses (props.foo) to preserve reactivity.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the destructuring and use props.foo instead.</span> </code></pre>
tsx
let Component = ({ prop1 }: Props) => <div p1={prop1} />;
<pre class="language-text"><code class="language-text">code-block.tsx:1:48 <a href="https://biomejs.dev/linter/rules/no-solid-destructured-props">lint/correctness/noSolidDestructuredProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This variable shouldn't be destructured.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let Component = (&#123; prop1 &#125;: Props) =&gt; &lt;div p1=&#123;prop1&#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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This is where the props were destructured.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let Component = (&#123; prop1 &#125;: Props) =&gt; &lt;div p1=&#123;prop1&#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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">In Solid, props must be used with property accesses (props.foo) to preserve reactivity.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the destructuring and use props.foo instead.</span> </code></pre>

Valid

jsx
let Component = (props) => <div />;
jsx
let Component = (props) => <div a={props.a} />;
</TabItem> </Tabs>