-
Notifications
You must be signed in to change notification settings - Fork 215
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
linter: make constraint-name-style configurable #2017
linter: make constraint-name-style configurable #2017
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #2017 +/- ##
==========================================
- Coverage 92.95% 92.95% -0.01%
==========================================
Files 358 359 +1
Lines 26446 26458 +12
==========================================
+ Hits 24583 24594 +11
- Misses 1863 1864 +1 ☔ View full report in Codecov by Sentry. |
(Sorry for the long delay, I was pretty busy with other things...) Maybe we can provide a regular expression, e.g. configuration parameter name Using regular expressions is probably also a good choice to configure some of the other rules - they are |
No worries, first things first! I remember seeing discussion about regular expressions for some other rules in the past but thought the support wasn't there yet. I'll give this a look and definitely change it. If it ends up being as easy at it sounds I'll make an issue to eventually update every rule that could make use of this feature. |
At the time we had the disccussions about regular expressions, the choice was |
5e9b7da
to
bbccb82
Compare
static const Matcher& ConstraintMatcher() { | ||
absl::Status ConstraintNameStyleRule::Configure( | ||
absl::string_view configuration) { | ||
std::string pattern = kSuffix; |
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 think this is redundant but the rationale is the following:
If at some point we add other parameters to the rule, but pattern
is not provided, the ParseNameValues
wouldn't set any value to pattern
, so we would then need to set a default value.
Avoid future problems by doing it already?
violations_.insert(LintViolation(*identifier_token, kMessage, context)); | ||
if (!RE2::FullMatch(constraint_name, *regex)) { | ||
violations_.insert( | ||
LintViolation(*identifier_token, FormatReason(), context)); |
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.
Didn't find many resources on RE2. Can it somehow help us provide a better linting message than just "follow the regex"? Perhaps provide an autofix?
7332d1b
to
846710b
Compare
Looking backwards in time to see if there are active PRs. This looks like it is still relevant though probably some rebase needed due to conflicts. |
846710b
to
de0dffd
Compare
Updated, thanks for the reminder! |
f97ec65
to
d666d5e
Compare
void HandleSymbol(const verible::Symbol &symbol, | ||
const verible::SyntaxTreeContext &context) final; | ||
|
||
verible::LintRuleStatus Report() const final; | ||
|
||
std::string Pattern() const { return regex->pattern(); } |
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.
Is this public method (returning a string by value) needed anywhere ?
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.
It isn't, I used it to diagnose if the user-provided regex failed to parse but it is not needed anymore thanks to the SetRegex
utility. Missed it, thanks!
// convention. | ||
// The constraints should be named with lower_snake_case and end with _c. | ||
// Lower snake case, ends with `_c` | ||
#define kSuffix "([a-z0-9]+_)+c" |
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.
Instead of a macro, can this be a static constexpr absl::string_view kSuffix
in the private section of ConstraintNameStyleRule instead ?
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.
Indeed, thanks! Before kPrefix
was here too and that "needed" to be a define to do this stupid trick https://github.com/IEncinas10/verible/blob/de368dbc5d0a46ad14763854ee105f89a65d476a/verible/verilog/analysis/checkers/constraint-name-style-rule_test.cc#L73
d666d5e
to
de368db
Compare
using verible::RunLintTestCases; | ||
|
||
// Lower snake case, starts with `c_` | ||
#define kPrefix "c+(_[a-z0-9]+)+" |
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'd probably move this into the VariousPrefixTests
TEST to be close to where it is needed.
(and since it is only used in one place to assemble the pattern:
configuration, maybe it doesn't need to
be a macro at all).
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.
(other than that, looks great and ready to be merged)
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 agree. I needed this because my original intent was to offer a choice between _c
suffix and prefix. Thanks!
Make constraint-name-style rule regex-configurable while maintaining its default behavior of requiring constraint names to be lower snake case ending in `_c`
de368db
to
2191f11
Compare
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.
Nice.
Thanks!
Up until now, constraint-name-style rule required constraint names to end in
_c
. This makes it configurable, so that users can require constraint names to start withc_
instead.I'm open to sugestions about the configuration parameter's name, it doesn't convince me too much but I can't think of a better option. We could have
check_suffix
andcheck_prefix
but as it doesn't make sense for them to be on at the same time I don't like it too much either.Edit: forgot to handle this, leaving it here so I don't forget