1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-17 20:57:58 +02:00

modifies-value-receiver: warn on slice or map (#943)

* modifies-value-receiver: warn on slice or map

Assignments which index into the slice or map are already ignored on
line 72, and those where the whole receiver is slice or map on line 50.
We should not ignore assignments where the member variable is slice
or map.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Remove extra space

---------

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Denis Voytyuk <5462781+denisvmedia@users.noreply.github.com>
This commit is contained in:
Bryan Boreham 2023-11-28 14:45:52 +00:00 committed by GitHub
parent 2862d06d26
commit 7da6a39044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 5 deletions

View File

@ -78,11 +78,6 @@ func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor {
if name == "" || name != receiverName {
continue
}
if w.skipType(ast.Expr(e.Sel)) {
continue
}
case *ast.Ident: // receiver := ...
if e.Name != receiverName {
continue

View File

@ -9,5 +9,6 @@ type data struct {
func (this data) vmethod() {
this.num = 8 // MATCH /suspicious assignment to a by-value method receiver/
*this.key = "v.key"
this.items = make(map[string]bool) // MATCH /suspicious assignment to a by-value method receiver/
this.items["vmethod"] = true
}