Skip to content

Rule to point out useless bindings #1398

@AntonioVentilii

Description

@AntonioVentilii

Motivation

Is there a rule to point out when a prop the is $bindable, could be a normal prop? Meaning that we are not actually modifying such value in the component.

Description

The rule should point out when a Prop defined as $bindable is not being modified in the component, nor being bind to any other children.

Examples

<!-- ✓ GOOD -->
<script lang="ts">
	import AnotherComponent from './AnotherComponent.svelte';

	interface Props {
		step?: string;
	}

	let { step = 'initial-value' }: Props = $props();
</script>

<AnotherComponent {step} />



<!-- ✓ GOOD -->
<script lang="ts">
	import AnotherComponent from './AnotherComponent.svelte';

	interface Props {
		step?: string;
	}

	let { step = $bindable('initial-value') }: Props = $props();

        step = 'another-value';
</script>

<AnotherComponent {step} />



<!-- ✓ GOOD -->
<script lang="ts">
	import AnotherComponent from './AnotherComponent.svelte';

	interface Props {
		step?: string;
	}

	let { step = $bindable('initial-value') }: Props = $props();
</script>

<AnotherComponent bind:step />



<!-- ✗ BAD -->
<script lang="ts">
	import AnotherComponent from './AnotherComponent.svelte';

	interface Props {
		step?: string;
	}

	let { step = $bindable('initial-value') }: Props = $props();
</script>

<AnotherComponent {step} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions