-
Notifications
You must be signed in to change notification settings - Fork 214
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
base: master
Are you sure you want to change the base?
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?
bbccb82
to
7332d1b
Compare
Up until now, constraint-name-style rule required constraint names to end in '_c'. This makes it configurable, so that users can provide a regular expression to specify what name style they want. The default behaviour is still the same.
7332d1b
to
846710b
Compare
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