golang-lint by samber/cc-skills-golang
npx skills add https://github.com/samber/cc-skills-golang --skill golang-lint角色: 你是一名 Go 代码质量工程师。你将代码检查视为开发工作流程中不可或缺的一环——而非事后清理步骤。
模式:
.golangci.yml、选择检查器、启用 CI:请按配置和工作流章节的顺序操作。golangci-lint run --fix;完成后展示结果。golangci-lint 是标准的 Go 代码检查工具。它将 100 多个检查器聚合到一个二进制文件中,并行运行它们,并提供统一的配置格式。在开发过程中应频繁运行它,并且在 CI 中必须始终运行。
每个 Go 项目必须有一个 .golangci.yml 文件——它是启用哪些检查器以及如何配置它们的唯一事实来源。查看推荐配置,这是一个启用了 33 个检查器的生产就绪设置。
# 运行所有已配置的检查器
golangci-lint run ./...
# 自动修复可能的问题
golangci-lint run --fix ./...
# 格式化代码 (golangci-lint v2+)
golangci-lint fmt ./...
# 仅运行单个检查器
golangci-lint run --enable-only govet ./...
# 列出所有可用的检查器
golangci-lint linters
# 带有计时信息的详细输出
golangci-lint run --verbose ./...
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
推荐的 .golangci.yml 提供了一个启用了 33 个检查器的生产就绪设置。关于配置详情、检查器类别以及每个检查器的描述,请参阅**检查器参考**——其中说明了哪些检查器检查什么(正确性、风格、复杂度、性能、安全性),描述了所有 33+ 个检查器,以及每个检查器在何时有用。
请谨慎使用 //nolint 指令——首先修复根本原因。
// 良好:指定检查器 + 理由
//nolint:errcheck // 即发即弃的日志记录,错误不可操作
_ = logger.Sync()
// 不良:无理由的全面抑制
//nolint
_ = logger.Sync()
规则:
//nolint:errcheck 而非 //nolint//nolint:errcheck // 理由nolintlint 检查器强制执行上述两条规则——它会标记裸 //nolint 和缺少理由的情况关于全面的模式和示例,请参阅 nolint 指令——何时抑制、如何编写理由、逐行抑制与逐函数抑制的模式,以及反模式。
golangci-lint run ./...golangci-lint run --fix ./...golangci-lint fmt ./....golangci.yml 中设置 issues.new-from-rev 以仅检查新的/更改的代码,然后逐步清理旧代码Makefile 目标(推荐):
lint:
golangci-lint run ./...
lint-fix:
golangci-lint run --fix ./...
fmt:
golangci-lint fmt ./...
关于 CI 流水线设置(使用 golangci-lint-action 的 GitHub Actions),请参阅 samber/cc-skills-golang@golang-continuous-integration 技能。
每个问题遵循以下格式:
path/to/file.go:42:10: 描述问题的消息 (linter-name)
括号中的检查器名称告诉你哪个检查器标记了它。使用它来:
//nolint:linter-name // 理由 来抑制golangci-lint run --verbose 获取额外的上下文和计时信息| 问题 | 解决方案 |
|---|---|
| "deadline exceeded" | 增加 .golangci.yml 中的 run.timeout(默认:5m) |
| 遗留代码问题过多 | 设置 issues.new-from-rev: HEAD~1 以仅检查新代码 |
| 检查器未找到 | 检查 golangci-lint linters —— 检查器可能需要更新版本 |
| 检查器之间冲突 | 禁用用处较小的那个,并附上解释原因的注释 |
| 升级后 v1 配置错误 | 运行 golangci-lint migrate 转换配置格式 |
| 大型仓库运行缓慢 | 减少 run.concurrency 或在 run.skip-dirs 中排除目录 |
在遗留代码库上采用代码检查时,使用最多 5 个并行的子代理(通过 Agent 工具)来同时修复独立的检查器类别:
golangci-lint run --fix ./... 处理可自动修复的问题samber/cc-skills-golang@golang-continuous-integration 技能,了解使用 golangci-lint-action 的 CI 流水线samber/cc-skills-golang@golang-code-style 技能,了解检查器强制执行的风格规则samber/cc-skills-golang@golang-security 技能,了解超越代码检查的 SAST 工具(gosec, govulncheck)每周安装数
74
代码仓库
GitHub 星标数
184
首次出现
3 天前
安全审计
安装于
opencode72
codex71
gemini-cli71
kimi-cli70
github-copilot70
cursor70
Persona: You are a Go code quality engineer. You treat linting as a first-class part of the development workflow — not a post-hoc cleanup step.
Modes:
.golangci.yml, choosing linters, enabling CI: follow the configuration and workflow sections sequentially.golangci-lint run --fix on the modified files only while the main agent continues implementing the feature; surface results when it completes.golangci-lint is the standard Go linting tool. It aggregates 100+ linters into a single binary, runs them in parallel, and provides a unified configuration format. Run it frequently during development and always in CI.
Every Go project MUST have a .golangci.yml — it is the source of truth for which linters are enabled and how they are configured. See the recommended configuration for a production-ready setup with 33 linters enabled.
# Run all configured linters
golangci-lint run ./...
# Auto-fix issues where possible
golangci-lint run --fix ./...
# Format code (golangci-lint v2+)
golangci-lint fmt ./...
# Run a single linter only
golangci-lint run --enable-only govet ./...
# List all available linters
golangci-lint linters
# Verbose output with timing info
golangci-lint run --verbose ./...
The recommended .golangci.yml provides a production-ready setup with 33 linters. For configuration details, linter categories, and per-linter descriptions, see the linter reference — which linters check for what (correctness, style, complexity, performance, security), descriptions of all 33+ linters, and when each one is useful.
Use //nolint directives sparingly — fix the root cause first.
// Good: specific linter + justification
//nolint:errcheck // fire-and-forget logging, error is not actionable
_ = logger.Sync()
// Bad: blanket suppression without reason
//nolint
_ = logger.Sync()
Rules:
//nolint:errcheck not //nolint//nolint:errcheck // reasonnolintlint linter enforces both rules above — it flags bare //nolint and missing reasonsFor comprehensive patterns and examples, see nolint directives — when to suppress, how to write justifications, patterns for per-line vs per-function suppression, and anti-patterns.
golangci-lint run ./...golangci-lint run --fix ./...golangci-lint fmt ./...issues.new-from-rev in .golangci.yml to only lint new/changed code, then gradually clean up old codeMakefile targets (recommended):
lint:
golangci-lint run ./...
lint-fix:
golangci-lint run --fix ./...
fmt:
golangci-lint fmt ./...
For CI pipeline setup (GitHub Actions with golangci-lint-action), see the samber/cc-skills-golang@golang-continuous-integration skill.
Each issue follows this format:
path/to/file.go:42:10: message describing the issue (linter-name)
The linter name in parentheses tells you which linter flagged it. Use this to:
//nolint:linter-name // reason if it's a false positivegolangci-lint run --verbose for additional context and timing| Problem | Solution |
|---|---|
| "deadline exceeded" | Increase run.timeout in .golangci.yml (default: 5m) |
| Too many issues on legacy code | Set issues.new-from-rev: HEAD~1 to lint only new code |
| Linter not found | Check golangci-lint linters — linter may need a newer version |
| Conflicts between linters | Disable the less useful one with a comment explaining why |
| v1 config errors after upgrade | Run golangci-lint migrate to convert config format |
| Slow on large repos | Reduce or exclude directories in |
When adopting linting on a legacy codebase, use up to 5 parallel sub-agents (via the Agent tool) to fix independent linter categories simultaneously:
golangci-lint run --fix ./... for auto-fixable issuessamber/cc-skills-golang@golang-continuous-integration skill for CI pipeline with golangci-lint-actionsamber/cc-skills-golang@golang-code-style skill for style rules that linters enforcesamber/cc-skills-golang@golang-security skill for SAST tools beyond linting (gosec, govulncheck)Weekly Installs
74
Repository
GitHub Stars
184
First Seen
3 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode72
codex71
gemini-cli71
kimi-cli70
github-copilot70
cursor70
智能代码探索工具smart-explore:AST解析结构化代码搜索与导航
798 周安装
run.concurrencyrun.skip-dirs