Skip to content

Commit

Permalink
modifies-value-receiver: warn on slice or map (#943)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
bboreham and denisvmedia authored Nov 28, 2023
1 parent 2862d06 commit 7da6a39
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
5 changes: 0 additions & 5 deletions rule/modifies-value-receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testdata/modifies-value-receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7da6a39

Please # to comment.