vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 665 forks source link

Removing trailing/leading spaces in directives and bindings #2482

Open Ericlm opened 4 months ago

Ericlm commented 4 months ago

Please describe what the rule should do: The rule would remove trailing and leading spaces from within directives and dynamic attributes. It could also remove trailing/leading spaces from static attributes maybe?

What category should the rule belong to? [X] Enforces code style (layout) [ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<span v-if=" condition " /> ⚠️ Unexpected trailing and leading spaces

<span
    v-for=" i of 10 " ⚠️ Same here
    :key="i " ⚠️ Warns about trailing space
/>

<span
    class=" bg-red-100 text-blue-900 " // ⚠️ Trailing & leading
/>
FloEdelmann commented 4 months ago

That's formatter (e.g. Prettier) territory rather than linter territory. But we currently do have many formatting rules, so this could be considered. @ota-meshi what do you think?

ota-meshi commented 4 months ago

In my opinion, it would be useful to provide formatting rules in an ESLint plugin, since current formatters, like Prettier, don't accept options in most cases.

Ericlm commented 4 months ago

That would be great! My team replaced Prettier with stylistic, that's why I've seen that. It would also be great to have a plugin so that a rule activated with ESLint stylistic would automatically be applied to the template part of .vue files. And a plugin could reduce the number of "extension rules" that are not so easy to discover in the documentation 😅

Ericlm commented 2 months ago

Maybe it could be integrated into eslint-stylistic ? There are already support for ts,js,jsx ; maybe would it be possible to have those rule into this package ? That would also allow the rules to be automatically "inherited" from the stylistic config.