-
Notifications
You must be signed in to change notification settings - Fork 42
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
dsl: add MatchComment method to the DSL module #222
Conversation
Every **rule** definition starts with a [`Match()`](https://godoc.org/github.com/quasilyte/go-ruleguard/dsl#Matcher.Match) or [`MatchComment()`](https://godoc.org/github.com/quasilyte/go-ruleguard/dsl#Matcher.MatchComment) method call. | ||
|
||
* For `Match()`, you specify one or more [AST patterns](https://github.com/mvdan/gogrep) that should represent what kind of Go code a rule is supposed to match. | ||
* For `MatchComment()`, you provide one or more regular expressions that sould match a comment of interest. |
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.
s/sould/should/
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.
Thanks!
Fixed in #223
|
||
// Good. No information loss in this case. | ||
// "// nolint foo bar" => "//nolint foo bar" | ||
m.MatchComment(`// nolint(?P<rest>)`).Suggest(`//nolint$rest`) |
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.
In practice, that should be able to handle several spaces after //
and optional :
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 removed this part from the docs.
See PR with actual implementation.
// Single-line // comments are passed line-by-line. | ||
// | ||
// Hint: if you want to match a plain text and don't want to do meta char escaping, | ||
// prepend `\Q` to your pattern. `\Qf(x)` will match `f(x)` as a plain text |
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.
Whoa! TIL
No description provided.