Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable int-conversion from perfsprint #8194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mmorel-35
Copy link
Contributor

@mmorel-35 mmorel-35 commented Jan 1, 2025

Description

enable and fixes all rules from perfsprint linter

@mmorel-35 mmorel-35 force-pushed the perfsprint/strconcat branch from 8d1f7a7 to be6aebd Compare January 1, 2025 12:15
@mmorel-35 mmorel-35 changed the title chore: enable strconcat rule from perfsprint chore: enable all rules from perfsprint Jan 1, 2025
@mmorel-35 mmorel-35 force-pushed the perfsprint/strconcat branch from f3c8f15 to 7cefcc7 Compare January 1, 2025 13:03
@@ -66,7 +66,7 @@ func TestRedisCache_PutArtifact(t *testing.T) {
addr = "dummy:16379"
}

c, err := cache.NewRedisCache(fmt.Sprintf("redis://%s", addr), "", "", "", false, 0)
c, err := cache.NewRedisCache("redis://"+addr, "", "", "", false, 0)
Copy link
Collaborator

@knqyf263 knqyf263 Jan 6, 2025

Choose a reason for hiding this comment

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

I feel like it's too much. `fmt.Sprintf is easier to read than string concatenation, even with a performance downside. However, if it drastically improves performance, it's worth considering.

.golangci.yaml Outdated
# Optimizes into strings concatenation.
strconcat: false
strconcat: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally prefer not to use this optimization.

Suggested change
strconcat: true
strconcat: false

@DmitriyLewen @simar7 @nikpivkin However, if you prefer string concatenation, I'm okay with that.

Copy link
Member

Choose a reason for hiding this comment

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

I would also vote not to use this. fmt.Sprintf seems fine to me. Is this subjective or there's something on the table w.r.t. performance by using this?

Copy link
Contributor

Choose a reason for hiding this comment

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

sometimes we use a long strings, so string concatenation will be almost unreadable.
So I think it is better to use fmt.Sprintf.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the performance gain will be imperceptible, but the readability will be lost. If we find a weakness, we can improve it.

@mmorel-35 mmorel-35 marked this pull request as draft January 9, 2025 06:18
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@mmorel-35 mmorel-35 force-pushed the perfsprint/strconcat branch from 7cefcc7 to 3540ec8 Compare January 9, 2025 06:35
@mmorel-35 mmorel-35 changed the title chore: enable all rules from perfsprint chore: enable int-conversion from perfsprint Jan 9, 2025
@mmorel-35 mmorel-35 marked this pull request as ready for review January 9, 2025 06:36
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

LGTM.
@aquasecurity/trivy Any other comments?

@@ -132,7 +133,7 @@ func parseTimestamp(ts string) (time.Time, error) {
case "Z07:00":
what = "UTC offset"
case "T":
return time.Time{}, fmt.Errorf("not a valid RFC3339 timestamp: missing required time introducer 'T'")
return time.Time{}, errors.New("not a valid RFC3339 timestamp: missing required time introducer 'T'")
Copy link
Contributor

@DmitriyLewen DmitriyLewen Jan 9, 2025

Choose a reason for hiding this comment

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

nit:

Suggested change
return time.Time{}, errors.New("not a valid RFC3339 timestamp: missing required time introducer 'T'")
return time.Time{}, xerrors.New("not a valid RFC3339 timestamp: missing required time introducer 'T'")

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.

5 participants