|
| 1 | +package fixtures |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | +) |
| 8 | + |
| 9 | +type testLogger struct{} |
| 10 | + |
| 11 | +func (l *testLogger) Info(ctx context.Context, msg string) {} |
| 12 | + |
| 13 | +func getLogger() *testLogger { |
| 14 | + return &testLogger{} |
| 15 | +} |
| 16 | + |
| 17 | +func test1007() { |
| 18 | + getLogger().Info(context.Background(), "test1007") |
| 19 | + getLogger().Info(context.Background(), "test1007") |
| 20 | + getLogger().Info(context.Background(), "test1007") |
| 21 | +} |
| 22 | + |
| 23 | +func foo(a float32, b string, c any, d int) { |
| 24 | + a = 1.0 // ignore |
| 25 | + b = "ignore" |
| 26 | + c = 2 // ignore |
| 27 | + println("lit", 12) // MATCH /avoid magic numbers like '12', create a named constant for it/ |
| 28 | + if a == 12.50 { // MATCH /avoid magic numbers like '12.50', create a named constant for it/ |
| 29 | + if b == "lit" { |
| 30 | + c = "lit" // MATCH /string literal "lit" appears, at least, 3 times, create a named constant for it/ |
| 31 | + } |
| 32 | + for i := 0; i < 1; i++ { |
| 33 | + println("lit") |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + println(0666) // MATCH /avoid magic numbers like '0666', create a named constant for it/ |
| 38 | + os.Chmod("test", 0666) // ignore |
| 39 | + os.FindProcess(102100) // ignore |
| 40 | + fmt.Println("test", 12) // ignore |
| 41 | + fmt.Printf("%d", 100) // MATCH /avoid magic numbers like '100', create a named constant for it/ |
| 42 | + myPrintln("%d", 100) // MATCH /avoid magic numbers like '100', create a named constant for it/ |
| 43 | + ignoredFunc(1000) // ignore |
| 44 | + ignoredFunc1(1000) // ignore - match regexp too |
| 45 | + |
| 46 | + println("The result of calling myFunc is: ", ignoredFunc(100)) // ignore |
| 47 | + println("result is: ", ignoredFunc(notIgnoredFunc(ignoredFunc(100)))) // ignore |
| 48 | + println("result of calling myFunc is: ", notIgnoredFunc(ignoredFunc(100))) // ignore |
| 49 | + |
| 50 | + println("result myFunc is: ", notIgnoredFunc(100)) // MATCH /avoid magic numbers like '100', create a named constant for it/ |
| 51 | + println("The result is: ", ignoredFunc(notIgnoredFunc(100))) // MATCH /avoid magic numbers like '100', create a named constant for it/ |
| 52 | +} |
| 53 | + |
| 54 | +func myPrintln(s string, num int) { |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +func ignoredFunc1(num int) int { |
| 59 | + return num |
| 60 | +} |
| 61 | + |
| 62 | +func ignoredFunc(num int) int { |
| 63 | + return num |
| 64 | +} |
| 65 | + |
| 66 | +func notIgnoredFunc(num int) int { |
| 67 | + return num |
| 68 | +} |
| 69 | + |
| 70 | +func tagsInStructLiteralsShouldBeOK() { |
| 71 | + a := struct { |
| 72 | + X int `json:"x"` |
| 73 | + }{} |
| 74 | + |
| 75 | + b := struct { |
| 76 | + X int `json:"x"` |
| 77 | + }{} |
| 78 | + |
| 79 | + c := struct { |
| 80 | + X int `json:"x"` |
| 81 | + }{} |
| 82 | + |
| 83 | + d := struct { |
| 84 | + X int `json:"x"` |
| 85 | + Y int `json:"y"` |
| 86 | + }{} |
| 87 | + |
| 88 | + e := struct { |
| 89 | + X int `json:"x"` |
| 90 | + Y int `json:"y"` |
| 91 | + }{} |
| 92 | + |
| 93 | + var f struct { |
| 94 | + X int `json:"x"` |
| 95 | + Y int `json:"y"` |
| 96 | + } |
| 97 | + |
| 98 | + var g struct { |
| 99 | + X int `json:"x"` |
| 100 | + Y int `json:"y"` |
| 101 | + } |
| 102 | + |
| 103 | + _, _, _, _, _, _, _ = a, b, c, d, e, f, g |
| 104 | +} |
0 commit comments