Skip to content
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

Extend rule to look into Template Literal and BinaryExpressions #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RatoX
Copy link

@RatoX RatoX commented Jul 12, 2023

Fixes #7


This Pull Request is improving the lint rule to check more edge cases, like:

new RegExp("(?<=)" + "");
new RegExp(`(?<=)`);

However, it still doesn't cover this kind of scenario:

const foo = "(?<=)";
new RegExp(`some content ${foo}`);

That would require a little bit of more code.

@@ -85,8 +85,25 @@ const noLookaheadLookbehindRegexp: Rule.RuleModule = {
if (!unsupportedTargets.length && hasConfig) return {};

return {
TemplateLiteral(node: ESTree.TemplateLiteral & Rule.NodeParentExtension): void {
for (let quasi of node.quasis) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would end up reporting the problem on any string template literal (regardless if it is used inside a regexp or not). We should first check if the template literal is inside a regexp constructor before we iterate over all the nodes

@JonasBa
Copy link
Owner

JonasBa commented Jul 31, 2023

@RatoX I'm sorry for the delayed review, I missed this in the flood of GH notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The rule doesn't find Regex from concatenated strings
2 participants