-
Notifications
You must be signed in to change notification settings - Fork 267
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
Allows inversing the semantics of string-format
rule configurations
#765
Conversation
rule/string-format.go
Outdated
failure = r.errorMessage | ||
} else { | ||
failure = fmt.Sprintf("string literal doesn't match user defined regex /%s/", r.regexp.String()) | ||
switch r.negated { |
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.
Maybe we can reduce nesting if we use if/else
rather than switch
:
if r.negated {
// ...
}
// else here
rule/string-format.go
Outdated
failure = fmt.Sprintf("string literal doesn't match user defined regex /%s/", r.regexp.String()) | ||
switch r.negated { | ||
case false: | ||
// Fail if the string doesn't match the user's regex |
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.
// Fail if the string doesn't match the user's regex | |
// Fail if the string does NOT match the user's regex |
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.
To make it easier to read :)
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.
LGTM. Left few nits, feel free to consider them and merge.
Adds a syntactic mean to negate the regular expressions in the configuration to pass from a "accept if match" to "fail if match" mode.
Now, using a
!
the configuration meaning is invertedwith "/^[A-Z].$/" the rule will accept strings starting with capital letters
with "!/^[A-Z].$/" the rule will a fail on strings starting with capital letters
Closes #762