mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.73k stars 276 forks source link

False positive in `unconditional-recursion` in presence of func literals #902

Closed chavacava closed 10 months ago

chavacava commented 11 months ago

Describe the bug The rule unconditional-recursion produces false positives when it finds calls to foo in function literals defined inside foo. For example:

func (c *connector) SpanStats(ctx context.Context, req *roachpb.SpanStatsRequest) (*roachpb.SpanStatsResponse, error) {
        // ... 
        err := c.withClient(ctx, func(ctx context.Context, c *client) error {
                stats, err := c.SpanStats(ctx, req)  // <- this call is wrongly flagged as unconditional recusive
               // ...
                return nil
        })
        return response, err
}

To Reproduce Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. Include the following code in testdata/unconditional-recursion.go
    func falsePositiveFuncLiteral() {
        _ = foo(func() {
                falsePositiveFuncLiteral()
        })
    }
  3. run make test (test will fail for unconditional-recursion rule)

Expected behavior The new test pass.

mfederowicz commented 11 months ago

@chavacava to be clear what is to fix content of unconditional-recursion.go, or writing new test which asserts other testcases than actual one, or maybe both?

chavacava commented 11 months ago

The goal is to add the new test and fix the rule implementation to make tests pass.

mfederowicz commented 11 months ago

@chavacava we waiting for something more in this issue, other tests or something?

chavacava commented 10 months ago

Closed by #909