Skip to content

refactor: streamline Makefile and add diff functionality with tests - #11

Merged
kazeburo merged 5 commits into
masterfrom
feat/refactor
Aug 5, 2026
Merged

kazeburo merged 5 commits into
masterfrom
feat/refactor

Conversation

@kazeburo

@kazeburo kazeburo commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

User description

  • modify Makefile and add make lint
  • create diff.go and move some fuctions
  • fix some lint issues

PR Type

Enhancement, Tests


Description

  • Extract diff helpers into new diff.go

  • Add diff_test.go covering diff and message builders

  • Improve main.go error handling and exit codes

  • Update Makefile with wildcard targets and lint


Diagram Walkthrough

flowchart LR
  A["main.go"] -- "extracts diff helpers" --> B["diff.go"]
  B -- "unit tests" --> C["diff_test.go"]
  A -- "better exit codes & error handling" --> A
  D["Makefile"] -- "adds lint target & wildcards" --> D
Loading

File Walkthrough

Relevant files
Enhancement
diff.go
Extract diff helpers into dedicated file                                 

diff.go

  • New file containing diff, getLines, buildDiffMsg, and
    buildNoDifferenceMsg
  • Uses gonp to compute unified diffs between two files
  • Handles io.EOF when reading file preview bytes
+81/-0   
main.go
Improve main error handling and constants                               

main.go

  • Remove diff helpers moved to diff.go
  • Add exit-code constants OK, WARNING, CRITICAL, UNKNOWN
  • Improve main error handling for help output and missing command
  • Wrap command error with %w and ignore os.Remove return
+19/-82 
Tests
diff_test.go
Add unit tests for diff helpers                                                   

diff_test.go

  • New test file for diff.go functions
  • Covers diff, buildDiffMsg, buildNoDifferenceMsg, and large-result
    truncation
  • Verifies no-difference case returns empty diff
+88/-0   
main_test.go
Clean up tests after diff extraction                                         

main_test.go

  • Remove diff-related tests now in diff_test.go
  • Handle error from file.Seek in TestCmd
  • Ignore os.Remove return value in createTempFile cleanup
+5/-84   
Configuration changes
Makefile
Streamline build targets and add lint                                       

Makefile

  • Use *.go wildcard for check-diff and linux targets
  • Add lint target running golangci-lint run ./...
+6/-4     

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 8a2b0ea)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incomplete .PHONY

The .PHONY declaration only lists check-diff, but all, linux, check, and lint are also phony targets. If a file named lint, check, linux, or all exists in the project root, make will incorrectly treat the target as up-to-date and skip the recipe. For example, touch lint && make lint would not run golangci-lint.

.PHONY: check-diff

check-diff: *.go
	go build $(LDFLAGS) -o check-diff

linux: *.go
	GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o check-diff

check:
	go test -v ./...

lint:
	golangci-lint run ./...

Comment thread diff.go
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 8c4c517

Comment thread diff.go
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit ac9ed4a

Comment thread main.go
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit b51bdf6

Comment thread diff.go Outdated
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 8a2b0ea

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@kazeburo
kazeburo merged commit 197007f into master Aug 5, 2026
3 checks passed
@kazeburo
kazeburo deleted the feat/refactor branch August 5, 2026 13:50
@github-actions github-actions Bot mentioned this pull request Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant