Skip to content

feat: implement graceful-teardown checker#305

Open
mmorel-35 wants to merge 3 commits into
Antonboom:masterfrom
mmorel-35:graceful-teardown
Open

feat: implement graceful-teardown checker#305
mmorel-35 wants to merge 3 commits into
Antonboom:masterfrom
mmorel-35:graceful-teardown

Conversation

@mmorel-35

Copy link
Copy Markdown
Contributor

Implements the graceful-teardown checker proposed in CONTRIBUTING.md. Using require in t.Cleanup callbacks or suite teardown methods calls runtime.Goexit(), which aborts the goroutine mid-cleanup and can leave resources unreleased.

Checker

Detects require.* calls (including s.Require().Method()) inside:

  • t.Cleanup(func() { ... })
  • Suite teardown methods: TearDownTest, TearDownSuite, AfterTest, HandleStats, TearDownSubTest
// ❌ detected
func (s *Suite) TearDownTest() {
    s.Require().NoError(s.producer.Close()) // goroutine exits here; consumer never closed
    s.Require().NoError(s.consumer.Close())
}

t.Cleanup(func() {
    require.NoError(t, db.Close())
})

// ✅ fixed
func (s *Suite) TearDownTest() {
    s.Assert().NoError(s.producer.Close())
    s.Assert().NoError(s.consumer.Close())
}

t.Cleanup(func() {
    assert.NoError(t, db.Close())
})

Autofix

Two fix strategies:

Pattern Fix
require.X(t, ...) Replace require qualifier with assert; add assert import if absent (via addImportFix)
s.Require().X(...) Replace Require() with Assert() in the method chain

The addImportFix helper (ported from the http-const branch) handles existing imports, aliases, name conflicts with top-level declarations, and insertion into the correct import group.

Configuration

  • Enabled by default: false
  • Autofix: true

Test coverage

  • Generated test + golden file for the main cases (both packages already imported)
  • Manual graceful-teardown-no-import test verifying the autofix correctly inserts the assert import when the file only imports require

Closes #142

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@mmorel-35 mmorel-35 force-pushed the graceful-teardown branch from 5a0c1cc to 8f87040 Compare April 9, 2026 18:24
Copilot AI added a commit to mmorel-35/testifylint that referenced this pull request May 28, 2026
mmorel-35 pushed a commit to mmorel-35/testifylint that referenced this pull request May 28, 2026
@Antonboom Antonboom added the llm-based LLM shit label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-based LLM shit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graceful-teardown: warns about usage of require in t.Cleanup functions and suite teardown methods

2 participants