Commit 64804da
go/analysis/passes/modernize: slicescontains: omit fix with empty body
In the slicescontains modernizer, if the inspected RangeStmt's
child IfStmt contains an unlabeled break statement, the fix will
remove it. If the IfStmt contains only the break and no other
statements, the resulting fix will have a call to
"if slices.Contains(...) {}" with an empty body.
This code is confusing and produces a linter error,
so we should avoid suggesting a fix.
Fixes golang/go#77677
Change-Id: I7c0368678b9034aa698febca2acf20c0071e29c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/749160
TryBot-Bypass: Madeline Kalil <mkalil@google.com>
Auto-Submit: Madeline Kalil <mkalil@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>1 parent da12812 commit 64804da
File tree
3 files changed
+28
-1
lines changed- go/analysis/passes/modernize
- testdata/src/slicescontains
3 files changed
+28
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
234 | 235 | | |
| 236 | + | |
235 | 237 | | |
236 | 238 | | |
237 | 239 | | |
| |||
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
295 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
296 | 307 | | |
297 | 308 | | |
298 | 309 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
0 commit comments