erbfmt

Reference

Configuration

Every supported erbfmt.json option, its accepted values, and its default behavior.

Config file

Run erbfmt init to create the default configuration in the current directory. Use erbfmt init --force to replace an existing file.

erbfmt init
erbfmt init --force

Without --config, erbfmt searches the current directory and then each parent directory for erbfmt.json. An explicit path takes precedence:

erbfmt --config path/to/erbfmt.json app/views/users/show.html.erb

Add the published schema for editor completion and validation:

{
  "$schema": "https://raw.githubusercontent.com/hinamimi/erbfmt/main/docs/schema/erbfmt.schema.json"
}

Complete example

{
  "$schema": "https://raw.githubusercontent.com/hinamimi/erbfmt/main/docs/schema/erbfmt.schema.json",
  "files": {
    "includes": ["**/*.html.erb", "!vendor/**"]
  },
  "parser": {
    "allowHtmlOptionalClosingTags": false
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2,
    "indentHtml": true,
    "lineEnding": "lf",
    "lineWidth": 80,
    "trailingNewline": true
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "emptyErbBranch": "error",
      "emptyErbCodeTag": "error",
      "emptyErbControlBlock": "error",
      "noDeprecatedHtmlTag": "error",
      "noDuplicateHtmlAttribute": "error",
      "noInvalidHtmlBooleanAttribute": "error",
      "noInvalidHtmlNesting": "error",
      "noNonDoubleQuotedHtmlAttributeValue": "error",
      "noSelfClosingHtmlTag": "error",
      "unsupportedErbBlockStarter": "error"
    }
  }
}

Files

files.includesarray of glob patterns

Filters CLI targets before formatting, checking, or linting. Patterns are evaluated relative to the config file directory when possible. Use ! for exclusions, for example ["**/*.html.erb", "!vendor/**"]. Supported wildcards are *, ?, and **.

Parser

parser.allowHtmlOptionalClosingTagsboolean · default: false

Allows common HTML optional closing tags such as omitted </li>, </p>, </td>, and </tr>. By default erbfmt treats omitted close tags as parse errors. When enabled, erbfmt accepts these forms but preserves the omitted closing tags instead of inserting them.

Formatter

formatter.enabledboolean · default: true

Enables or disables formatting. When disabled, formatter modes leave source text unchanged.

formatter.indentStyle"space" | "tab" · default: "space"

Chooses spaces or tab characters for indentation generated by erbfmt.

formatter.indentWidthinteger ≥ 1 · default: 2

Sets the number of spaces per indentation level when indentStyle is space.

formatter.indentHtmlboolean · default: true

Indents content according to nested HTML elements. ERB control-flow indentation remains active when this is disabled.

formatter.lineEnding"lf" | "crlf" · default: "lf"

Chooses Unix LF or Windows CRLF line endings for formatted output.

formatter.lineWidthinteger ≥ 1 · default: 80

Sets the target line width. Long HTML opening tags expand to one attribute per line. Format-sensitive subtrees keep their content intact, but their opening tag attributes may still wrap. Standalone ERB tags move their markers onto separate lines, and safely recognized method calls may place one top-level argument per line. Ambiguous Ruby remains unchanged.

formatter.trailingNewlineboolean · default: true

Adds one final newline to formatted output. The default follows normal source-file conventions. Set this to false for ERB files that are intentionally rendered as inline partial fragments where a final newline would become visible whitespace.

Linter

linter.enabledboolean · default: true

Enables or disables all lint diagnostics.

linter.rules.recommendedboolean · default: true

Controls the default state of rules that are not configured individually. With true, unspecified rules are enabled as errors. With false, they are disabled.

Every individual rule accepts "off", "warn", or "error". Warnings are reported without failing erbfmt --lint. Errors produce a nonzero exit status.

Lint rules

emptyErbBranchoff | warn | error

Reports empty ERB branches. Finds branch markers such as else, elsif, when, rescue, or ensure that contain no meaningful content.

emptyErbCodeTagoff | warn | error

Reports empty code and output tags. Finds tags such as <% %> and <%= %> with no Ruby expression.

emptyErbControlBlockoff | warn | error

Reports empty control-flow blocks. Finds a supported ERB block opener and matching end with no meaningful body.

noDeprecatedHtmlTagoff | warn | error

Disallows deprecated HTML elements. Reports presentational or obsolete tags that should be replaced with current HTML and CSS.

noDuplicateHtmlAttributeoff | warn | error

Disallows duplicate attributes. Reports an HTML opening tag that declares the same attribute name more than once.

noInvalidHtmlBooleanAttributeoff | warn | error

Validates boolean attribute values. Boolean HTML attributes should be omitted or use their own name rather than arbitrary string values.

noInvalidHtmlNestingoff | warn | error

Validates common HTML content models. Checks list children, table structure, and block-level elements nested inside paragraphs.

noNonDoubleQuotedHtmlAttributeValueoff | warn | error

Requires double-quoted HTML attribute values. Reports unquoted and single-quoted values such as class=<%= foo %> or class='card'; boolean attributes without values are allowed.

noSelfClosingHtmlTagoff | warn | error

Disallows XML-style self-closing HTML syntax. Reports /> syntax where HTML5 expects a normal opening/closing pair or a void element without the slash.

unsupportedErbBlockStarteroff | warn | error

Reports unsupported block starters. Identifies Ruby control-flow forms that look like ERB blocks but are outside the formatter's supported block set.