golangci.star¶
Edit golangci-lint configs: enable and disable linters and set linter settings.
Works on YAML configs (.golangci.yml and .golangci.yaml), in both the v1
and v2 formats; settings go where each version expects them. Edits are
line-based, so comments stay. To move a config from v1 to v2, run the
official golangci-lint migrate in a run step: it knows every renamed
and merged linter, which a text edit can't.
load("@fleet//golangci.star", "find", "config_version", "enable_linter", "disable_linter", "set_setting")
| Function | What it does |
|---|---|
find |
Finds the repo's golangci-lint config. |
config_version |
Reads the config format version. |
enable_linter |
Enables a linter, removing it from disable if it was there. |
disable_linter |
Disables a linter, removing it from enable if it was there. |
set_setting |
Sets a linter's setting, in linters-settings (v1) or linters.settings (v2). |
find¶
Finds the repo's golangci-lint config.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
Returns: The path of .golangci.yml or .golangci.yaml, or None.
Example
config_version¶
Reads the config format version.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
Returns: "2" for a v2 config, "1" for a config without a version key, or
None when the repo has no config.
Example
Used in: golangci-v2
enable_linter¶
Enables a linter, removing it from disable if it was there.
The linter is added to linters.enable, as a block or flow list
(whichever the file uses), which is created if missing.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
name |
The linter, such as gosec. |
Returns: True when the file changed.
Example
Used in: golangci-v2
disable_linter¶
Disables a linter, removing it from enable if it was there.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
name |
The linter, such as lll. |
Returns: True when the file changed.
Example
set_setting¶
Sets a linter's setting, in linters-settings (v1) or linters.settings (v2).
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
linter |
The linter, such as govet. |
key |
The setting, dotted for nested keys, such as enable-all. |
value |
A string, number, boolean or list. |
Returns: True when the file changed.
Example