Linter: Implement erb-closing-tag-indent rule - #1445
Conversation
erb-closing-tag-indent ruleerb-closing-tag-indent rule
e79f27c to
510233b
Compare
|
I haven't forgotten about this one, but I'll get back to it. This one is quite tricky to get right and I want to make sure we are covering all the edge cases to not cause more trouble like the formatter did in #479. |
|
@markokajzer if you get a chance, would you mind rebasing this one off of main, thank you! 馃檹馃徏 |
c740a20 to
0bfca74
Compare
0bfca74 to
01fa135
Compare
|
@marcoroth done! i've ran the rule against the herb corpus (thanks for the hint!), and there were three edgecases:
i added fixes for each of these, see the three added commits a lot of things have changed since i opened this PR, so let me know if anything else is missing 馃檹 |
|
|
||
| type StringLikeNode = PrismNodes.StringNode | PrismNodes.InterpolatedStringNode | PrismNodes.XStringNode | PrismNodes.InterpolatedXStringNode | ||
|
|
||
| class HeredocDetector extends PrismVisitor { |
There was a problem hiding this comment.
this would benefit from sth like visitHeredocNode 馃憖
There was a problem hiding this comment.
or maybe at the very least isPrismHeredocNode for now 馃
| const openTag = node.tag_opening | ||
| const closeTag = node.tag_closing | ||
| const content = node.content | ||
| if (!openTag || !closeTag || !content) return |
There was a problem hiding this comment.
@markokajzer I just had another thought, but not fully verified yet, but I think we want so skip messing with <%- opening tags and -%> closings tags, as they are usually put there carefully and exactly for whitespace preserving reasons.
See adjacent PRs:
- Engine:
<%= -%>does not trim trailing newline聽#1361 - Engine: Whitespace stripped between HTML closing tag and ERB control tag聽#1366
- Engine: Strip whitespace between consecutive end tags after expression blocks聽#1492
- Engine: Fix whitespace not trimmed between
-%>and indented control tag聽#1493 - Engine: Preserve leading whitespace before control tags with inline content聽#1495
- Engine: Fix leading whitespace before inline control tags after trimmed code lines聽#1553
- Engine: Fix right-trim on expression block opening tags聽#1554
There was a problem hiding this comment.
i see, will adjust!
thanks for the extra context! 馃檹
closes #555
Linter Rule: Enforce consistent closing ERB tag indentation
Rule:
erb-closing-tag-indentDescription
This rule enforces that the closing ERB tag (
%>) is consistently indented relative to its opening tag (<%or<%=). When an ERB tag spans multiple lines, the closing%>must be on its own line and indented to match the column position of the opening tag.Rationale
Inconsistent indentation of closing ERB tags makes templates harder to read and maintain. When an ERB tag spans multiple lines, the closing
%>should visually align with the opening<%to clearly show the tag boundaries. Conversely, if the opening tag is on the same line as the content, the closing tag should also be on the same line.