Table of Contents
To see a list of supported formatters and which formatters are enabled/disabled:
golangci-lint help formatters
All Formatters
Name | Description | AutoFix | Since |
---|---|---|---|
gci | Checks if code and import statements are formatted, with additional rules. | ✔ | v1.30.0 |
gofmt | Checks if the code is formatted according to 'gofmt' command. | ✔ | v1.0.0 |
gofumpt | Checks if code and import statements are formatted, with additional rules. | ✔ | v1.28.0 |
goimports | Checks if the code and import statements are formatted according to the 'goimports' command. | ✔ | v1.20.0 |
golines | Checks if code is formatted, and fixes long lines. | ✔ | v2.0.0 |
Formatters Configuration
gci
Checks if code and import statements are formatted, with additional rules.
formatters:gci:# Section configuration to compare against.# Section names are case-insensitive and may contain parameters in ().# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,# If `custom-order` is `true`, it follows the order of `sections` option.# Default: ["standard", "default"]sections:- standard # Standard section: captures all standard packages.- default # Default section: contains all imports that could not be matched to another section type.- prefix(github.com/org/project) # Custom section: groups all imports with the specified Prefix.- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.# Checks that no inline comments are present.# Default: falseno-inline-comments: true# Checks that no prefix comments (comment lines above an import) are present.# Default: falseno-prefix-comments: true# Enable custom order of sections.# If `true`, make the section order the same as the order of `sections`.# Default: falsecustom-order: true# Drops lexical ordering for custom sections.# Default: falseno-lex-order: true
gofmt
Checks if the code is formatted according to 'gofmt' command.
formatters:gofmt:# Simplify code: gofmt with `-s` option.# Default: truesimplify: false# Apply the rewrite rules to the source before reformatting.# https://pkg.go.dev/cmd/gofmt# Default: []rewrite-rules:- pattern: 'interface{}'replacement: 'any'- pattern: 'a[b:len(a)]'replacement: 'a[b:]'
gofumpt
Checks if code and import statements are formatted, with additional rules.
formatters:gofumpt:# Module path which contains the source code being formatted.# Default: ""module-path: github.com/org/project# Choose whether to use the extra rules.# Default: falseextra-rules: true
goimports
Checks if the code and import statements are formatted according to the 'goimports' command.
formatters:goimports:# A list of prefixes, which, if set, checks import paths# with the given prefixes are grouped after 3rd-party packages.# Default: []local-prefixes:- github.com/org/project
golines
Checks if code is formatted, and fixes long lines.
Edit this page on GitHub
formatters:golines:# Target maximum line length.# Default: 100max-len: 200# Length of a tabulation.# Default: 4tab-len: 8# Shorten single-line comments.# Default: falseshorten-comments: true# Default: truereformat-tags: false# Split chained methods on the dots as opposed to the arguments.# Default: truechain-split-dots: false