11

I get this error message:

main.go:24: File is not `gci`-ed with --skip-generated -s standard,default (gci)
import (

What does this mean?

Background: I am new to Go, and the linting was not set up by me. I confess that I don't know the actual linter which creates this warning.

guettli
  • 25,042
  • 81
  • 346
  • 663
  • Looks like you are using a tool called `gci` which is skipping that file with the given flags. This isn't part of the `go` toolchain or language. – JimB Jan 19 '23 at 15:54
  • 1
    «I get this error message»—how do you get one? What linter do you run? It _looks_ like you're running `golangci-lint` (it aggregates multiple linters, and print the name of the linter which generated a warning in paretheses), is it correct? Please do not force those who's about to help to do psychic debugging. – kostix Jan 19 '23 at 16:20
  • 1
    If it's `golangci-lint`, then [here are the GCI's docs](https://github.com/daixiang0/gci) and [this](https://golangci-lint.run/usage/configuration) explains how to tweaks settings of particular linters or exclude specific files from being linted by particular linters etc. – kostix Jan 19 '23 at 16:21
  • @kostix thank you for your comments. I found a solution and posted it as answer below. – guettli Jan 19 '23 at 16:40

2 Answers2

10

Try

golangci-lint run --fix

and you can go from there!

jjkim
  • 417
  • 5
  • 12
8

gci is

a tool that controls golang package import order and makes it always deterministic.

When linting the code with golangci-lint, the changes required by the gci linter are not directly applied. One then has to manually apply them. For this get gci with

 go install github.com/daixiang0/gci@latest

scan it and directly write required changes with

gci write --skip-generated -s standard,default .
  • --skip-generated skips generated files
  • -s standard,default defines how import inputs are processed. standard are all official Golang provided imports, default are all other ones.
Wolfson
  • 1,187
  • 17
  • 22
guettli
  • 25,042
  • 81
  • 346
  • 663