Last week I wrote about rebuilding my website with Astro, Vite+ and Void.
One part of that setup was moving from Biome to Vite+, which uses Oxfmt for vp fmt.
There was one gap, though.
My TypeScript, CSS and Markdown got formatted. My .astro files didn’t.
On an Astro website, that’s most of the code.
Now they do.
One line of config
Oxfmt has an astro option. It’s disabled by default. In a Vite+ project, you turn it on in the fmt block of vite.config.ts:
import { defineConfig } from "vite-plus";
export default defineConfig({
fmt: {
useTabs: true,
astro: true,
},
});
That’s the whole change.
Well, almost.
The dependency you need to install yourself
Under the hood, Oxfmt formats .astro files with prettier-plugin-astro. That plugin needs the Rust-based Astro compiler, @astrojs/compiler-rs, at runtime.
Oxfmt doesn’t bundle it.
So if you only flip the option, formatting fails. You need to add the compiler to your project yourself:
pnpm add -D @astrojs/compiler-rs
The docs do mention it, in a note under the option. But it’s the kind of thing you skim past, and then wonder why your formatter is complaining.
I left a comment next to the option in my config, so future me doesn’t remove the dependency because it looks unused:
// Formats .astro files via prettier-plugin-astro (needs @astrojs/compiler-rs installed).
astro: true,
Small detail. Annoying when you miss it.
What changed in my code
Running vp fmt for the first time touched 19 .astro files: 833 lines added, 585 removed.
Most of that is markup getting more vertical. Elements with inline content now get their own lines:
<!-- Before -->
<a href="/" class="btn btn--pink btn--lg">Back home →</a>
<!-- After -->
<a href="/" class="btn btn--pink btn--lg">
Back home →
</a>
And .map() calls in templates get wrapped in parentheses, like you’d see in JSX:
{post.data.tags.slice(0, 2).map((tag) => (
<span class="tag">{tag}</span>
))}
Is it prettier than before? Not always. Some short one-liners became three lines.
But it’s consistent, it’s automatic and nobody has to think about it anymore. That’s the whole point of a formatter.
A few options worth knowing
Instead of true, you can pass an object with some settings:
astro.compressHTMLmirrors Astro’s owncompressHTMLsetting, so the formatter knows which whitespace the compiler will collapse. It defaults to"jsx".astro.skipFrontmatterleaves the frontmatter script alone, if you’d rather not touch it.astro.allowShorthandnormalizes attributes like{href}to shorthand or to the explicit form. When it’s not set, whatever you wrote stays as-is.
I’m using the defaults for now.
What about linting?
Formatting is one thing. Linting is another.
Oxlint, which powers vp lint, does look at .astro files, but only at their script parts. I tried it with a debugger statement in three places: the frontmatter, a <script> tag and an expression in the template.
Oxlint caught the first two. The one in the template slipped through.
So your component logic gets linted. Your markup and the expressions inside it don’t. The compatibility page puts it plainly: “No template linting yet”.
That’s fine for my website, where most of the logic lives in the frontmatter anyway. But it’s worth knowing before you delete your ESLint setup and assume everything is covered.
Oxfmt already understands the whole .astro file, so the formatter is a step ahead of the linter here. Let’s hope template linting lands in Oxlint soon. Then Vite+ would cover Astro projects end to end.
Should you turn it on?
If you’re already using Vite+ or Oxfmt on an Astro project: yes. It’s one line of config and one dev dependency, and you get one formatter for your whole project instead of a separate Prettier setup just for .astro files.
Expect one big formatting commit. Do it in its own pull request, away from real changes, so your future git blame stays readable.
And install @astrojs/compiler-rs.