Skip to content

Revert strconv changes - keep fmt.Sprintf to pass linter#8

Closed
ilramdhan wants to merge 1 commit into
masterfrom
session/agent_1e6d5de6-be76-473e-bccd-b383e5a8aa6d
Closed

Revert strconv changes - keep fmt.Sprintf to pass linter#8
ilramdhan wants to merge 1 commit into
masterfrom
session/agent_1e6d5de6-be76-473e-bccd-b383e5a8aa6d

Conversation

@ilramdhan
Copy link
Copy Markdown
Owner

Description

Reverts the strconv.Itoa changes back to fmt.Sprintf as golangci-lint reports S1039 false positive for these cases. The fmt.Sprintf is needed for proper zero-padding in SQLite strftime queries.

Type of Change

  • ♻️ Code refactoring

Changes Made

  1. Reverted holiday_repository.go to use fmt.Sprintf
  2. Reverted pkg/client/client.go to use fmt.Sprintf

How Has This Been Tested?

  • Manual testing

Description

Fixes # (issue number)

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🎨 Code style/formatting
  • ♻️ Code refactoring
  • ⚡ Performance improvement
  • 🧪 Test updates
  • 🔧 Build/CI changes
  • 📝 Other (please describe):

Changes Made

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual testing
  • Other (please describe):

Test Configuration:

  • Go version:
  • Operating System:

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

Related PRs

## Description
Reverts the strconv.Itoa changes back to fmt.Sprintf as golangci-lint reports S1039 false positive for these cases. The fmt.Sprintf is needed for proper zero-padding in SQLite strftime queries.

## Type of Change
- [x] ♻️ Code refactoring

## Changes Made
1. Reverted holiday_repository.go to use fmt.Sprintf
2. Reverted pkg/client/client.go to use fmt.Sprintf

## How Has This Been Tested?
- [x] Manual testing
@ilramdhan ilramdhan requested a review from Copilot March 4, 2026 16:13
@ilramdhan ilramdhan self-assigned this Mar 4, 2026
@ilramdhan ilramdhan added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Mar 4, 2026
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread pkg/client/client.go
}
if month != nil {
q.Add("month", strconv.Itoa(*month))
q.Add("month", fmt.Sprintf("%d", *month))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Month filtering will break - the API handler parses month as integer (1-12), but this sends zero-padded string (01-12). When user passes month=1, this sends "01" which fails the integer parsing in the handler (strconv.Atoi("01") returns 1, but the filter won't match the "01" in SQL).

if filter.Month != nil {
whereConditions = append(whereConditions, "strftime('%m', date) = ?")
args = append(args, strconv.Itoa(*filter.Month))
args = append(args, fmt.Sprintf("%02d", *filter.Month))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Repository expects month in "%02d" format (e.g., "01", "02"), but the handler sends month as integer (1, 2) to the repository. This will cause month filtering to silently fail.

if filter.Day != nil {
whereConditions = append(whereConditions, "strftime('%d', date) = ?")
args = append(args, strconv.Itoa(*filter.Day))
args = append(args, fmt.Sprintf("%02d", *filter.Day))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Same issue as line 98 - day filter expects "%02d" format but receives integer.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 4, 2026

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 2
SUGGESTION 0

Issue Details

CRITICAL

File Line Issue
pkg/client/client.go 107 Client sends zero-padded month ("01") but API handler parses as integer (1-12), breaking month filtering

WARNING

File Line Issue
internal/repository/holiday_repository.go 98 Repository expects month in "%02d" format but receives integer from handler
internal/repository/holiday_repository.go 103 Same issue - day filter expects "%02d" format but receives integer

Root Cause

The code changes replaced strconv.Itoa() with fmt.Sprintf("%02d", ...) for month/day, but:

  1. The Go client (pkg/client/client.go) sends month as zero-padded string to the API
  2. The API handler (internal/handlers/holiday_handler.go) parses month as integer and passes to repository
  3. The repository uses strftime('%m', date) which expects "01" format for January

Result: The month filter will not match because the repository compares "01" against integer 1.

Suggested Fix

  1. Option A: Change repository to use integer comparison: CAST(strftime('%m', date) AS INTEGER) = ?
  2. Option B: Pass month/day as zero-padded strings through the handler to repository
  3. Option C: Remove zero-padding in repository and use integer conversion on SQL side

Files Reviewed (2 files)

  • internal/repository/holiday_repository.go - 2 issues
  • pkg/client/client.go - 1 issue

This is a Go (Golang) API project with SQLite database.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reverts integer-to-string conversions from strconv.Itoa back to fmt.Sprintf in a couple of places, motivated by golangci-lint/staticcheck behavior and SQLite strftime zero-padding requirements for month/day filters.

Changes:

  • Switched query parameter serialization in pkg/client/client.go back to fmt.Sprintf.
  • Switched SQLite strftime filter argument formatting in internal/repository/holiday_repository.go back to fmt.Sprintf (including %02d padding for month/day).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/client/client.go Reverts year/month query parameter string conversions to fmt.Sprintf.
internal/repository/holiday_repository.go Reverts date-part filter argument formatting to fmt.Sprintf (with zero-padding for month/day).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/client/client.go
Comment on lines 103 to +107
if year != nil {
q.Add("year", strconv.Itoa(*year))
q.Add("year", fmt.Sprintf("%d", *year))
}
if month != nil {
q.Add("month", strconv.Itoa(*month))
q.Add("month", fmt.Sprintf("%d", *month))
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sprintf("%d", ...) on query parameters will be flagged by staticcheck (S1039) as unnecessary formatting. Since there’s no zero-padding needed here, prefer strconv.Itoa(...) (and re-add the strconv import) to keep golangci-lint green.

Copilot uses AI. Check for mistakes.
if filter.Year != nil {
whereConditions = append(whereConditions, "strftime('%Y', date) = ?")
args = append(args, strconv.Itoa(*filter.Year))
args = append(args, fmt.Sprintf("%d", *filter.Year))
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sprintf("%d", *filter.Year) is also likely to trigger staticcheck S1039 (unnecessary Sprintf). Using strconv.Itoa(*filter.Year) avoids the lint issue and would also make the existing strconv import in this file meaningful (right now it’s unused, which will fail the build).

Suggested change
args = append(args, fmt.Sprintf("%d", *filter.Year))
args = append(args, strconv.Itoa(*filter.Year))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants