-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added go-mnd linter #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added go-mnd linter #842
Changes from all commits
2a08573
3577294
d3e5aa4
dbb8ec3
40a19ea
c7c2e19
061c111
073501b
64cc91c
23f4b25
98d1b1f
30f02f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package golinters | ||
|
||
import ( | ||
magic_numbers "github.com/tommy-muehle/go-mnd" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I would just alias this as |
||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewGomnd() *goanalysis.Linter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Similarly, I would name this |
||
analyzers := []*analysis.Analyzer{ | ||
magic_numbers.Analyzer, | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
"gomnd", | ||
"checks whether magic number is used", | ||
analyzers, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeSyntax) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//args: -Egomnd | ||
package testdata | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func UseMagicNumber() { | ||
c := &http.Client{ | ||
Timeout: 1 * time.Second, // ERROR : "Magic number: 1, in <assign> detected" | ||
} | ||
|
||
res, err := c.Get("http://www.google.com") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if res.StatusCode != 200 { // ERROR : "Magic number: 200, in <condition> detected" | ||
log.Println("Something went wrong") | ||
} | ||
} | ||
|
||
func UseNoMagicNumber() { | ||
c := &http.Client{ | ||
Timeout: time.Second, | ||
} | ||
|
||
res, err := c.Get("http://www.google.com") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if res.StatusCode != http.StatusOK { | ||
log.Println("Something went wrong") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this to reference a tagged release version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried before, but it gives me the below error (even the tag is available)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I got it now, the tag in github.com/tommy-muehle/go-mnd is not prefixed with
v
, so we can only use pseudo-versions onlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raised one issue here tommy-muehle/go-mnd#1