Skip to content

Releases: runtime-studio-au/tailwind-sort-php

v0.4.0

Choose a tag to compare

@runtime-studio-au runtime-studio-au released this 02 Jul 05:21

Fixed

  • Single-pass convergence with tailwindPhpSources. A sortable PHP string inside a PHP island in a class attribute (e.g. class="p-4 <?= $on ? 'flex z-10' : '' ?>") was overwritten by the enclosing attribute rewrite, so the transform only converged on a second run — and the pre-commit --check hook could block the same file twice. String edits are now folded into the attribute rewrite and everything sorts in one pass.
  • Ignored directories match whole path segments only. Files like distribution.php or vendors-page.php were silently skipped because their names share a prefix with dist/vendor. Only actual node_modules/vendor/dist/.git directories are skipped now.

Added

  • -h/--help prints a full usage reference (also works as tailwind-sort-php init --help).
  • --version prints the package version.
  • Unknown options now print usage after the error; a flag missing its value exits with a clean Missing value for --attr instead of crashing.

Performance

  • On Node, ignored directories are pruned during glob traversal instead of walked and filtered afterwards.
  • The HTML scanner no longer re-lowercases the whole document for every <script>/<style>/<textarea>/<title> tag.

Internal

  • The PHP string/comment/heredoc boundary rules now live in one shared lexer module (php-lexer.ts) instead of two hand-mirrored copies.
  • Test suite grew from 74 to 84, including regression coverage for all of the above.
  • Dev dependencies updated: Prettier ^3.9, Tailwind CSS ^4.3.

Full Changelog: v0.3.0...v0.4.0

v0.3.0

Choose a tag to compare

@runtime-studio-au runtime-studio-au released this 19 Jun 04:24

Sort Tailwind Classes in PHP String Declarations

The tool previously sorted classes only inside HTML class="..." attributes. 0.3.0 adds an opt-in pass that also sorts class strings declared in PHP — constants, static properties, config arrays — using the same engine and order as the HTML side.

What's New

Opt in per file via the new tailwindPhpSources key in your Prettier config (or the repeatable --php-source <glob> flag):

export default {
    plugins: ['prettier-plugin-tailwindcss'],
    tailwindStylesheet: './resources/css/main.css',
    tailwindPhpSources: ['src/classes/*.php'],
};
// before → after
'primary' => 'text-white px-4 bg-blue-600 rounded py-2',
'primary' => 'rounded bg-blue-600 px-4 py-2 text-white',

Works for scalar declarations and nested/list-style arrays. In key => value arrays only the value is sorted — keys are never touched. The opt-in lives in formatter config only; your PHP stays vanilla.

Safety

Point tailwindPhpSources only at files whose string values are all class lists — within a matched file, every eligible string value is sorted (the tool doesn't guess what "looks like" classes). Concatenated, interpolated, heredoc/nowdoc, and escaped strings are skipped automatically.

Backward Compatible

Without tailwindPhpSources / --php-source, behavior is identical to 0.2.x — the new pass is off by default.

Install

npm install -D @runtimestudio/tailwind-sort-php prettier prettier-plugin-tailwindcss

Requires Node ≥ 22.18 or Bun · prettier ≥ 3 · prettier-plugin-tailwindcss ≥ 0.8

Full Changelog: v0.2.1...v0.3.0

v0.2.1

Choose a tag to compare

@runtime-studio-au runtime-studio-au released this 12 Jun 04:39

Documentation and comment polish; no functional changes.

Changed

  • README: examples now lead with npm/npx (Bun remains the documented alternative); Setup clarifies that any Prettier config format works (.prettierrc, prettier.config.js, package.json "prettier" key, shareable configs) — the CLI reads the resolved config via Prettier's own resolver.
  • Hook templates: the partial-staging note now backticks git add -p, consistent with the README.
  • Doc-comment cleanups across src/ and test/ (grammar fix in html.ts, redundant inline comment removed in cli.ts, consistent file references in test headers).

Note for existing installs

The hook text changed (comment only). A future init re-run will report hooks installed by 0.2.0 as "a custom hook" — re-run with --force to refresh, or leave them; behaviour is identical.

Full Changelog: v0.2.0...v0.2.1

v0.2.0

Choose a tag to compare

@runtime-studio-au runtime-studio-au released this 11 Jun 07:34

New

init subcommand

One command installs the pre-commit gate — writes .githooks/pre-commit and points core.hooksPath at it:

npx tailwind-sort-php init          # check-and-fail: blocks the commit, names the files
npx tailwind-sort-php init --fix    # auto-fix: sorts staged files in place, then blocks for review
  • No-clobber by default — refuses to overwrite a differing hook, repoint a core.hooksPath set elsewhere (husky etc.), or disable hooks already living in .git/hooks; --force overrides, --dry-run previews.
  • Hook hardening over the previously documented snippet: NUL-delimited file handling (-z / xargs -0) so paths with spaces are safe, --diff-filter=ACMR so renamed-and-edited files are caught, and a self-disable guard when node_modules isn't installed.
  • 8 new tests run init against throwaway git repositories (54 total).

Documentation

  • README: searchable title, npm badges, VS Code run-on-save setup, rewritten pre-commit section, corrected CI guidance.
  • LICENSE copyright holder updated to the full legal entity.

Full Changelog: v0.1.1...v0.2.0

v0.1.1

Choose a tag to compare

@runtime-studio-au runtime-studio-au released this 10 Jun 07:19

First Working Release

0.1.0 shipped TypeScript source as its entry points, which Node refuses to run when the package is installed as a dependency (ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING).

0.1.1 ships compiled JavaScript (dist/), so it runs under both Node ≥ 22.18 and Bun — as a dependency or standalone.

Changes

  • Ship compiled JS via tsc (rewriteRelativeImportExtensions); main / bin / types now point at dist/.
  • Add gated integration tests that run the real prettier-plugin-tailwindcss sorter (skip cleanly without the toolchain).
  • prepublishOnly runs the test suite before building.

⚠️ Use this instead of 0.1.0 (deprecated).