Skip to content

Extend rule to look into Template Literal and BinaryExpressions#8

Open
RatoX wants to merge 1 commit intoJonasBa:mainfrom
RatoX:main
Open

Extend rule to look into Template Literal and BinaryExpressions#8
RatoX wants to merge 1 commit intoJonasBa:mainfrom
RatoX:main

Conversation

@RatoX
Copy link
Copy Markdown

@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.


return {
TemplateLiteral(node: ESTree.TemplateLiteral & Rule.NodeParentExtension): void {
for (let quasi of node.quasis) {
Copy link
Copy Markdown
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
Copy Markdown
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