Skip to content
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

Merged
merged 1 commit into from Mar 18, 2020
Merged

Conversation

quasilyte
Copy link
Member

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

@quasilyte
Copy link
Member Author

I'm going to add tests as well.

@quasilyte quasilyte force-pushed the quasilyte/addChecker/ruleguard branch from ffa1ccb to 0d01422 Compare March 18, 2020 21:01
@quasilyte
Copy link
Member Author

Done. Now we have integration tests for ruleguard.

cristaloleg
cristaloleg previously approved these changes Mar 18, 2020
Usage: "path to a gorules file",
},
}
info.Summary = "Detects custom rules violations"
Copy link
Member

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

func (c *ruleguardChecker) WalkFile(f *ast.File) {
// Rule set is nil if no rules were loaded from a rules file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted.

return c
}

// We can handle initialization errors easier when we make
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

fset := token.NewFileSet()
rset, err := ruleguard.ParseRules(rulesFilename, fset, bytes.NewReader(data))
if err != nil {
log.Printf("init ruleguard: %v", err)
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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

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>
@quasilyte quasilyte force-pushed the quasilyte/addChecker/ruleguard branch from dd33c1c to f09aa99 Compare March 18, 2020 21:30
@quasilyte quasilyte merged commit 8c5f841 into master Mar 18, 2020
@quasilyte quasilyte deleted the quasilyte/addChecker/ruleguard branch March 18, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants