-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/analysis: add skipped analysis simplify on generated code
On generated code, gopls always suggest to simplify code produced literals polluting the "Problems" pane in IDE, while properly refusing to format file on save because it is generated code. This change will make simplifycompositelit, simplifyrange, simplifyslice skipped on generated code, so it will not polluting the "Problems" pane in IDE. Fixes golang/go#67733 Change-Id: I99b3f083ce96594f360576f530cfc7f4b77c1cc1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/598835 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
Showing
18 changed files
with
298 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
gopls/internal/analysis/simplifycompositelit/testdata/src/generatedcode/generatedcode.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...internal/analysis/simplifycompositelit/testdata/src/generatedcode/generatedcode.go.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Code generated with somegen DO NOT EDIT. | ||
|
||
package testdata | ||
|
||
type T struct { | ||
x, y int | ||
} | ||
|
||
var _ = [42]T{ | ||
T{}, // No simplification fix is offered in generated code. | ||
T{1, 2}, // No simplification fix is offered in generated code. | ||
T{3, 4}, // No simplification fix is offered in generated code. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
gopls/internal/analysis/simplifyrange/testdata/src/generatedcode/generatedcode.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
gopls/internal/analysis/simplifyrange/testdata/src/generatedcode/generatedcode.go.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Code generated with somegen DO NOT EDIT. | ||
|
||
package testdata | ||
|
||
import "log" | ||
|
||
func mgeneratedcode() { | ||
maps := make(map[string]string) | ||
for k, _ := range maps { // No simplification fix is offered in generated code. | ||
log.Println(k) | ||
} | ||
for _ = range maps { // No simplification fix is offered in generated code. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
gopls/internal/analysis/simplifyslice/testdata/src/generatedcode/generatedcode.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
gopls/internal/analysis/simplifyslice/testdata/src/generatedcode/generatedcode.go.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Code generated with somegen DO NOT EDIT. | ||
|
||
package testdata | ||
|
||
var ( | ||
a [10]byte | ||
b [20]float32 | ||
s []int | ||
t struct { | ||
s []byte | ||
} | ||
|
||
_ = a[0:] | ||
_ = a[1:10] | ||
_ = a[2:len(a)] // No simplification fix is offered in generated code. | ||
_ = a[3:(len(a))] | ||
_ = a[len(a)-1 : len(a)] // No simplification fix is offered in generated code. | ||
_ = a[2:len(a):len(a)] | ||
|
||
_ = a[:] | ||
_ = a[:10] | ||
_ = a[:len(a)] // No simplification fix is offered in generated code. | ||
_ = a[:(len(a))] | ||
_ = a[:len(a)-1] | ||
_ = a[:len(a):len(a)] | ||
|
||
_ = s[0:] | ||
_ = s[1:10] | ||
_ = s[2:len(s)] // No simplification fix is offered in generated code. | ||
_ = s[3:(len(s))] | ||
_ = s[len(a) : len(s)-1] | ||
_ = s[0:len(b)] | ||
_ = s[2:len(s):len(s)] | ||
|
||
_ = s[:] | ||
_ = s[:10] | ||
_ = s[:len(s)] // No simplification fix is offered in generated code. | ||
_ = s[:(len(s))] | ||
_ = s[:len(s)-1] | ||
_ = s[:len(b)] | ||
_ = s[:len(s):len(s)] | ||
|
||
_ = t.s[0:] | ||
_ = t.s[1:10] | ||
_ = t.s[2:len(t.s)] | ||
_ = t.s[3:(len(t.s))] | ||
_ = t.s[len(a) : len(t.s)-1] | ||
_ = t.s[0:len(b)] | ||
_ = t.s[2:len(t.s):len(t.s)] | ||
|
||
_ = t.s[:] | ||
_ = t.s[:10] | ||
_ = t.s[:len(t.s)] | ||
_ = t.s[:(len(t.s))] | ||
_ = t.s[:len(t.s)-1] | ||
_ = t.s[:len(b)] | ||
_ = t.s[:len(t.s):len(t.s)] | ||
) | ||
|
||
func _() { | ||
s := s[0:len(s)] // No simplification fix is offered in generated code. | ||
_ = s | ||
} | ||
|
||
func m() { | ||
maps := []int{} | ||
_ = maps[1:len(maps)] // No simplification fix is offered in generated code. | ||
} |
Oops, something went wrong.