yeonjuan / html-eslint

ESLint plugin for linting HTML
https://html-eslint.org
MIT License
161 stars 28 forks source link

[Feature request] One attribute per line, if more than `n` attributes #191

Closed RobertAKARobin closed 5 months ago

RobertAKARobin commented 5 months ago
type options = {
  enforceIfMoreThan: integer,
  closeStyle: `newline` | `newline-indent` | `sameline`
}

Example

{
  "@html-eslint/attribute-newline": ["error", {
    "enforceIfMoreThan": 2,
    "closeStyle": "newline"
  }]
}
<img alt="foo" src="foo.jpg" />

<img
  alt="foo"
  class="myclass"
  src="foo.jpg"
/>

Example

{
  "@html-eslint/attribute-newline": ["error", {
    "enforceIfMoreThan": 1,
    "closeStyle": "newline-indent"
  }]
}
<img src="foo.jpg" />

<img
  alt="foo"
  src="foo.jpg"
  />

Example

{
  "@html-eslint/attribute-newline": ["error", {
    "enforceIfMoreThan": 0,
    "closeStyle": "sameline"
  }]
}
<img />

<img
  alt="foo" />

Please let me know if this already exists — I didn't see it. If not I may try to make a PR for it.

yeonjuan commented 5 months ago

Hi @RobertAKARobin Thank you for your suggestion.I agree to add this rule. 👍 How about attrs-newline for the rule name? There are rules that include “attrs” in the name, so it would be nice to be consistent.

"closeStyle": "newline-indent"

I don't think we need this option in this rule, we already have a rule that deals with indent. - https://html-eslint.org/docs/rules/indent If the new rule handles indentation, then the ndent rule and the new rule might conflict if used together.

RobertAKARobin commented 5 months ago

Sure, that all makes sense to me!

gian1200 commented 4 months ago

Quick question. This new rule was added to the recommended list. Was it expected?

RobertAKARobin commented 4 months ago

@gian1200 One of the tests failed unless the rule was added to the recommendations, so I assumed new rules were supposed to be added.