Skip to content

refactor: tidy source, tests and docs - #178

Draft
yesdevnull wants to merge 1 commit into
mainfrom
claude/gifted-newton-h8bnjs
Draft

yesdevnull wants to merge 1 commit into
mainfrom
claude/gifted-newton-h8bnjs

Conversation

@yesdevnull

Copy link
Copy Markdown
Owner

Summary

A code quality and cleanup pass over the tool, with a secondary pass over the tests and the agent docs. CLI output, flags, exit codes and the JSON contracts are unchanged.

Source (main.go, config.go, audit.go)

  • Doc comments condensed to idiomatic Go: the javadoc-style Parameters/Returns/Examples tables are replaced with one-paragraph summaries, and the longest explanatory comments are trimmed while keeping the reasoning they record.
  • updateVerb supplies the ✓ Updated / → Would update prefix and verb that three loops each built by hand; moduleUpdateOptions.warnSkip prints the three module skip warnings that each spelt out the same Fprintf.
  • The module and provider block updaters no longer return a changed result that always equalled updated; updateProviderBlockSyntaxResult returns only the changed indexes.
  • containsVersion is replaced by slices.Contains, shouldIgnoreModule uses slices.ContainsFunc, and the three-helper wildcard matcher becomes one matchPattern that searches the middle parts between the fixed prefix and suffix (same semantics, same pattern_test.go).
  • objectItemValueRange is shared by the updater and the audit instead of two copies of the byte-range check; replaceProviderObjectVersion uses slices.Clone and slices.Concat.
  • updateReport records block IDs into caller-owned maps rather than returning them; runConfigFileMode fills configOutcome directly and printConfigSummary prints its count lines through one helper.
  • Nested errors are wrapped with %w; FromVersions.UnmarshalYAML is a kind switch and loadConfig uses errors.Is for EOF.
  • .golangci.yml disables staticcheck ST1005 (the CLI prints its capitalised Error: strings verbatim), which removes the ~25 per-line //nolint:staticcheck directives.

Tests

  • runMainCommand, captureRunnerOutput, captureStream, captureLog and captureStdoutAndStderr are rebuilt on two shared primitives, redirectStream and redirectLog, replacing five hand-rolled pipe/drain/restore sequences.
  • The test-only updateTerraformVersion adapter moves beside the other adapters in test_helpers_test.go.
  • TestUpdateActionsReleasePinRejectsUnwritableTargetWithoutPartialChanges now skips as root like the other permission tests (it failed when run as root).

Docs

  • CLAUDE.md: the "Errors and output" and -report-file paragraphs are condensed, and the lint section notes the ST1005 change.

Validation

  • go vet, go test -race -coverprofile=... (coverage 94.3%), golangci-lint run on v2.12.2 (0 issues), go build, make actionlint, and a manual dry run and real run of the built binary over examples/*.tf in a scratch directory.
  • make shellcheck was not run here (shellcheck is not installed in this environment); no shell scripts changed.

Generated by Claude Code

Condense doc comments to idiomatic Go, replacing the parameter and return
tables with one-paragraph summaries, and trim the longest explanatory
comments while keeping the reasoning they record.

Source simplifications, with no change to CLI output or exit codes:
- share the dry-run prefix/verb through updateVerb and the module skip
  warning through moduleUpdateOptions.warnSkip
- drop the always-equal changed result from the module and provider block
  updaters, and the explicit zeroing of named results
- replace containsVersion with slices.Contains and the three-helper
  wildcard matcher with one function that searches the middle parts
  between the fixed prefix and suffix
- share the object item byte-range check between the updater and the
  audit through objectItemValueRange
- record report block IDs into caller-owned maps rather than returning
  them, and fill configOutcome directly in runConfigFileMode
- wrap nested errors with %w, and switch FromVersions.UnmarshalYAML to a
  kind switch with errors.Is for EOF

Disable staticcheck ST1005 in .golangci.yml, since the CLI prints its
capitalised Error strings verbatim, and remove the per-line nolint
directives it needed.

Tests: build runMainCommand, captureRunnerOutput, captureStream,
captureLog and captureStdoutAndStderr on two shared redirectStream and
redirectLog primitives; move the updateTerraformVersion adapter beside
the other test-only adapters; skip the read-only release-pin test as
root like the other permission tests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3nZPPpASKdKUe8n5vqdoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants