Conversation
marcoroth
added a commit
that referenced
this pull request
Nov 1, 2025
Building on top of #759, this pull request implements a `tailwind-class-sorter` rewriter that's going to be built-in to the `@herb-tools/rewriter` package. Other tools will be able to refer to this built-in rewriter just by its name `tailwind-class-sorter`. This is going to enable us to plug it in to the `@herb-tools/formatter` (see #671). **Example**: ```ts import { Herb } from "@herb-tools/node-wasm" import { IdentityPrinter } from "@herb-tools/printer" import { TailwindClassSorterRewriter } from "@herb-tools/rewriter" await Herb.load() const rewriter = new TailwindClassSorterRewriter() await rewriter.initialize({ baseDir: process.cwd() }) const input = `<div class="px-4 bg-blue-500 text-white"></div>` const parseResult = Herb.parse(input, { track_whitespace: true }) const rewritten = rewriter.rewrite(parseResult, { baseDir: process.cwd() }) const output = IdentityPrinter.print(rewritten.value) console.log(output) // Output: <div class="bg-blue-500 px-4 text-white"></div> ```
marcoroth
added a commit
that referenced
this pull request
Nov 1, 2025
Building on #759 and #760, this pull request integrates the `@herb-tools/tailwind-css-sorter` package into the `@herb-tools/formatter`, by using the built-in `tailwind-css-sorter` rewriter from the `@herb-tools/rewriter` package. Users can set the `tailwind-class-sorter` rewriter under the `formatter` section in the `.herb.yml` configuration file. ```diff formatter: enabled: true + rewriter: + pre: + - tailwind-class-sorter ``` Since this is just a formatter configuration option, it will also work in the `textDocument/formatting` request in the language server. https://github.com/user-attachments/assets/57979d1e-88ac-421e-8551-1af82de14f1b Additionally, users can put custom rewriters in `.herb/rewriters/*` and then reference them by filename in the `rewriter` section of the configuration. Resolves #671
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
@herb-tools/rewriterpackage that provides a plugin architecture for transforming HTML+ERB templates and enables users to create custom transformations.This pull request just introduces the
@herb-tools/rewriterpackage and the building blocks. These transformations can later be used for pre- and post-format rewriters. It can also serve as a foundation for re-implementing the linter autofixes using the rewriter architecture.We also want use this architecture to integrate the
@herb-tools/tailwind-class-sorterpackage into the@herb-tools/formatterso it can be run as part of the format-action.