Herb Formatter experimental preview
Package: @herb-tools/formatter
Experimental Preview
This formatter is currently in experimental preview. While it works for many common cases, it may potentially corrupt files in edge cases. Only use on files that can be restored via git or other version control systems.
Auto-formatter for HTML+ERB templates with intelligent indentation, line wrapping, and ERB-aware pretty-printing.
Perfect for format-on-save in editors and formatting verification in CI/CD pipelines. Transforms templates into consistently formatted, readable code while preserving all functionality.
Installation
Global Installation
npm install -g @herb-tools/formatter
pnpm add -g @herb-tools/formatter
yarn global add @herb-tools/formatter
bun add -g @herb-tools/formatter
Then run directly:
herb-format template.html.erb
One-time Usage
For occasional use without installing:
npx @herb-tools/formatter template.html.erb
Project Installation
npm add -D @herb-tools/formatter
pnpm add -D @herb-tools/formatter
yarn add -D @herb-tools/formatter
bun add -D @herb-tools/formatter
After installing as a dev dependency, add format scripts to your package.json
:
{
"scripts": {
"herb:format": "herb-format",
"herb:format:check": "herb-format --check"
}
}
Then run the scripts:
npm run herb:format
npm run herb:format:check
pnpm herb:format
pnpm herb:format:check
yarn herb:format
yarn herb:format:check
bun run herb:format
bun run herb:format:check
Usage
Command Line
Basic usage:
herb-format
herb-format template.html.erb
herb-format templates/
Options
Check Mode:
# Check if files are formatted without modifying them
herb-format --check template.html.erb
# Check all files in current directory
herb-format --check
Input Sources:
# Format specific file
herb-format templates/index.html.erb
# Format all .html.erb files in directory
herb-format templates/
# Format all .html.erb files in current directory (default)
herb-format
# Format from stdin
cat template.html.erb | herb-format
Help and Version:
# Show help
herb-format --help
# Show version information
herb-format --version