eslint-plugin-svelte icon indicating copy to clipboard operation
eslint-plugin-svelte copied to clipboard

Add `svelte/no-constant-condition` rule

Open AlexRMU opened this issue 2 years ago • 2 comments

Description

You need to take all the rules from eslint and try to adapt them to the markup.

if (2) { // no-constant-condition
    "foo";
} else if (3) { // no-constant-condition
    "bar";
} else if (3) { // no-constant-condition no-dupe-else-if
    "baz";
}
{#if 2}
    <div>foo</div>
{:else if 3}
    <div>bar</div>
{:else if 3} <!-- svelte/no-dupe-else-if-blocks -->
    <div>baz</div>
{/if}

Perhaps you need to try to convert the markup to (pseudo) regular js and, in addition to the rules of the svelte, apply the rules for js to it (including other plugins and future ts support in the markup).

AlexRMU avatar Nov 12 '23 17:11 AlexRMU

Thank you for posting this issue. Since template logic blocks are different from JavaScript, I think we need to create rules like svelte/no-constant-condition separately. If you think there is a rule we need, please post rule proposal in an new issue.

ota-meshi avatar Nov 13 '23 01:11 ota-meshi

Perhaps you need to try to convert the markup to (pseudo) regular js and, in addition to the rules of the svelte, apply the rules for js to it (including other plugins and future ts support in the markup).

If you want to try out the idea of linting from pseudo JavaScript code, please create your own new plugin and try it out, as the mechanism is different from eslint-plugin-svelte.

ota-meshi avatar Nov 13 '23 01:11 ota-meshi