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.includesFilters 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.allowHtmlOptionalClosingTagsAllows 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.enabledEnables or disables formatting. When disabled, formatter modes leave source text unchanged.
formatter.indentStyleChooses spaces or tab characters for indentation generated by erbfmt.
formatter.indentWidthSets the number of spaces per indentation level when
indentStyleisspace.formatter.indentHtmlIndents content according to nested HTML elements. ERB control-flow indentation remains active when this is disabled.
formatter.lineEndingChooses Unix LF or Windows CRLF line endings for formatted output.
formatter.lineWidthSets 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.trailingNewlineAdds one final newline to formatted output. The default follows normal source-file conventions. Set this to
falsefor ERB files that are intentionally rendered as inline partial fragments where a final newline would become visible whitespace.
Linter
linter.enabledEnables or disables all lint diagnostics.
linter.rules.recommendedControls the default state of rules that are not configured individually. With
true, unspecified rules are enabled as errors. Withfalse, 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
emptyErbBranchReports empty ERB branches. Finds branch markers such as
else,elsif,when,rescue, orensurethat contain no meaningful content.emptyErbCodeTagReports empty code and output tags. Finds tags such as
<% %>and<%= %>with no Ruby expression.emptyErbControlBlockReports empty control-flow blocks. Finds a supported ERB block opener and matching
endwith no meaningful body.noDeprecatedHtmlTagDisallows deprecated HTML elements. Reports presentational or obsolete tags that should be replaced with current HTML and CSS.
noDuplicateHtmlAttributeDisallows duplicate attributes. Reports an HTML opening tag that declares the same attribute name more than once.
noInvalidHtmlBooleanAttributeValidates boolean attribute values. Boolean HTML attributes should be omitted or use their own name rather than arbitrary string values.
noInvalidHtmlNestingValidates common HTML content models. Checks list children, table structure, and block-level elements nested inside paragraphs.
noNonDoubleQuotedHtmlAttributeValueRequires double-quoted HTML attribute values. Reports unquoted and single-quoted values such as
class=<%= foo %>orclass='card'; boolean attributes without values are allowed.noSelfClosingHtmlTagDisallows XML-style self-closing HTML syntax. Reports
/>syntax where HTML5 expects a normal opening/closing pair or a void element without the slash.unsupportedErbBlockStarterReports unsupported block starters. Identifies Ruby control-flow forms that look like ERB blocks but are outside the formatter's supported block set.