go-linting
Use when configuring Go linting, golangci-lint, static analysis, or CI checks, or choosing linters for a new project. Reviewing code belongs to go-code-review.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 7
- Forks
- 2
01 前言 Front Matter
- name
- go-linting
- description
- Use when configuring Go linting, golangci-lint, static analysis, or CI checks, or choosing linters for a new project. Reviewing code belongs to go-code-review.
- allowed-tools
- Bash(bash ${CLAUDE_SKILL_DIR}/scripts/*) Bash(bash ${CLAUDE_PLUGIN_ROOT}/hooks/go-check-receipt.sh *)
02 资源文件 4
- 资产文件assets/golangci.yml5.6 KB
- 参考文档references/CONFIGURATION.md5.4 KB
- 参考文档references/RECEIPTS.md3.0 KB
- 脚本scripts/setup-lint.sh7.4 KB
03 SKILL.md 正文
Go Linting
This skill owns the repository's verification gate — the commands that decide whether Go work is finished.
Compatibility: Baseline Go 1.27 (see COMPATIBILITY.md). Analyzer and linter names are checked against go1.27.2 and golangci-lint 2.15.0.
Resource Routing
scripts/setup-lint.sh- Run from the target module asbash <installed-skill-dir>/scripts/setup-lint.sh [local-prefix]when generating a.golangci.yml, validating the first lint pass, or producing JSON metadata.assets/golangci.yml- Use as the v2 golangci-lint baseline for established projects, and as the gate's lint config where the repository has none.../../hooks/go-check-receipt.sh- Where the plugin hook runs, execute the matching Bash verification command it prints before crediting a receipt; absent on standalone installs.../../hooks/helper/receipt.go- Internal receipt runner behind the Bash entry point; inspect only when debugging the hook or verifier.../../hooks/go-verification-routing.sh- The plugin's Bash verification prerequisite after a Go edit; inspect only when diagnosing routing or opt-out behavior.references/CONFIGURATION.md- Read for any linter configuration, CI, or first-lint setup task.references/RECEIPTS.md- Read before crediting an edit-hook receipt or writing apass (hook)orpass (receipt)label.
Verification Gate
Normative: Verify the requested work with observed results. Complete the repository's required checks; use the defaults below when it has no gate. A question or documentation-only edit does not require a Go runtime gate.
gofmt -l . # inspect output: exit 0 alone does not mean clean; a vendor/ or testdata/ path is not a finding
go build ./...
go vet ./... # includes stdversion, printf, lostcancel, waitgroup
go test -race ./...
go fix -diff <changed packages> # preview only; exits 1 whenever it prints a hunk
golangci-lint run ./... # no repository config: add --config <installed-skill-dir>/assets/golangci.yml
govulncheck ./... # dependency CVEs
Gate rules:
- Read the convention files go-style-core names. Use their gate at its required scope; do not automatically union it with this one. A specific request such as "check it builds" selects that check, not the full gate. Report the selected scope; build-only success is not full-gate success.
- Run from the target module or workspace, not the installed skill directory. For a local change without a prescribed gate, start with affected packages; include consumers for shared APIs and broaden for cross-package risk or release. Documentation-only work needs the applicable documentation checks.
- For modernization, identify existing packages from the task's actual diff,
including staged and untracked files when relevant. Pass explicit quoted
package arguments (for example
go fix -diff ./internal/store). An empty package list means skip; do not fall back to the current package or./.... Separate pre-existing findings from new ones; do not rewrite unrelated code. The check ispasswhen no hunk lies in the lines the task wrote or changed, whatever the exit code, and the report counts the other hunks as pre-existing; a hunk in those lines isfail. golangci-lint config pathexits non-zero when the repository has no lint config; lint with the bundled baseline then. Without it golangci-lint runs five default linters: none of thenoctx,bodyclose,rowserrcheck,sqlclosecheck,gosec, orsloglintchecks the skills name runs, anderrcheckreports the deferredrows.Close,tx.Rollback, andresp.Body.Closethe baseline excludes.- The default gate always runs
-race. A repository gate without it gets one-racerun of the changed packages for a concurrency change: inspect amake testrecipe first, since a plaingo testis not evidence of a race check, and keep its setup in the race-enabled equivalent. - A check's result is its own exit status, not the pipeline's:
go test ./... | tailexits 0 on a failure, and| headkillsgo testwith SIGPIPE before later packages run. Run gate commands unpiped or underset -o pipefail. - Run
govulncheckbefore release, for dependency changes in the requested diff (including staged changes), or when requested. Otherwise report itskipped (no dependency change). - Fix attributable failures in the code, not in the check
(Holding the Bar), then rerun affected checks. Reuse passing results
for unchanged code and configuration, including across checklist items. Repeat
or broaden only for new edits, failures, unresolved concerns, or required gates.
A check that fails the same way after two fixes aimed at it has a cause not
yet found: stop patching, take go-troubleshooting's
loop from the first diagnostic, and if it does not close, report the check
failwith both attempts. - Where the plugin edit hook runs, first run the
go-check-receipt.sh --gatecommand the last edit hook printed, as printed and alone in its Bash call, before any direct check and again after every later Go edit: the plugin blocks a direct check until then. Credit only what it reports with exit 0 andhook_credit=true, at its reported scope; run every other selected check directly. Hook tests use-shortwithout-race. Without a shell, a hook result isobserved (hook, reuse unverified), neverpass. RECEIPTS.md holds the rest of the receipt rules; read it before writing apass (hook)orpass (receipt)label. - A test check passes on evidence that the tests ran, not on exit 0.
ok … [no tests to run](a-runpattern that matches nothing, or a file behind a//go:buildtag the run did not pass),[no test files], and aTestMainthat returns beforem.Run(INTEGRATION.md), and a package whose tests all calledt.Skipall exit 0 having run nothing; anExamplewithout// Output:is compiled and never run. The evidence is--- PASS: TestXunder-vor its"Action":"pass"event under-json. - Report each selected check as
pass,fail, orunavailable (reason); explicitly omitted checks areskipped (reason). OverallPASSrequires all required checks to pass;FAILmeans a finding;INCOMPLETEmeans required evidence is unavailable with no known finding. Report both when they coexist. Missing tools, unsupported toolchains, and infrastructure failures are not clean results. Attribute an environment gap from evidence, not error text alone. A missing tool is reported, not installed: unless the task asks, the gate never runsgo installorgo get, editsgo.mod, or switches the toolchain to make a check runnable.
Modernization: go fix
Since Go 1.26 the modernizers are go fix analyzers.
go fix -diff <packages> previews; go fix <packages> applies. Use the package
scope established above and inspect the preview before applying changes.
go tool fix help lists the current set; most rewrite to a form the
idiom card lists, and
MODERNIZATION.md
names the rest, the Go 1.27 renames, and which hunks change behavior.
Select a subset with go fix -rangeint ./..., or exclude with
-NAME=false. Review the diff: these carry fixes, not just diagnostics, and a
few change allocation behavior.
Fixes from two analyzers that overlap are not shown at all: go fix -diff
exits 1 with only fix: N of M fixes skipped (e.g. due to conflicts), and on
go1.27.1 a plain go fix then reports them applied without writing a file.
Preview and apply one analyzer at a time (go fix -diff -rangeint ./pkg), and
confirm a write with git diff --stat.
After applying fixes, build the affected packages and review retained comments:
modernizers can leave unused imports/variables or discard comments inside a
rewritten loop. Use the existing gate once on the final code, not a duplicate
verification cycle.
Nolint Directives
return rand.N(d) //nolint:gosec // G404: retry jitter, not a secret
nolintlint in the baseline rejects a bare //nolint, one without a reason,
and one on a line with no finding for that linter; place the comment on the
finding's line. _ = f() needs no directive: errcheck does not report an
explicit discard. The line still says why: a bare _ on an error is a
go-code-review finding.
Holding the Bar
Normative: A failing check turns green by a change to the code, never by a change to the check.
The cheap road to green, and what it looks like in a diff:
| Move | In the diff |
|---|---|
| Silence a checker | a new //nolint, //lint:ignore, or #nosec; a .golangci.yml edit that disables a linter, adds an exclusion, or raises a threshold |
| Make a test easier | a new t.Skip or testing.Short() guard; a test file or test function deleted; an assertion, // Output: line, or table case removed from a test that stays; a testdata/*.golden file rewritten to match the new output |
| Drop a check | -race removed from the Makefile, CI, or a script |
| Leave the work unfinished | panic("not implemented") where the behavior should be |
| Quiet the compiler | _ on an error a changed signature now returns; return nil, nil or a zero value added for missing return; n, _ := strconv.Atoi(s): the build passes and the behavior is invented |
Each move is legitimate only with a reason a reviewer can check, on the line
or in the report: the directive's reason (Nolint Directives),
the infrastructure a skipped test needs, the requirement that changed a golden
file. Without one the failure stays and is reported as fail. Tightening needs
no mention. pre-review.sh --new-from-rev <base> lists the first four rows'
moves in a diff (go-code-review); a quieted
compiler is found by reading it.
Related Skills
- go-code-review: linter output alongside the manual checklist.
- go-error-handling: what to do with an
errcheckfinding. - go-testing: linters and tests in one CI pipeline.
04 同仓库更多 Skills
go-troubleshooting
Use when investigating a bug or ticket in a Go service whose cause is unknown — wrong or missing results, tenant-specific behavior, a regression, stage/prod/CI differences, a panic, hang, deadlock, leak, unexplained CPU/RSS growth, or a flaky test. Also use for pasted stack traces, profiles, logs, or requests to find a Go issue's root cause, even without the word debug. Does not cover rewriting ticket text, implementing an already-diagnosed fix alone (use its topic skill), or optimizing a known bottleneck (see go-performance).
go-testing
Use when writing, reviewing, or improving Go test code — including table-driven tests, subtests, parallel tests, test helpers, test doubles, and assertions with cmp.Diff. Also use when a user asks to write a test for a Go function, even if they don't mention specific patterns like table-driven tests or subtests. Does not cover benchmark performance testing (see go-performance).
go-style-core
Use when resolving Go style or language mechanics such as formatting, nesting, declarations, initialization, scope, shadowing, loops, switches, or enum zero values. API design, naming, errors, and tests have specialized skills.
go-security
Use when writing or reviewing Go code that touches untrusted input, secrets, or credentials — SQL, shell, or template injection, path traversal, SSRF, cookies and security headers, password hashing, TLS settings, token comparison, or what may appear in a log line. Also use when a handler accepts a file name, URL, or command argument from a client, or when asked to find "vulnerabilities", even if the user never says "security". Does not cover the os.Root and crypto/rand mechanics (see go-defensive) or the dependency CVE scan in the gate (see go-linting).
go-resilience
Use when handling Go dependency failures or overload with retries, backoff/jitter, budgets, idempotency, duplicate delivery, circuit breakers, bulkheads, rate limits, backpressure, or degradation. Unknown root causes belong to go-troubleshooting.
go-performance
Use when optimizing slow or performance-critical Go code, allocations, string concatenation in loops, or benchmarks. Also use when writing or reviewing a cache, including implementing one from a stub — its key, its expiry, and how a miss loads. Concurrent code patterns belong to go-concurrency.