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
checkers: add ruleguard checker #907
Conversation
79280cb
to
ffa1ccb
Compare
I'm going to add tests as well. |
ffa1ccb
to
0d01422
Compare
Done. Now we have integration tests for ruleguard. |
checkers/ruleguard_checker.go
Outdated
Usage: "path to a gorules file", | ||
}, | ||
} | ||
info.Summary = "Detects custom rules violations" |
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.
Sounds depressive. Allows users to define custom rules
, WDYT ?
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.
Fixed.
checkers/ruleguard_checker.go
Outdated
} | ||
|
||
func (c *ruleguardChecker) WalkFile(f *ast.File) { | ||
// Rule set is nil if no rules were loaded from a rules file. |
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.
do we need this? :)
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.
Deleted.
checkers/ruleguard_checker.go
Outdated
return c | ||
} | ||
|
||
// We can handle initialization errors easier when we make |
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.
// TODO ?
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.
Fixed.
checkers/ruleguard_checker.go
Outdated
fset := token.NewFileSet() | ||
rset, err := ruleguard.ParseRules(rulesFilename, fset, bytes.NewReader(data)) | ||
if err != nil { | ||
log.Printf("init ruleguard: %v", err) |
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.
what about: ruleguard init error: %#v
? it's a bit easier to grep then.
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.
Fixed.
Sizes: c.ctx.SizesInfo, | ||
Fset: c.ctx.FileSet, | ||
Report: func(n ast.Node, msg string, _ *ruleguard.Suggestion) { | ||
// TODO(quasilyte): investigate whether we should add a rule name as |
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.
imo - yes :) but it's a minor one
0d01422
to
dd33c1c
Compare
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
dd33c1c
to
f09aa99
Compare
This is part of the ruleguard integration experiment.
Hopefully, we can get some feedback to improve the way it's integrated.
The simplest way to try it out:
Where:
An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go
Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard.
Updates #873
Updates #869
Updates #837
Updates #836
Updates #831
Signed-off-by: Iskander Sharipov quasilyte@gmail.com