Skip to content

Implement elements-match checker - #303

Open
mmorel-35 wants to merge 6 commits into
Antonboom:masterfrom
mmorel-35:elements-match
Open

Implement elements-match checker#303
mmorel-35 wants to merge 6 commits into
Antonboom:masterfrom
mmorel-35:elements-match

Conversation

@mmorel-35

Copy link
Copy Markdown
Contributor

Adds the elements-match checker from the CONTRIBUTING.md open-for-contribution list, which detects verbose slice comparison patterns that should use assert.ElementsMatch.

What it detects

// ❌ Verbose: sort both slices, then compare
slices.Sort(expected)
slices.Sort(result)
assert.True(t, slices.Equal(expected, result))

// ✅ Use the testify idiom
assert.ElementsMatch(t, expected, result)

Changes

  • internal/checkers/elements_match.goAdvancedChecker that walks ast.BlockStmt nodes looking for the 3-statement triplet slices.Sort(x) + slices.Sort(y) + assert.True(t, slices.Equal(x, y)). Handles commuted sort order and both slices (Go 1.21) and golang.org/x/exp/slices. Includes a full autofix that removes the two sort statements and rewrites the assertion.
  • internal/testgen/gen_elements_match.go — Test generator with errored and golden templates.
  • Registry — Registered as disabled by default (matching the "maybe" stability note in CONTRIBUTING.md).
  • README.md — Added to the checkers table and reference section.
  • CONTRIBUTING.md — Removed from the open-for-contribution list.

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@ccoVeille

Copy link
Copy Markdown
Contributor

I had no idea ElementsMatch existed 😱😅🤣

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
mmorel-35 added 2 commits May 29, 2026 12:55
Removed elements-match section from CONTRIBUTING.md to simplify the document.
…sort.Slice`

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@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.

3 participants