我使用Makefile在GolangCI工具中启用了goImports,它能够发现未使用的导入,但不会自动删除它们.如何使我的GolangCI工具能够自动删除未使用的导入?
下面是我对Golangci皮棉使用的Makefile命令,我使用的是--fix
标签:
##@ Linting
lint:
@echo "lint via golangci-lint in " $(OUTPUT_DIR)/src
docker run --rm -v $(PWD):/local \
-w /local golangci/golangci-lint:latest \
golangci-lint run --fix --config .golangci.yaml $(OUTPUT_DIR)/src/*.go
下面是我的Golangci.yaml文件,我将remove-unused
设置为True:
run:
timeout: 5m
modules-download-mode: readonly
linters:
enable:
- errcheck
- goimports
- revive
- govet
- staticcheck
# Configuration for the goimports linter
goimports:
# Set to true to remove unused imports automatically
remove-unused: true
# Configuration for the revive linter
revive:
# Add any custom rules you want to use
rules:
- id: 'import-shadowing'
severity: warning
match: '\bimport\s+\.\s+\S+'
message: 'Importing packages using dot notation (.) is discouraged.'
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0