Skip to content

redundant-test-main-exit: allow flag.Parse() in TestMain#1599

Merged
alexandear merged 5 commits intomgechev:masterfrom
alexandear:fix/redundant-test-main-exit-flag-parse
Dec 5, 2025
Merged

redundant-test-main-exit: allow flag.Parse() in TestMain#1599
alexandear merged 5 commits intomgechev:masterfrom
alexandear:fix/redundant-test-main-exit-flag-parse

Conversation

@alexandear
Copy link
Copy Markdown
Collaborator

@alexandear alexandear commented Dec 4, 2025

I propose to skip functions from the package flag: flag.Parse, flag.NewFlagSet.

Fixes #1598.

Copy link
Copy Markdown
Contributor

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 addresses issue #1598 by modifying the redundant-test-main-exit rule to allow flag.Parse() calls in TestMain functions. The change recognizes that flag.Parse() is commonly used in TestMain to enable checking of test flags like testing.Short().

Key Changes

  • Added logic to skip flagging flag.Parse() calls as redundant in TestMain functions
  • Added a test case demonstrating the valid use of flag.Parse() with testing.Short() in TestMain

Reviewed changes

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

File Description
rule/redundant_test_main_exit.go Added check to skip all flag package calls before checking for exit functions
testdata/go1.15/redundant_test_main_exit_test.go Added test case showing flag.Parse() used with testing.Short() that should not be flagged

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

Comment thread rule/redundant_test_main_exit.go
Comment thread rule/redundant_test_main_exit.go Outdated
Comment thread testdata/go1.15/redundant_test_main_exit_test.go Outdated
alexandear and others added 2 commits December 4, 2025 04:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

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

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


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

Comment thread testdata/go1.15/redundant_test_main_exit_test.go Outdated
Copy link
Copy Markdown
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

OK for a quick fix, but I wonder if it could be better

Comment thread testdata/go1.15/redundant_test_main_exit_test.go Outdated
Comment thread rule/redundant_test_main_exit.go Outdated
@alexandear alexandear merged commit 50a36ac into mgechev:master Dec 5, 2025
10 checks passed
@alexandear alexandear deleted the fix/redundant-test-main-exit-flag-parse branch December 5, 2025 16:27
@alexandear alexandear mentioned this pull request Feb 10, 2026
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.

redundant-test-main-exit bad flag.Parse() advice

4 participants