Skip to content

Commit

Permalink
fix: preserve whitespace between attributes in sort-attributes rule
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst committed Nov 6, 2024
1 parent 6ffa048 commit 67b0ea1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/rules/sort-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default createRule("sort-attributes", {
return fixer.replaceTextRange(
[left.node.range[0], right.node.range[1]],
sourceCode.text.slice(...right.node.range) +
" ".repeat(right.node.range[0] - left.node.range[1]) +
sourceCode.text.slice(...left.node.range),
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
---

<div b="b"c="c" a="a"></div>
<div b="b" c="c" a="a"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"message": "Expected \"a\" to come before \"b\".",
"line": 5,
"column": 6
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
---

<div b="b" a></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
---

<div a b="b"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
---

<div bb="b"c="c" aaa="a"></div>
<div bb="b" c="c" aaa="a"></div>

0 comments on commit 67b0ea1

Please sign in to comment.