-
Notifications
You must be signed in to change notification settings - Fork 8
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: validate pattern declarations #298
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.
Just one problem. We can fix this in a separate PR though
Otherwise LGTM 🤘
node/manifest.ts
Outdated
throw new Error( | ||
`Could not parse path declaration of function '${declaration.function}': ${(error as Error).message}`, | ||
) | ||
} | ||
} | ||
|
||
return pathToRegularExpression(declaration.path) | ||
} | ||
|
||
const getExcludedRegularExpression = (declaration: Declaration) => { | ||
if ('pattern' in declaration && declaration.excludedPattern) { |
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.
if ('pattern' in declaration && declaration.excludedPattern) { | |
if ('excludedPattern' in declaration && declaration.excludedPattern) { |
Not really a change from this PR but seems it is currently wrong/broken? But I might be wrong and we only return the excludePattern when there is a 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.
Good catch! Fixed in 51d1023.
node/declaration.ts
Outdated
Assertion(path) { | ||
// Lookaheads are not supported. If we find one, throw an error. | ||
if (path.node.kind === 'Lookahead') { | ||
throw new Error('Regular expressions with negative lookaheads are not supported') |
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's not just negative lookaheads that aren't supported: positive lookaheads aren't either.
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.
Ah-ha! The comment was correct but the error message was not. Fixed in 2efa3f8.
* feat: validate pattern declarations * refactor: change import * chore: add comment * fix: add missing call to `serializePattern` * refactor: wrap call to `parsePattern` * refactor: update error message * fix: look for `excludedPattern`
Which problem is this pull request solving?
This PR parses into an AST any paths defined as regular expressions and:
List other issues or pull requests related to this problem
Supersedes #226.