sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
276 stars 29 forks source link

Add svelte/attributes-line-break #762

Open jamesst20 opened 1 month ago

jamesst20 commented 1 month ago

Motivation

There are currently 2 existing rules that helps formatting attributes line break:

The problem with them is that there is no way to consider the line length to enforce proper style.

Description

"svelte/attributes-line-break": ["error", { printWidth: 90 }]

Examples

<script>
</script>

<!-- ✓ GOOD -->

<!-- 41 characters -->
<MyComponent attr1="test" attr2="test" />

<!-- 99 characters -->
<MyComponent
  attr1="test"
  attr2="test"
  attr3="some very long text that takes spaces and many..."
/>

<!-- ✗ BAD -->

<!-- 41 characters -->
<MyComponent
  attr1="test"
  attr2="test"
/>

<!-- 99 characters -->
<MyComponent  attr1="test"  attr2="test"  attr3="some very long text that takes spaces and many..."/>

Additional comments

These are only examples, I am not very much opiniated on the rule name or customization as long as it can give the proper result in the end.

Right now Prettier is able to enforce this style correctly, however Prettier is very opiniated and doesn't offer much customization and i would like to get rid of it.

ota-meshi commented 3 weeks ago

Thank you for the rule suggestion. I'm interested in that rule, but I think it conflicts with svelte/max-attributes-per-line. Could you please consider changing the rule so that it doesn't conflict, or consider deprecating svelte/max-attributes-per-line and creating a new rule that includes the use case of svelte/max-attributes-per-line?

https://sveltejs.github.io/eslint-plugin-svelte/rules/max-attributes-per-line/

jamesst20 commented 3 weeks ago

Thank you for the rule suggestion. I'm interested in that rule, but I think it conflicts with svelte/max-attributes-per-line. Could you please consider changing the rule so that it doesn't conflict, or consider deprecating svelte/max-attributes-per-line and creating a new rule that includes the use case of svelte/max-attributes-per-line?

https://sveltejs.github.io/eslint-plugin-svelte/rules/max-attributes-per-line/

Indeed I'm open to all this. I currently have these 2 rules disabled in favor of Prettier for the time being until anyone implement this suggestion :)

Do you have a proposal? I could edit the top post