-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds tests for specific go versions (#1043)
Co-authored-by: chavacava <[email protected]>
- Loading branch information
Showing
15 changed files
with
341 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/mgechev/revive/testdata | ||
|
||
// set the lowest go version | ||
// to trigger testing of all rules | ||
go 1.0 |
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,3 @@ | ||
module github.com/mgechev/revive/testdata | ||
|
||
go 1.21 |
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,54 @@ | ||
package fixtures | ||
|
||
func (this data) vmethod() { | ||
nil := true // MATCH /assignment creates a shadow of built-in identifier nil/ | ||
iota = 1 // MATCH /assignment modifies built-in identifier iota/ | ||
} | ||
|
||
func append(i, j int) { // MATCH /redefinition of the built-in function append/ | ||
|
||
} | ||
|
||
type string int16 // MATCH /redefinition of the built-in type string/ | ||
|
||
func delete(set []int64, i int) (y []int64) { // MATCH /redefinition of the built-in function delete/ | ||
for j, v := range set { | ||
if j != i { | ||
y = append(y, v) | ||
} | ||
} | ||
return | ||
} | ||
|
||
type any int // MATCH /redefinition of the built-in type any/ | ||
|
||
func any() {} // MATCH /redefinition of the built-in type any/ | ||
|
||
var any int // MATCH /redefinition of the built-in type any/ | ||
|
||
const any = 1 // MATCH /redefinition of the built-in type any/ | ||
|
||
var i, copy int // MATCH /redefinition of the built-in function copy/ | ||
|
||
// issue #792 | ||
type () | ||
|
||
func foo() { | ||
clear := 0 // MATCH /redefinition of the built-in function clear/ | ||
max := 0 // MATCH /redefinition of the built-in function max/ | ||
min := 0 // MATCH /redefinition of the built-in function min/ | ||
_ = clear | ||
_ = max | ||
_ = min | ||
} | ||
|
||
func foo1(new int) { // MATCH /redefinition of the built-in function new/ | ||
_ = new | ||
} | ||
|
||
func foo2() (new int) { // MATCH /redefinition of the built-in function new/ | ||
return | ||
} | ||
|
||
func foo3[new any]() { // MATCH /redefinition of the built-in function new/ | ||
} |
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,30 @@ | ||
package fixtures | ||
|
||
func datarace() (r int, c char) { | ||
for _, p := range []int{1, 2} { | ||
go func() { | ||
print(r) // MATCH /potential datarace: return value r is captured (by-reference) in goroutine/ | ||
print(p) // Shall not match /datarace: range value p is captured (by-reference) in goroutine/ | ||
}() | ||
for i, p1 := range []int{1, 2} { | ||
a := p1 | ||
go func() { | ||
print(r) // MATCH /potential datarace: return value r is captured (by-reference) in goroutine/ | ||
print(p) // Shall not match /datarace: range value p is captured (by-reference) in goroutine/ | ||
print(p1) // Shall not match /datarace: range value p1 is captured (by-reference) in goroutine/ | ||
print(a) | ||
print(i) // Shall not match /datarace: range value i is captured (by-reference) in goroutine/ | ||
}() | ||
print(i) | ||
print(p) | ||
go func() { | ||
_ = c // MATCH /potential datarace: return value c is captured (by-reference) in goroutine/ | ||
}() | ||
} | ||
print(p1) | ||
} | ||
go func() { | ||
print(r) // MATCH /potential datarace: return value r is captured (by-reference) in goroutine/ | ||
}() | ||
print(r) | ||
} |
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,3 @@ | ||
module github.com/mgechev/revive/testdata | ||
|
||
go 1.22 |
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,163 @@ | ||
package fixtures | ||
|
||
func rangeValAddress() { | ||
m := map[string]*string{} | ||
|
||
mySlice := []string{"A", "B", "C"} | ||
for _, value := range mySlice { | ||
m["address"] = &value // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress2() { | ||
m := map[string]*string{} | ||
|
||
mySlice := []string{"A", "B", "C"} | ||
for i := range mySlice { | ||
m["address"] = &mySlice[i] | ||
} | ||
} | ||
|
||
func rangeValAddress3() { | ||
m := map[string]*string{} | ||
|
||
mySlice := []string{"A", "B", "C"} | ||
for _, value := range mySlice { | ||
a := &value // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
m["address"] = a | ||
} | ||
} | ||
|
||
func rangeValAddress4() { | ||
m := []*string{} | ||
|
||
mySlice := []string{"A", "B", "C"} | ||
for _, value := range mySlice { | ||
m = append(m, &value) // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress5() { | ||
m := map[*string]string{} | ||
|
||
mySlice := []string{"A", "B", "C"} | ||
for _, value := range mySlice { | ||
m[&value] = value // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress6() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
mySlice := []v{{id: "A"}, {id: "B"}, {id: "C"}} | ||
for _, value := range mySlice { | ||
m = append(m, &value.id) // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress7() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
for _, value := range []v{{id: "A"}, {id: "B"}, {id: "C"}} { | ||
m = append(m, &value.id) // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress8() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
mySlice := []*v{{id: "A"}, {id: "B"}, {id: "C"}} | ||
for _, value := range mySlice { | ||
m = append(m, &value.id) | ||
} | ||
} | ||
|
||
func rangeValAddress9() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
mySlice := map[string]*v{"a": {id: "A"}, "b": {id: "B"}, "c": {id: "C"}} | ||
for _, value := range mySlice { | ||
m = append(m, &value.id) | ||
} | ||
} | ||
|
||
func rangeValAddress10() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
for _, value := range map[string]*v{"a": {id: "A"}, "b": {id: "B"}, "c": {id: "C"}} { | ||
m = append(m, &value.id) | ||
} | ||
} | ||
|
||
func rangeValAddress11() { | ||
type v struct { | ||
id string | ||
} | ||
m := map[string]*string{} | ||
|
||
for key, value := range map[string]*v{"a": {id: "A"}, "b": {id: "B"}, "c": {id: "C"}} { | ||
m[key] = &value.id | ||
} | ||
} | ||
|
||
func rangeValAddress12() { | ||
type v struct { | ||
id string | ||
} | ||
m := map[string]*string{} | ||
|
||
for key, value := range map[string]v{"a": {id: "A"}, "b": {id: "B"}, "c": {id: "C"}} { | ||
m[key] = &value.id // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} | ||
|
||
func rangeValAddress13() { | ||
type v struct { | ||
id string | ||
} | ||
m := []*string{} | ||
|
||
otherSlice := map[string]*v{"a": {id: "A"}, "b": {id: "B"}, "c": {id: "C"}} | ||
mySlice := otherSlice | ||
for _, value := range mySlice { | ||
m = append(m, &value.id) | ||
} | ||
} | ||
|
||
func rangeValAddress14() { | ||
type v struct { | ||
id *string | ||
} | ||
|
||
m := []v{} | ||
for _, value := range []string{"A", "B", "C"} { | ||
a := v{id: &value} // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
m = append(m, a) | ||
} | ||
} | ||
|
||
func rangeValAddress15() { | ||
type v struct { | ||
id *string | ||
} | ||
|
||
m := []v{} | ||
for _, value := range []string{"A", "B", "C"} { | ||
m = append(m, v{id: &value}) // Shall not match /suspicious assignment of 'value'. range-loop variables always have the same address/ | ||
} | ||
} |
Oops, something went wrong.