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
…445)

* fix: preserve whitespace between attributes in sort-attributes rule

* Create wise-news-fly.md

---------

Co-authored-by: Yosuke Ota <[email protected]>
  • Loading branch information
stefanprobst and ota-meshi authored Nov 6, 2024
1 parent 6ffa048 commit 1133962
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-news-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-astro": patch
---

fix: preserve whitespace between attributes in sort-attributes rule
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 1133962

Please sign in to comment.