GolangCI Not Removing Unused Imports

85 Views Asked by At

For some reason my GolangCI is able to identify unused imports but not able to remove them. This is my GolangCI file used to remove unused import statements, I did specify remove-unused as true:

run:
  timeout: 5m
  modules-download-mode: mod

linters:
  enable:
    - errcheck
    - goimports
    - revive
    - govet
    - staticcheck

linters-settings:
  goimports:
    remove-unused: true

  misspell:
    locale: US

issues:
  exclude-use-default: false
  max-issues-per-linter: 0
  max-same-issues: 0

This is how I am running my golangCI:

lint-build-code: ## Lint the generated Code in the Build Folder
    @echo "Linting code in directory: $(GEN_CODE_DIR)/src"
    docker run --rm -v $(PWD):/local \
        -w /local golangci/golangci-lint:latest \
        golangci-lint run --fix --config $(GOLANG_CI) --verbose ./$(GEN_CODE_DIR)/src/**
1

There are 1 best solutions below

0
On

I wish I could have gotten GolangCI to work but I couldn't. This is what I used to get the job done, if anyone has a way to get GolangCI work let me know.

remove-unused-imports: generate-code ## Remove unused imports
    @echo "Removing unused imports"
    cd ./$(GEN_CODE_DIR)/src/ && docker run --rm -v $(PWD):/data cytopia/goimports -d -w .