Skip to content

Commit

Permalink
Add support for sorting class attribute on Astro components (#129)
Browse files Browse the repository at this point in the history
* Add support for sorting `class` attribute on Astro components

* Update changelog

* Simplify test

* Add support for custom elements

* Update changelog
  • Loading branch information
thecrypticace authored Mar 2, 2023
1 parent fef2c9c commit 2dd9fcd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Add support for sorting `class` attribute on custom elements and Astro components ([#129](https:/tailwindlabs/prettier-plugin-tailwindcss/pull/129))

## [0.2.3] - 2023-02-15

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export const parsers = {
}

function transformAstro(ast, { env, changes }) {
if (ast.type === "element") {
if (ast.type === "element" || ast.type === "custom-element" || ast.type === "component") {
for (let attr of ast.attributes ?? []) {
if (attr.name === "class" && attr.type === "attribute" && attr.kind === "quoted") {
attr.value = sortClasses(attr.value, {
Expand Down
10 changes: 10 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ let tests = {
}
</style>`,
],
t`---
import Layout from '../layouts/Layout.astro'
import Custom from '../components/Custom.astro'
---
<Layout>
<main class="${yes}"></main>
<my-element class="${yes}"></my-element>
<Custom class="${yes}" />
</Layout>`,
],
};

Expand Down

0 comments on commit 2dd9fcd

Please sign in to comment.