Skip to content

indent_style

Every non-blank line indents with the configured style (tabs or spaces). When style: spaces, optional width enforces a multiple.

Fix: indent_style — reindents tab-indented lines to spaces, for a style: spaces + width: N rule only (the width is the spaces-per-tab). It converts a PURE-TAB leading run to N spaces per tab (1 tab → N, 2 tabs → 2N), preserving the rest of the line, its terminator, and the trailing-newline state; it declines the genuinely ambiguous cases — a mixed tab+space lead, or a pure-space run that isn't a multiple of width — so check does not advertise those as auto-fixable. A tabs-style or width-less rule with a fix is rejected at load (spaces → tabs has no spaces-per-tab). Unsafe by default — a mis-aimed reindent hard-breaks an indent-significant file (a Makefile recipe requires a literal tab), so a bare alint fix suggests it and --unsafe-fixes (or a per-rule applicability: safe) applies it; it is also demoted to a suggestion from an untrusted remote extends:. With no fix declared, violations are unfixable; pair with your editor's "reindent on save".

OptionTypeRequiredDefaultDescription
styleone of tabs | spacesyesRequired indentation style: tabs rejects any leading space; spaces rejects any leading tab.
widthinteger (>= 1)nullWhen style: spaces, the leading-space count on every non-blank line must be a multiple of this. Ignored for style: tabs.

Plus the common paths, level, id, when, scope_filter, fix, and expect_matches fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

A Go file indented with spaces instead of tabs

Section titled "A Go file indented with spaces instead of tabs"

The rule fires on this repository:

  • src/
  • src/bad.go

    ✗ error go-tabs

    4:1 line 4 indented with the wrong character (expected tabs)

  • src/ok.go✓
src/bad.go
package main
func y() {
return
}
src/ok.go
package main
func x() {
return
}

With this .alint.yml:

version: 1
rules:
- id: go-tabs
kind: indent_style
paths: "src/**/*.go"
style: tabs
level: error

alint check reports:

Terminal window
--- src/bad.go -----------------------------------------------------------------
x error go-tabs
4:1 line 4 indented with the wrong character (expected tabs)
Summary (1 violation):
x 1 error
0 passing * 1 failing

Every Go file is indented with tabs

Section titled "Every Go file is indented with tabs"

This repository is compliant:

  • src/
  • src/a.go✓
  • src/b.go✓
src/a.go
package main
func x() {
return
}
src/b.go
package main
func y() {
if true {
return
}
}

With this .alint.yml:

version: 1
rules:
- id: go-tabs
kind: indent_style
paths: "src/**/*.go"
style: tabs
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.