Skip to content

Releases: mpyw/gormreuse

v0.13.2

27 Dec 07:51
8f5f055

Choose a tag to compare

Documentation Updates

This release contains documentation improvements across the codebase:

Changes

  • Expanded purity package documentation (internal/ssa/purity/validator.go)

    • Added detailed Pure Contract explanation
    • Documented SSA-based derivation tracking analysis strategy
    • Clarified what pure functions CAN do
  • Improved doc comment accuracy (analyzer.go)

    • Fixed Session() placement explanation (now correctly shows .Session() at end of chain)
    • Added //gormreuse:immutable-return to supported directives list
  • README cleanup

    • Removed retracted versions warning (handled by go.mod retract directive)

Full Changelog

v0.13.1...v0.13.2

v0.13.1

27 Dec 07:40
e758213

Choose a tag to compare

What's Changed

Bug Fixes

  • Fix incorrect unused directive detection logic (#51, #52)

    • //gormreuse:pure and //gormreuse:immutable-return were incorrectly reported as unused
    • Changed detection from "was consulted during analysis" to "does the function have a valid signature"
    • //gormreuse:pure is now unused only if function has NO *gorm.DB in parameters
    • //gormreuse:immutable-return is now unused only if function has NO *gorm.DB in return values
  • Treat interface types as potentially containing *gorm.DB

    • interface{} parameters/returns are now valid for directives (can hold *gorm.DB at runtime)
  • Also check for gorm.DB (non-pointer) type

    • gorm.DB by value is also dangerous because it contains *Statement which is shared when copied

Improvements

  • Improve pointer chain detection in closure captures
    • Recursively unwrap **gorm.DB, ***gorm.DB, etc. in ClosureCapturesGormDB
    • Add containsGormDBThroughPointers() for consistent pointer chain handling

Refactoring

  • Extract signature validation to separate file (signature.go)
  • Add comprehensive tests for type checking (generic types, containers, cycle detection)

Retracted Versions

  • v0.13.0 is retracted due to incorrect unused directive detection logic

Design Summary

Function Purpose Pointer Chain interface{} struct fields
typeutil.IsGormDB SSA analysis 1 level only
containsGormDBThroughPointers Closure capture Recursive
containsGormDB Directive validation Recursive

Full Changelog: v0.13.0...v0.13.1

v0.13.0

27 Dec 06:02
5cddb83

Choose a tag to compare

What's Changed

New Features

  • Support //gormreuse:pure and //gormreuse:immutable-return directives on closures (#48)
  • Detect unused //gormreuse:pure and //gormreuse:immutable-return directives (#49)

Bug Fixes

  • Optimize hasCodeBeforeComment to avoid timeout on large files (#50)

Performance Improvements

  • Use inspector.Preorder for faster AST traversal (~40% improvement)
  • Cache ast/inspector.Inspector per file to avoid recreation
  • Cache fix.Generator across violations in the same analysis run
  • Add t.Parallel for faster test execution

Full Changelog: v0.12.0...v0.13.0

v0.12.0

26 Dec 07:09
fecfe09

Choose a tag to compare

What's Changed

Bug Fixes

  • Fix false positives for single-return closure + method chain in loop patterns (#45)
  • Add global edit deduplication to prevent duplicate Session() in suggested fixes

Tests

  • Add comprehensive test files for closure loop patterns (closure_loop.go)
  • Add comprehensive test files for interface conversion behaviors (interface_patterns.go)

Full Changelog: v0.11.6...v0.12.0

v0.11.6

26 Dec 04:29
9ac3569

Choose a tag to compare

What's Changed

Documentation

  • docs: update CLAUDE.md for user-defined function reassignment behavior

Updated internal documentation to reflect the new behavior where user-defined functions that return *gorm.DB with the result being assigned are treated like gorm method assignments (no pollution).

Full Changelog: v0.11.5...v0.11.6

v0.11.5

26 Dec 04:24
55ad18b

Choose a tag to compare

What's Changed

Bug Fixes

  • fix: resolve false positive for user-defined function reassignment pattern (#44)

When a user-defined function receives *gorm.DB as argument and returns *gorm.DB with the result being assigned (e.g., q = buildQuery(q, "filter")), treat it like a gorm method assignment instead of marking the argument as polluted.

This enables the common builder pattern:

q := db.Where("base")
if condition1 {
    q = buildAlertQuery(q, types)  // No longer false positive
}
if condition2 {
    q = buildVersionStatusQuery(q, status)  // No longer false positive
}
q.Find(nil)  // OK - first actual use

Full Changelog: v0.11.4...v0.11.5

v0.11.4

26 Dec 03:42
fe77507

Choose a tag to compare

Bug Fixes

  • fix: add FindAllMutableRoots for Phi receiver tracing in bound/go/defer (#43)

    • Add FindAllMutableRoots to trace all possible mutable roots from Phi nodes
    • Process go statements in second pass to handle SSA block ordering
    • Add tests for Phi receiver scenarios with one polluted branch
  • fix: resolve false positive for chained method calls in switch cases (#41)

Full Changelog

v0.11.3...v0.11.4

v0.11.3

26 Dec 01:54
a86a0bc

Choose a tag to compare

Bug Fixes

  • Fix Session edit position to target innermost CallExpr instead of outermost
    • Prevents Session being incorrectly added to wrapper functions like t.Run() or Transaction()
    • Session now correctly added to the actual *gorm.DB method call
  • Add gorm import automatically when Session fix requires it
    • Handles both single imports (import "pkg") and grouped imports (import (...))

v0.11.2

25 Dec 23:21
96975e9

Choose a tag to compare

Changes

Code Cleanup & Refactoring

  • Unified PureFuncSet and ImmutableReturnFuncSet into generic DirectiveFuncSet (-185 lines)
  • Trimmed excessive documentation in handler/call.go while preserving concrete examples (-880 lines)
  • Removed unused analyzedFn field from pollution.Tracker (-6 lines)
  • Renamed PureFuncKey to FuncKey for consistency

Results

  • Net reduction: ~1000 lines of code
  • Coverage: maintained at ~89%
  • All tests passing

Full Changelog: v0.11.1...v0.11.2

v0.11.1

25 Dec 22:42
1653a57

Choose a tag to compare

What's Changed

Code Quality Improvements

  • Reduce code duplication and improve maintainability (-162 lines)
  • Extract common patterns into reusable helper functions
  • Coverage improved from 88.8% to 89.4%

Changes

  • handler/call.go: Unified Go/Defer handlers with processGormDBCallCommonWith
  • pollution/tracker.go: Unified violation detection loops with checkViolationsBetween
  • tracer/root.go: Unified swap-phi detection with isLoopVariableSwap

Full Changelog: v0.11.0...v0.11.1