Skip to content

Commit

Permalink
Ignore also float representations of 1 and 0, fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-muehle committed Jan 22, 2021
1 parent eff5d0e commit 9a7adaf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func DefaultConfig() *Config {
return &Config{
Checks: map[string]bool{},
IgnoredNumbers: map[string]struct{}{
"0": {},
"1": {},
"0": {},
"0.0": {},
"1": {},
"1.0": {},
},
IgnoredFiles: []*regexp.Regexp{
regexp.MustCompile(`_test.go`),
Expand Down
10 changes: 10 additions & 0 deletions testdata/src/case/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ func example2() {
fmt.Println("Good evening.")
}
}

func example3() {
var x interface{}

switch x {
case 1.0:
case 0.0:
case 3.0: // want "Magic number: 3.0"
}
}
10 changes: 10 additions & 0 deletions testdata/src/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ func example() {
if "test" == y {
}
}

func example2() {
var x float32

if x > 1.0 {
}

if x < 0.0 {
}
}
6 changes: 6 additions & 0 deletions testdata/src/operation/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ func example6() {
// ...
}
}

func example7() {
var x float32
if 10 < (x * 1.0) { // want "Magic number: 10"
}
}
12 changes: 12 additions & 0 deletions testdata/src/return/return.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ func example6(x int32) int32 {
func example7(x int32) int32 {
return (42 * x) + 10 // want "Magic number: 42" "Magic number: 10"
}

func example8() float32 {
return 0.0
}

func example9() float32 {
return 1.0
}

func example10() float32 {
return 3.0 // want "Magic number: 3.0"
}

0 comments on commit 9a7adaf

Please sign in to comment.