-
-
Notifications
You must be signed in to change notification settings - Fork 681
[Fixes #293] Update indent rule #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm, I think it's enough common style that it aligns rest attributes to the first attribute; it exists in the source code of this PR page as well (though both styles are mixed). |
I personally don't see a use case for either of them. 😄 They seem just as strange as these styles in JavaScript: const myObject = { foo: 'a',
bar: 'b',
baz: 'c',
} const myObject = { foo: 'a',
bar: 'b',
baz: 'c',
} I don't think ESLint even provides an option to format objects with either of these styles. That said, @mysticatea is right that these are both unfortunately quite common in HTML. I believe at least one popular editor (don't remember which one) even auto-formats HTML in the first style by default. So an optional setting may be the best way to go, defaulting to the current behavior for backwards-compatibility. |
Well, it's not a JS, so it might differ after all :D I'm fine with an optional setting, but would argue that the second version should be a default one, and Also we have another rule that doesn't allow attributes in first line in case there are other attributes in the following lines ( |
I'm not strongly opinionated in which of these is the default. I think it's possible that the current (aligned) style is more popular, but I find your proposed change slightly less offensive for multi-line. 😄 I can see arguments either way. On a technical note, since this is fixable: how do we know the specific indentation level to use if we can't tell from context? |
I'll ask on discord to see how people think about it :)
And about indentation level, what do you mean by context? In the first example we know the alignment of the first attribute and simply set expected alignments on the reset of attributes to be equal. And in the second case we set expected indentation on each but the first attribute to be shifted by |
What I mean is that in cases like this: <div id="foo"
class="abc"
style="font-color: red;"
>
</div> When we fix the indentation to match your proposed style (1 indentation level from the opening tag), how do we know whether to indent 2 spaces, 4 spaces, 1 tab, etc? |
@michalsnik I think that vertical alignment is enough common style. We have received such request frequently in core as well. Also, the change of default behavior requires mejor version up. About option form, how about |
@chrisvfritz We know it by checking settings of this rule. @mysticatea the proposition with const a = 1,
b = 2,
c = 3; ArrayExpression and ObjectExpression also have I think it should look exactly the same here. And since we're still in beta I don't think it would be a big problem to introduce this change now. In my opinion better now than later :) |
In |
Ah, I missed it. Then perhaps this should also be updated 🤔 |
Arrays and objects are the same. If the first element is on the same line as the left paren, it aligns rest elements. The rule handles the condition as the sign of vertical alignment at all. Especially in the variable declaration case, this simplifies implementation hugely. |
Variables declarations indeed look better vertically aligned, but as for objects, arrays and attributes I think we could quite easily update this rule to be less strict by default. Also cases with attributes, objects or arrays are, or should be most common to use, everything more should rather be avoided in interpolated expressions and bindings in my opinion anyway. |
I believe it's not "less strict". Just it fits preference or not. The number of spaces is A or B. I thought the order of commonly is the following. I didn't think let first = {
a: 1,
b: 2,
c: 3
}
let second = { a: 1,
b: 2,
c: 3 }
let third = { a: 1,
b: 2,
c: 3
} Anyway, I can accept the change of the default behavior, however, I can't accept if we do without semver-major. We are following to ESLint semantic versioning policy. It intends that bug fixes never break user's CI if the user depends on eslint/plugins with npm's |
Okay let's meet at the middle ground then :) I'll update this PR as I proposed, but under additional option and I won't change the default behaviour to not introduce unnecessary confusion @mysticatea About that third case - to be honest I didn't see such style in JS ever. Maybe we don't have to change anything about arrays and object in interpolated expressions and bindings at all 🤔 And that optional setting would only take care of HTML attributes indentation. Simple as that. |
I as promised, I added |
lib/rules/html-indent.js
Outdated
if (nodeList.some(isBeginningOfLine)) { | ||
setBaseline(baseToken) | ||
} | ||
setOffset(alignTokens, 0, baseToken) | ||
|
||
if (!options.alignAttributesVertically && rootNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you move options.alignAttributesVertically
to the call site? processNodeList
is a common logic for many expressions/statements. I'd like to change the value of rootNode
by the option.
Done, check if that's what you wanted me to do @mysticatea :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
As pointed in #293 currently indent rule requires attributes to be aligned as the first one:
It's not that common I think, and most people prefer to use it like this:
This PR updates indent rule to force the second version.
Though I'm thinking whether we shouldn't add an optional setting to make it possible to align to the first token if needed.
What do you think guys? @mysticatea @chrisvfritz