Skip to content

Fix lint errors #5897

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

Merged
merged 11 commits into from
May 29, 2025
Merged

Fix lint errors #5897

merged 11 commits into from
May 29, 2025

Conversation

Warashi
Copy link
Member

@Warashi Warashi commented May 29, 2025

What this PR does:

  • fixed lint error about import groupings
  • fixed lint error about log.Fatal and defer
    • log.Fatal calls os.Exit, so the deferred functions are not called. instead of using log.Fatal, I use the log.Println, made func _main() int and called os.Exit(_main()) in the main.
    • for detail, please see the following commits
  • fixed lint error about simplicity

Why we need it:

  • To make lint success on local
  • To hardening codebase

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?: No

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Warashi added 8 commits May 29, 2025 14:07
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
log.Fatalf calls os.Exit(1) and deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
log.Fatal calls os.Exit, so the deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.
This is a workaround to fix the lint errors.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
@Warashi Warashi marked this pull request as ready for review May 29, 2025 05:46
@Warashi Warashi requested a review from a team as a code owner May 29, 2025 05:46
Copy link

codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 1.42857% with 69 lines in your changes missing coverage. Please review.

Project coverage is 27.88%. Comparing base (23b62f8) to head (d51b7bd).
Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
tool/actions-gh-release/main.go 0.00% 31 Missing ⚠️
tool/actions-plan-preview/main.go 0.00% 30 Missing ⚠️
tool/actions-gh-release/filematcher.go 0.00% 6 Missing ⚠️
tool/actions-gh-release/release.go 50.00% 1 Missing ⚠️
tool/codegen/protoc-gen-auth/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5897      +/-   ##
==========================================
- Coverage   27.89%   27.88%   -0.02%     
==========================================
  Files         519      519              
  Lines       55900    55923      +23     
==========================================
  Hits        15594    15594              
- Misses      39108    39131      +23     
  Partials     1198     1198              
Flag Coverage Δ
. 23.73% <ø> (ø)
.-pkg-app-pipedv1-plugin-example 0.00% <ø> (ø)
.-pkg-app-pipedv1-plugin-kubernetes 63.32% <ø> (ø)
.-pkg-app-pipedv1-plugin-kubernetes_multicluster 64.93% <ø> (ø)
.-pkg-app-pipedv1-plugin-wait 35.51% <ø> (ø)
.-pkg-plugin-sdk 49.25% <ø> (ø)
.-tool-actions-gh-release 19.23% <2.56%> (-0.36%) ⬇️
.-tool-actions-plan-preview 22.83% <0.00%> (-0.40%) ⬇️
.-tool-codegen-protoc-gen-auth 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -426,7 +426,7 @@ func renderReleaseNote(p ReleaseProposal, cfg ReleaseConfig) []byte {
}

for _, ctg := range cfg.CommitCategories {
commits := make([]ReleaseCommit, 0, 0)
commits := make([]ReleaseCommit, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
commits := make([]ReleaseCommit, 0)
commits := make([]ReleaseCommit, 0, len(filteredCommits))

nits

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. Fixed on this commit.
2465b2e

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
@@ -95,22 +103,28 @@ func main() {
body,
)
if err != nil {
log.Fatal(err)
log.Println(err)
return err
Copy link
Member

Choose a reason for hiding this comment

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

IMO, if this error is returned, and the caller prints again, it's redundant. If we don't have specific logic based on the error, then instead of returning the error, we should return the existing code. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm unsure about that.

Initially, I wrote as you said and thought it was not the standard go code to check whether the return value was zero.
Secondly, I wrote just return the error from the doComment, printed it on the caller side, and was a bit nervous about whether I had written all the logging.
Finally, I wrote logging in the doComment, returned an error, and didn't print it on the caller side.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for the clarification. Because I saw many places that perform "if error, then return 1, else return 0," I think it could be better to emit it as well. This means we logged the error and returned 0 and 1 from this doComment, and on the caller side, only returning doComment is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I try to do it again.

Copy link
Member Author

@Warashi Warashi May 29, 2025

Choose a reason for hiding this comment

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

I changed doComment to return int. I think it's simpler than before. Thank you.
7f14722

Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

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

Almost LGTM

Comment on lines 142 to 146
if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil {
return 1
}
log.Println(err)
return 1
Copy link
Member

Choose a reason for hiding this comment

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

This order?? err in doComment() is already printed in doComment(), and we want to print err of result, err := retrievePlanPreview( ??

(I'm not confident)

Suggested change
if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil {
return 1
}
log.Println(err)
return 1
log.Println(err)
if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil {
return 1
}
return 1

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I want to print err from retrievePlanPreview.
The behavior differs when the doComment fails, my code doesn't print retrievePlanPreview's error, and your code does.
the doComment's error is shadowing the retrievePlanPreview's error and scope is narrow, so log.Println correctly prints err from retrievePlanPreview.

But I think it's better to print err from retrievePlanPreview even if doComment fails, so I'll apply your suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed doComment to return int.
Additionally, this commit enables logging err from retrievePlanPreview without changing the order, and it's clear to read. I think it's enough. WDYT?

7f14722

Copy link
Member

Choose a reason for hiding this comment

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

Thank you! it seems good!

if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil {
return 1
}
log.Println(err)
Copy link
Member

Choose a reason for hiding this comment

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

same here

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
@Warashi Warashi requested review from khanhtc1202 and t-kikuc May 29, 2025 07:15
@t-kikuc t-kikuc enabled auto-merge (squash) May 29, 2025 08:20
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Look neat 👍

@t-kikuc t-kikuc merged commit 6f5d4d8 into master May 29, 2025
45 of 47 checks passed
@t-kikuc t-kikuc deleted the fix-lint-errors branch May 29, 2025 08:24
@github-actions github-actions bot mentioned this pull request Jun 2, 2025
github-actions bot pushed a commit that referenced this pull request Jun 2, 2025
* Fix import grouping by make lint/go FIX=true

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix linter errors by make lint/go FIX=true

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Rewrite long if-else to switch

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Remove unnecessary zero-value initialization

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Remove unnecessary string conversion

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix to correctly call deferred functions

log.Fatalf calls os.Exit(1) and deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix lint errors

log.Fatal calls os.Exit, so the deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.
This is a workaround to fix the lint errors.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix lint errors

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Initialize the slice with the correct capacity

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Change return type of doComment to int

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
Warashi added a commit that referenced this pull request Jun 2, 2025
* Fix lint errors (#5897)

* Fix import grouping by make lint/go FIX=true

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix linter errors by make lint/go FIX=true

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Rewrite long if-else to switch

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Remove unnecessary zero-value initialization

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Remove unnecessary string conversion

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix to correctly call deferred functions

log.Fatalf calls os.Exit(1) and deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix lint errors

log.Fatal calls os.Exit, so the deferred functions are not called.
This commit changes the _main function to return an integer and
call os.Exit from main.
This is a workaround to fix the lint errors.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Fix lint errors

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Initialize the slice with the correct capacity

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Change return type of doComment to int

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Add 'title' to distinguish multiple projects in actions-plan-preview (#5905)

* add title to args

Signed-off-by: t-kikuc <[email protected]>

* Add the title to filter latest comments

Signed-off-by: t-kikuc <[email protected]>

* Use hash

Signed-off-by: t-kikuc <[email protected]>

* Fix tests

Signed-off-by: t-kikuc <[email protected]>

* add multibyte test

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: t-kikuc <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Revert "Do treeless clone for git clone to improve performance (#5722)" (#5908)

This reverts commit 7e74937.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

* Cut release v0.52.1 (#5909)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Warashi <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
Signed-off-by: t-kikuc <[email protected]>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
Co-authored-by: Tetsuya KIKUCHI <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Warashi <[email protected]>
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.

3 participants