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
Improve prefer-lookaround
rule to report when there are leading/trailing assertions
#480
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.
Thank you for implementing this!
I find 2 things we should talk about.
lib/rules/prefer-lookaround.ts
Outdated
@@ -172,6 +180,190 @@ function getSideEffectsWhenReplacingCapturingGroup( | |||
} | |||
} | |||
|
|||
/** Checks if the given element is a zero length element that can be placed as a leading/trailing element. */ | |||
function isLeadingTrailingElement(element: Element): boolean { | |||
if (element.type === "CapturingGroup") return false |
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.
Why is it not allowed to be a capturing groups? A zero-length capturing group is useless, but would it be wrong if we transformed those capturing groups? E.g. /foo(bar)(\b|$)/
-> /foo(?=bar(\b|$))/
should be fine as long as this capturing group isn't used in the replacement string, right?
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.
You're right! I will change this PR.
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.
Thank you @ota-meshi!
close #478