Skip to content

feat(docs): add prettier-plugin-bootstrap for automatic class sorting#42383

Open
pierluigilenoci wants to merge 1 commit intotwbs:mainfrom
pierluigilenoci:feat/prettier-plugin-bootstrap
Open

feat(docs): add prettier-plugin-bootstrap for automatic class sorting#42383
pierluigilenoci wants to merge 1 commit intotwbs:mainfrom
pierluigilenoci:feat/prettier-plugin-bootstrap

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Contributor

@pierluigilenoci pierluigilenoci commented May 1, 2026

Summary

Adds prettier-plugin-bootstrap as a standalone npm package to automatically sort Bootstrap CSS classes following the framework's recommended order — similar to what prettier-plugin-tailwindcss provides for Tailwind CSS.

This addresses the feedback from #42359 where @coliff and @julien-deramond suggested extracting the plugin into a separate package.

Closes #38397

Note: This PR depends on #42389 being merged first (fixes 3 Astro files with invalid JSX that prevent Prettier from parsing them).

What changed

  1. package.json — adds prettier-plugin-bootstrap@^0.2.1 as a dev dependency
  2. site/.prettierrc.json — adds plugins: ["prettier-plugin-astro", "prettier-plugin-bootstrap"]
  3. 28 .astro files — class attributes reordered by prettier --write (no functional changes)

Plugin features (v0.2.x)

  • Sorts classes following Bootstrap's architecture (layout → components → helpers → utilities)
  • Responsive variants (d-md-flex) sort immediately after their base class
  • Unknown/custom classes preserved in their original relative order at the end
  • bootstrapFunctions option for sorting inside clsx(), cn(), classNames() calls
  • Supports HTML, JSX/TSX, Vue, Angular, Svelte, and Astro parsers
  • 88 tests, 100% code coverage
  • Zero runtime dependencies

Sorting order

  1. Layout — containers, grid, columns
  2. Components — btn, card, modal, navbar, etc. (following bootstrap.scss import order)
  3. Helpers — clearfix, visually-hidden, stretched-link
  4. Utilities — following the key order of scss/_utilities.scss

Plugin repository

https://github.com/pierluigilenoci/prettier-plugin-bootstrap

CI codecov npm

Test plan

  • npx prettier --config site/.prettierrc.json -c site passes (after fix(docs): wrap adjacent JSX elements in fragments for Prettier compat #42389 is merged)
  • Plugin tested with HTML, JSX/TSX, Vue, Angular, Svelte, and Astro parsers
  • 88 unit + integration + snapshot tests in the plugin repository
  • 100% code coverage (statements, branches, functions, lines)
  • CI green on Node 20/22
  • Zero security vulnerabilities (Snyk verified)

@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

cc @julien-deramond @mdo @coliff — this adds automatic Bootstrap class sorting to the docs site via a Prettier plugin (similar to prettier-plugin-tailwindcss). Happy to adjust anything if needed.

@pierluigilenoci pierluigilenoci force-pushed the feat/prettier-plugin-bootstrap branch 3 times, most recently from 6edb2a7 to 7d7841b Compare May 3, 2026 17:53
Adds `prettier-plugin-bootstrap` (v0.3.0) to automatically sort Bootstrap
CSS classes following the framework's architecture order.

- Adds `prettier-plugin-bootstrap@^0.3.0` as a dev dependency
- Configures `.prettierrc.json` with the plugin (after prettier-plugin-astro)
- Reformats 28 `.astro` files with sorted class attributes (no functional changes)

Plugin features:
- Sorts classes: layout → components → helpers → utilities
- Responsive variants sort after their base class
- Supports HTML, JSX/TSX, Vue, Angular, Svelte, and Astro
- Public sorting API via `prettier-plugin-bootstrap/sorter`
- 121 tests, 100% coverage, zero runtime dependencies

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the feat/prettier-plugin-bootstrap branch from 7d7841b to 4cb6504 Compare May 3, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a Bootstrap class ordering prettier

2 participants