Skip to content

Commit

Permalink
checkers: add io.WriteString patterns to preferFprint (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte committed Dec 31, 2021
1 parent 27e5601 commit b7720e1
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 299 deletions.
4 changes: 4 additions & 0 deletions checkers/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ func preferFprint(m dsl.Matcher) {
Where(m["w"].Type.Implements("io.Writer")).
Suggest("fmt.Fprintln($w, $args)").
Report(`fmt.Fprintln($w, $args) should be preferred to the $$`)

m.Match(`io.WriteString($w, fmt.Sprint($*args))`).Suggest(`fmt.Fprint($w, $args)`)
m.Match(`io.WriteString($w, fmt.Sprintf($*args))`).Suggest(`fmt.Fprintf($w, $args)`)
m.Match(`io.WriteString($w, fmt.Sprintln($*args))`).Suggest(`fmt.Fprintln($w, $args)`)
}

//doc:summary Detects suspicious duplicated arguments
Expand Down

0 comments on commit b7720e1

Please sign in to comment.