Configure and troubleshoot golangci-lint for Go projects. Handle import resolution issues, type-checking problems, and optimize configurations for both local and CI environments.
为Go项目配置和调试golangci-lint。本技能帮助处理导入解析问题、类型检查问题,并优化本地和CI环境的配置。
安装golangci-lint:
bash
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
或使用官方安装脚本:
bash
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
对整个项目运行linter:
bash
golangci-lint run ./...
使用特定配置运行:
bash
golangci-lint run --config .golangci.yml ./...
linters:
disable-all: true
enable:
- gofmt # 仅格式检查
linters-settings:
gofmt:
simplify: true
issues:
exclude-use-default: false
max-issues-per-linter: 50
max-same-issues: 3
output:
format: tab
linters:
enable:
- gofmt
- govet
- errcheck
- staticcheck
- unused
- gosimple
- ineffassign
linters-settings:
govet:
enable:
- shadow
errcheck:
check-type-assertions: true
staticcheck:
checks: [all]
issues:
exclude-use-default: false
max-issues-per-linter: 50
max-same-issues: 3
output:
format: tab
适用于GitHub Actions工作流:
yaml
name: 代码质量
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 设置Go环境
uses: actions/setup-go@v4
with:
go-version: 1.21
cache: true
- name: 下载依赖
run: go mod download
- name: 安装golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
- name: 运行Lint
run: golangci-lint run --config .golangci.yml ./...
根据项目需求和CI性能要求选择合适的linter。
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 go-linter-configuration-1776372154 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 go-linter-configuration-1776372154 技能
skillhub install go-linter-configuration-1776372154
文件大小: 2.29 KB | 发布时间: 2026-4-17 15:15