diff --git a/.changeset/wise-news-fly.md b/.changeset/wise-news-fly.md new file mode 100644 index 00000000..dfaaad4c --- /dev/null +++ b/.changeset/wise-news-fly.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-astro": patch +--- + +fix: preserve whitespace between attributes in sort-attributes rule diff --git a/src/rules/sort-attributes.ts b/src/rules/sort-attributes.ts index 26b115a8..956e0419 100644 --- a/src/rules/sort-attributes.ts +++ b/src/rules/sort-attributes.ts @@ -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), ) }, diff --git a/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test01-output.astro b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test01-output.astro index 3e2c256f..22dad620 100644 --- a/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test01-output.astro +++ b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test01-output.astro @@ -2,4 +2,4 @@ --- -
+
diff --git a/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-errors.json b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-errors.json new file mode 100644 index 00000000..374bfd06 --- /dev/null +++ b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-errors.json @@ -0,0 +1,7 @@ +[ + { + "message": "Expected \"a\" to come before \"b\".", + "line": 5, + "column": 6 + } +] diff --git a/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-input.astro b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-input.astro new file mode 100644 index 00000000..a5fa0b70 --- /dev/null +++ b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-input.astro @@ -0,0 +1,5 @@ +--- + +--- + +
diff --git a/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-output.astro b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-output.astro new file mode 100644 index 00000000..bcf35a73 --- /dev/null +++ b/tests/fixtures/rules/sort-attributes/invalid/alphabetical/test02-output.astro @@ -0,0 +1,5 @@ +--- + +--- + +
diff --git a/tests/fixtures/rules/sort-attributes/invalid/line-length/test01-output.astro b/tests/fixtures/rules/sort-attributes/invalid/line-length/test01-output.astro index 0ce47b62..15e7d4c7 100644 --- a/tests/fixtures/rules/sort-attributes/invalid/line-length/test01-output.astro +++ b/tests/fixtures/rules/sort-attributes/invalid/line-length/test01-output.astro @@ -2,4 +2,4 @@ --- -
+