Skip to content

add lint and fix some issue - #49

Merged
kazeburo merged 3 commits into
masterfrom
feat/lint-and-fix
Jul 30, 2026
Merged

add lint and fix some issue#49
kazeburo merged 3 commits into
masterfrom
feat/lint-and-fix

Conversation

@kazeburo

@kazeburo kazeburo commented Jul 30, 2026

Copy link
Copy Markdown
Member

User description

  • add golangci.yml and make lint
  • fix lint issues

PR Type

Enhancement, Tests, Bug fix


Description

  • Add golangci-lint configuration and Makefile target

  • Improve error handling and logging in main

  • Refactor test helpers for safer cleanup

  • Pre-allocate slice capacity to optimize performance


Diagram Walkthrough

flowchart LR
  Config["Add .golangci.yml & Makefile lint target"] --> ErrorHandling["Improve error handling & logging"]
  ErrorHandling --> Tests["Refactor test cleanup helpers"]
  Tests --> Perf["Pre-allocate slices & reduce complexity"]
Loading

File Walkthrough

Relevant files
Enhancement
command.go
Pre-allocate slice capacity for metric results                     

internal/statworker/command.go

  • Pre-allocates slice capacity to 5 for better performance
+1/-1     
Tests
stat_test.go
Refactor temporary file cleanup in test helpers                   

internal/statworker/stat_test.go

  • Updates tmpFileWithContent to return a cleanup function
  • Replaces manual os.Remove with deferred cleanup calls
+17/-12 
main_test.go
Handle server serve errors gracefully in tests                     

main_test.go

  • Wraps srv.Serve in a goroutine with error logging
  • Prevents silent failures during test server startup
+6/-1     
Bug fix
main.go
Add comprehensive error handling and logging                         

main.go

  • Adds error checking for syscall.Kill and cmd.Start
  • Logs removal errors and handles missing socket files
+23/-12 
Configuration changes
.golangci.yml
Add golangci-lint configuration and linter settings           

.golangci.yml

  • Introduces linter configuration with enabled static analysis tools
  • Configures complexity thresholds and error check exclusions
+37/-0   
Makefile
Add lint target to project Makefile                                           

Makefile

  • Adds lint target to run golangci-lint
  • Sets 5-minute timeout for linting process
+2/-0     

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit cf6a8d3)

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

Potential Variable Scope Issue

The line err = os.Remove(opt.Socket) uses the assignment operator =. If the err variable is not already declared in the function scope, this will result in a compile error. Ensure err is declared earlier in the function, or change to err := os.Remove(opt.Socket) to declare it locally.

err = os.Remove(opt.Socket)
if err != nil && !os.IsNotExist(err) {
	log.Printf("%v", err)
	return CRITICAL
}

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Latest suggestions up to cf6a8d3

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix potential variable scope issue with err assignment

Ensure err is properly declared in the current scope before assignment. Using =
requires err to be already defined; otherwise, it will cause a compilation error.
Verify the variable's declaration location to prevent scope-related issues.

main.go [132-136]

-	err = os.Remove(opt.Socket)
-	if err != nil && !os.IsNotExist(err) {
-		log.Printf("%v", err)
-		return CRITICAL
-	}
+err := os.Remove(opt.Socket)
+if err != nil && !os.IsNotExist(err) {
+	log.Printf("%v", err)
+	return CRITICAL
+}
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a compilation error where err is assigned using = without prior declaration. Changing it to := ensures proper variable declaration in the current scope, which is critical for the code to build successfully.

High
General
Prevent blocking the check loop with time.Sleep

The time.Sleep blocks the ticker loop goroutine, delaying subsequent binary
modification checks. Consider using a separate goroutine or a timer channel to avoid
blocking the main check loop.

main.go [54-61]

 } else {
-	time.Sleep(10 * time.Second)
-	// sockファイルを消さないようsigkillで止める
-	errKill := syscall.Kill(syscall.Getpid(), syscall.SIGKILL)
-	if errKill != nil {
-		log.Printf("%v", errKill)
-	}
+	go func() {
+		time.Sleep(10 * time.Second)
+		// sockファイルを消さないようsigkillで止める
+		errKill := syscall.Kill(syscall.Getpid(), syscall.SIGKILL)
+		if errKill != nil {
+			log.Printf("%v", errKill)
+		}
+	}()
 }
Suggestion importance[1-10]: 6

__

Why: Wrapping the time.Sleep and syscall.Kill in a goroutine prevents blocking the ticker loop, allowing the binary modification check to run at its intended 5-second interval. This improves responsiveness and concurrency without altering core logic.

Low

Previous suggestions

Suggestions up to commit 6832ea0
CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix undefined variable compilation error

The variable err is assigned using = but is not declared in the current scope, which
will cause a compilation error. Replace the assignment with a short variable
declaration inside an if statement to fix the issue and properly scope the error
variable.

main.go [131-135]

-err = os.Remove(opt.Socket)
-if err != nil && !os.IsNotExist(err) {
+if err := os.Remove(opt.Socket); err != nil && !os.IsNotExist(err) {
 	log.Printf("%v", err)
 	return CRITICAL
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential compilation error from reusing err without declaration and proposes the idiomatic if err := ... pattern, which properly scopes the variable and resolves the issue.

Medium
Suggestions up to commit c206cde
CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix assignment operator to prevent compilation error

The assignment err = os.Remove(opt.Socket) will cause a compilation error if err is
not already declared in this scope. Change = to := to properly declare the variable
and avoid a compile-time error.

main.go [131-135]

--	os.Remove(opt.Socket)
-+	err = os.Remove(opt.Socket)
-+	if err != nil && !os.IsNotExist(err) {
-+		log.Printf("%v", err)
-+		return CRITICAL
-+	}
+err := os.Remove(opt.Socket)
+if err != nil && !os.IsNotExist(err) {
+	log.Printf("%v", err)
+	return CRITICAL
+}
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that err = will cause a compilation error if err is not previously declared in the scope. Changing it to := properly declares the variable and fixes the issue.

Medium

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 6832ea0

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit cf6a8d3

@kazeburo
kazeburo merged commit 4531016 into master Jul 30, 2026
3 checks passed
@kazeburo
kazeburo deleted the feat/lint-and-fix branch July 30, 2026 14:47
@github-actions github-actions Bot mentioned this pull request Jul 30, 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