Skip to content

feat: Add svelte/consistent-attribute-lines rule #591

Closed
@jacob-8

Description

@jacob-8

Motivation

This rule is essentially the same as Anthony's recently published antfu/consistent-list-newline rule, but for element attributes in Svelte files. The purpose of it is to save spending time messing with whitespace. However I write the first attribute, the rest will automatically follow the pattern.

Description

Keep attributes on same line or each on their own line based on the first attributes position

Examples

<script>
</script>

<!-- ✓ GOOD -->
<div baz foo bar="2">Text</div>

<div
  baz
  foo
  bar="2">Text</div>

<div
  foo
  use:baz={{
    setting: 'value',
  }} />

<!-- ✗ BAD -->
<div baz
  foo
  bar="2">Text</div>

<div baz foo
  bar="2">Text</div>

<div
  baz foo bar="2">Text</div>

<div foo
  bar />

<div foo use:baz={{
    setting: 'value',
  }} />

<div foo use:baz={{
    setting: 'value',
  }} use:box />

From the rule tests at https://github.com/jacob-8/eslint-plugin-svelte-stylistic/blob/main/src/rules/consistent-attribute-lines.test.ts

Additional comments

I've already published it to npm as eslint-plugin-svelte-stylistic so I'm set, but I thought others might appreciate it so wanted to propose adding it here. What do you think? (rule 2 of 2, see the first at #590)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions