mgechev / revive

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

fix: literal calls case #909

Closed mfederowicz closed 9 months ago

mfederowicz commented 9 months ago

related with issue #902

fix is simple, we should add case *ast.FuncLit in rule: rule/unconditional-recursion.go , and return nil, then test pass.

but at the end I dont know if I should add some additional code as in previous cases for ex: w.updateFuncStatus(n.Body) but if test pass it should be ok :P

chavacava commented 9 months ago

Hi @mfederowicz, thanks for the PR. I added a new test case:

func nr902() {
    go func() {
        nr902() // MATCH /unconditional recursive call/
    }()
}

In this case, the function literal contains an actual unconditional recursive call and the rule should spot it. To cope with this case, and still avoid false positives as the initial case of this issue, the rule should skip analyzing func literals used as function call arguments.

mfederowicz commented 9 months ago

ok @chavacava with that last one test was a problem with checking line number in: if p.Position.Start.Line != in.Line { statement and signature used to identifate current function:

w.currentFunc = &funcStatus{&funcDesc{rec, n.Name}, false}

after some tweaks, all tests passes

of course you can propose other solution, maye my changes were not optimal :P

FYI: I made cleanup in commits (rebase on branch), so please git pull on your copy