-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: Support Wildcard and * contract filters #567
feat: Support Wildcard and * contract filters #567
Conversation
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.
Some comments on the updated regex, and testing methodology. Great job adding jest here!
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.
Mostly looks good to me.
I just want to clarify once more that we want to support* as that seems correct to me. I checked with Pavel and he confirmed what I thought about supporting *
alone.
Also dropped a suggestion for fixing that babel issue. If it works, awesome. If not, no big deal, we can defer it. Leave a TODO in the test file to replace with imports later.
@@ -1 +1,2 @@ | |||
export const CONTRACT_NAME_REGEX = RegExp(/^(\*|([a-z\d]+[-_])*[a-z\d]+)(\.*(\*|([a-z\d]+[-_])*[a-z\d]+))*\.(\w+)$/); | |||
export const CONTRACT_NAME_REGEX = RegExp(/^(([a-z\d]+[-_])*[a-z\d]+(\.([a-z\d]+[-_])*[a-z\d]+)*\.([a-z\d]+)|([a-z\d]+))$/); |
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 job on the 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.
Looks good to me. There's a merge conflict but otherwise, should be good.
Add a comment above the original validate functions that they're duplicated in the test files due to a Babel config issue, and a TODO to address that.
Also, can you rename the PR to something like feat: Support Wildcard and * contract filters
?
added the * filter for contracts.
A valid contract is defined as
The function take in account all invalid contract names on nomicon
Please view test for more details.
Regex Broken down Below:
CONTRACT_NAME_REGEX:
/^(([a-z\d]+[-_])*[a-z\d]+(\.([a-z\d]+[-_])*[a-z\d]+)*\.([a-z\d]+)|([a-z\d]+))$/
^: Asserts the start of the string.
(: Begins a capturing group.
([a-z\d]+[-_])*: Matches a sequence of lowercase letters or digits, possibly followed by hyphens or underscores. The sequence may repeat zero or more times.
[a-z\d]+: Matches a sequence of one or more lowercase letters or digits.
(.([a-z\d]+[-_])[a-z\d]+): Allows for zero or more occurrences of a dot . followed by another sequence.
.([a-z\d]+): Matches a dot followed by a sequence of lowercase letters or digits.
|: OR operator.
([a-z\d]+): Matches a standalone sequence of lowercase letters or digits.
)$: Asserts the end of the string.
WILD_CARD_REGEX:
/\*\./
EDIT: Added more test please review
Added jest to support function testing.
It seems there's a problem getting Babel and the VM to work smoothly together. I'm going to dig deeper into it. Right now, I'm adjusting the test file to recreate the functions instead of using the usual require/import method, which seems to cause trouble with the VM code. It does mean there's some duplicated code in the testing files, but the test work.