npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

erb-fmt

v0.1.8

Published

*WARNING* This package is not yet stable and may not yet work without tree-sitter bindings natively installed.

Readme

ERB FMT

WARNING This package is not yet stable and may not yet work without tree-sitter bindings natively installed.

Fast and configurable code formatter for embedded Ruby templates.

Getting Started

npm install --save-dev erb-fmt

# format a template once
npx erb-fmt app/views/dashboard/index.html.erb

# format an entire view directory (recursive) in place
npx erb-fmt --write app/views/**/*.erb
# print formatted output plus debug segments for a glob
npx erb-fmt --format --segments app/views/shared/**/*.erb
  • The CLI accepts multiple files or globs (e.g. app/views/**/*.erb) and recursively walks directories to format every matching template. Use -- to terminate option parsing if a glob starts with a dash (for example, erbfmt --write -- ./-legacy/**/*.erb).
  • Pass --config path/to/config.json or --config-file to supply overrides. See docs/cli-usage.md for flag details.
  • Configuration options mirror FormatterConfig (indentation, HTML wrapping, whitespace behaviour). Sample files live under examples/config/.

Requirements

  • Node.js 18 or newer (the CLI is distributed as ESM and relies on Tree-sitter native bindings).
  • No Ruby runtime is required to run the formatter, but the heuristics are tuned against modern Rails templates (Ruby 2.7+ syntax); keep your ERB files compatible with the Ruby version your app targets.

Formatting Multiple Files

  • Format a curated set of templates:
    npx erb-fmt --write layout.erb partials/header.erb partials/footer.erb
  • Run a dry run that prints formatted output for an entire folder:
    npx erb-fmt --format app/views/admin/**/*.erb
  • Combine recursive formatting with inline configuration overrides:
    npx erb-fmt --write --config "indentation.size=4" app/components/**/*.erb

Configuration Example

You can supply a JSON file with --config-file (multiple files may be merged in order). The snippet below shows every available option:

{
  "indentation": {
    "size": 2,
    "style": "space",
    "continuation": 2
  },
  "newline": "lf",
  "whitespace": {
    "trimTrailingWhitespace": true,
    "ensureFinalNewline": true
  },
  "html": {
    "collapseWhitespace": "conservative",
    "lineWidth": 100,
    "attributeWrapping": "auto"
  },
  "ruby": {
    "format": "heuristic",
    "lineWidth": 100
  }
}

Inline overrides apply last, e.g.:

erb-fmt --config-file config/erb.json --config "indentation.size=4,ruby.format='none'" app/views/**/*.erb

See docs/config-reference.md for a detailed description of each field.

Known Limitations & Future Work

  • Placeholder HTML parse failures: if the generated placeholder document triggers Tree-sitter HTML errors, the formatter falls back to returning the original source and emits an error diagnostic. Malformed HTML or unsupported grammars therefore remain unformatted.
  • Ruby formatting scope: Ruby regions currently receive only inline whitespace normalisation. Complex Ruby blocks (multi-line expressions, guard clauses, stylistic rewrites) stay as-authored.
  • Sensitive blocks preserved verbatim: content inside <pre>, <code>, <textarea>, <script>, and <style> is emitted without structural changes. Embedded JS/CSS is not reformatted.
  • Attribute wrapping heuristics: line-width calculations operate on placeholder text. After reinserting Ruby, very long helpers may still exceed the configured width.
  • Configuration discovery: the CLI requires explicit --config or --config-file flags; there is no automatic lookup of project config files yet.