-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
gocritic: add support for variable substitution in ruleguard path settings #2308
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
550fdca
Add variable for ruleguard config directory
sebastien-rosset f7ed298
Add variable for ruleguard config directory
sebastien-rosset 1d990d9
Add variable for ruleguard config directory
sebastien-rosset 3f1942e
Add variable for ruleguard config directory
sebastien-rosset 9978d61
Merge branch 'master' of https://github.com/CiscoM31/golangci-lint in…
sebastien-rosset 84081e7
Add unit tests
sebastien-rosset e2a4ab3
Add unit tests for ruleguard
sebastien-rosset 289238d
Add unit tests for ruleguard
sebastien-rosset 4a96225
Add unit tests for ruleguard
sebastien-rosset 79cd0f2
Add unit tests for ruleguard, fix package name
sebastien-rosset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This directory contains ruleguard files that are used in functional tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// go:build ruleguard | ||
package gorules | ||
|
||
import "github.com/quasilyte/go-ruleguard/dsl" | ||
|
||
// Suppose that we want to report the duplicated left and right operands of binary operations. | ||
// | ||
// But if the operand has some side effects, this rule can cause false positives: | ||
// `f() && f()` can make sense (although it's not the best piece of code). | ||
// | ||
// This is where *filters* come to the rescue. | ||
func DupSubExpr(m dsl.Matcher) { | ||
// All filters are written as a Where() argument. | ||
// In our case, we need to assert that $x is "pure". | ||
// It can be achieved by checking the m["x"] member Pure field. | ||
m.Match(`$x || $x`, | ||
`$x && $x`, | ||
`$x | $x`, | ||
`$x & $x`). | ||
Where(m["x"].Pure). | ||
Report(`suspicious identical LHS and RHS`) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// go:build ruleguard | ||
package gorules | ||
|
||
import "github.com/quasilyte/go-ruleguard/dsl" | ||
|
||
func StringsSimplify(m dsl.Matcher) { | ||
// Some issues have simple fixes that can be expressed as | ||
// a replacement pattern. Rules can use Suggest() function | ||
// to add a quickfix action for such issues. | ||
m.Match(`strings.Replace($s, $old, $new, -1)`). | ||
Report(`this Replace call can be simplified`). | ||
Suggest(`strings.ReplaceAll($s, $old, $new)`) | ||
|
||
// Suggest() can be used without Report(). | ||
// It'll print the suggested template to the user. | ||
m.Match(`strings.Count($s1, $s2) == 0`). | ||
Suggest(`!strings.Contains($s1, $s2)`) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.