Skip to content

Commit 2dd9fcd

Browse files
Add support for sorting class attribute on Astro components (#129)
* Add support for sorting `class` attribute on Astro components * Update changelog * Simplify test * Add support for custom elements * Update changelog
1 parent fef2c9c commit 2dd9fcd

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Add support for sorting `class` attribute on custom elements and Astro components ([#129](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/129))
1113

1214
## [0.2.3] - 2023-02-15
1315

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ export const parsers = {
573573
}
574574

575575
function transformAstro(ast, { env, changes }) {
576-
if (ast.type === "element") {
576+
if (ast.type === "element" || ast.type === "custom-element" || ast.type === "component") {
577577
for (let attr of ast.attributes ?? []) {
578578
if (attr.name === "class" && attr.type === "attribute" && attr.kind === "quoted") {
579579
attr.value = sortClasses(attr.value, {

tests/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ let tests = {
265265
}
266266
</style>`,
267267
],
268+
t`---
269+
import Layout from '../layouts/Layout.astro'
270+
import Custom from '../components/Custom.astro'
271+
---
272+
273+
<Layout>
274+
<main class="${yes}"></main>
275+
<my-element class="${yes}"></my-element>
276+
<Custom class="${yes}" />
277+
</Layout>`,
268278
],
269279
};
270280

0 commit comments

Comments
 (0)