# marmot fix (/docs/commands/fix)

<!-- Generated by scripts/gen.mjs from `marmot fix --help` and scripts/commands.mjs. Do not edit by hand. -->

Build, apply every machine applicable fix (missing imports, unused imports and variables, := with no new variables, ...), and build again until no fix applies. -all adds fixes that may be incorrect, such as typo corrections.

```text title="Usage"
marmot fix [packages] [flags]
```

## Examples [#examples]

```sh
marmot fix
marmot fix -code M0005 ./cmd/app
marmot fix -all
```

`marmot fix` applies the machine applicable fixes of build errors, then those of the `fmt` and
`modernize` checks. After each round it type checks the changed packages and undoes the fixes
of any package that no longer builds; `-test` also requires their tests to pass.

- `-code M0004,M0005` limits it to those build error codes.
- `-all` adds fixes that may be incorrect, such as typo corrections and vet or lint suggestions.
- `-only fmt,modernize` applies only those check fixes.
- `-diff` prints the patches and changes nothing.
- `-upgrade go1.N` raises the module's go version first.

```sh
marmot fix -diff -only modernize
```

Every fix carries an applicability: `machine-applicable` (safe to apply unseen),
`maybe-incorrect` (likely, check it) or `has-placeholders` (never applied as is). Plain
`marmot fix` applies only the first kind.

## Flags [#flags]

Flags take one dash or two: `-release` and `--release` are the same.

| Flag | Meaning |
| --- | --- |
| `-all` | also apply fixes that may be incorrect (typo corrections); check the result |
| `-code string` | only apply fixes for these comma separated codes, for example M0004,M0005 |
| `-color string` | color in human output: auto, always or never (NO_COLOR turns auto off) (default "auto") |
| `-diff` | print the check fixes as patches, change nothing |
| `-json` | machine readable output: JSON Lines on stderr (also $MARMOT_OUTPUT=json, and the default under coding agents) |
| `-only string` | apply only the fixes of these checks (fmt, modernize, vet, lint, exhaustive), not the build errors |
| `-tags string` | comma separated build tags |
| `-test` | keep a check fix only if the tests of its package still pass |
| `-upgrade string` | raise the go version of the modules to go1.N and apply the modernizers it unlocks |

## Full help [#full-help]

```text title="marmot fix --help"
Build, apply every machine applicable fix (missing imports, unused imports and variables, := with no new variables, ...), and build again until no fix applies. -all adds fixes that may be incorrect, such as typo corrections.

Usage:
  marmot fix [packages] [flags]

Examples:
marmot fix
marmot fix -code M0005 ./cmd/app
marmot fix -all

Flags:
      --all              also apply fixes that may be incorrect (typo corrections); check the result
      --code string      only apply fixes for these comma separated codes, for example M0004,M0005
      --color string     color in human output: auto, always or never (NO_COLOR turns auto off) (default "auto")
      --diff             print the check fixes as patches, change nothing
  -h, --help             help for fix
      --json             machine readable output: JSON Lines on stderr (also $MARMOT_OUTPUT=json, and the default under coding agents)
      --only string      apply only the fixes of these checks (fmt, modernize, vet, lint, exhaustive), not the build errors
      --tags string      comma separated build tags
      --test             keep a check fix only if the tests of its package still pass
      --upgrade string   raise the go version of the modules to go1.N and apply the modernizers it unlocks
```