Meaning of "File is not `gci`-ed with --skip-generated -s standard,default (gci)"
Asked Answered
I

2

20

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.

Isolda answered 19/1, 2023 at 15:46 Comment(5)
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.Backspin
«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.Pictogram
If it's golangci-lint, then here are the GCI's docs and this explains how to tweaks settings of particular linters or exclude specific files from being linted by particular linters etc.Pictogram
@Pictogram thank you for your comments. I found a solution and posted it as answer below.Isolda
It is an issue that occurred because lint did not fit somewhere. In the case of me, I removed the blank line and solved itSubzero
S
25

Try

golangci-lint run --fix

and you can go from there!

Stichometry answered 27/4, 2023 at 16:22 Comment(2)
It might fix the issue but does not answer the question nor provide any hint. The answer from @Isolda helped me understand the message and how to deal with the matter. I would recommend to understand what is going on before using the --fix option.Diplomatics
Installation instructions are here: golangci-lint.run/usage/install/#local-installation (Assuming, like me, you're getting this error from CI and want to run this locally!)Hawkie
I
13

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.
Isolda answered 19/1, 2023 at 16:39 Comment(1)
To add on to this answer: it is most likely that the order of imports at the top of your .go file that is incorrect, although the gci tool doesn't actually tell you this in the error message. If you don't want to install gci locally, try reordering your imports and see if clears the error.Patrilineage

© 2022 - 2025 — McMap. All rights reserved.