question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prefer-regex-literals: should report regex literals passed to RegExp constructor

See original GitHub issue

What rule do you want to change?

prefer-regex-literals

Does this change cause the rule to produce more or fewer warnings?

It will produce more warnings.

How will the change be implemented? (New option, new default behavior, etc.)?

I think this makes sense as default behavior.

Please provide some example code that this change will affect:

const foo = new RegExp(/foo/);

What does the rule currently do for this code?

It is not recognized as a problem.

What will the rule do after it’s changed?

The rule should report this as problem and suggest the following autofix:

-const foo = new RegExp(/foo/);
+const foo = /foo/;

Are you willing to submit a pull request to implement this change?

Yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Feb 9, 2020

I’ll champion this, only one more 👍 needed.

1reaction
lo1tumacommented, Jan 30, 2020

I’ve updated the PR and implemented the change behind a new option disallowRedundantWrapping.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-regex-literals - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
JavaScript: RegExp constructor vs RegEx literal - Stack Overflow
The key difference is that literal REGEX can't accept dynamic input, i.e. from variables, whereas the constructor can, because the pattern ...
Read more >
disallow invalid regular expression strings in RegExp ...
An invalid pattern in a regular expression literal is a SyntaxError when the code is parsed, but an invalid string in RegExp constructors...
Read more >
Use a regular expression literal instead of the 'RegExp ...
Use a regular expression literal instead of the 'RegExp' constructor. Active. Project: Drupal core. Version: 10.0.x-dev. Component:.
Read more >
ESLint equivalents in Elm - Elmcraft
There is no special support for regular expressions in Elm. ... The compiler will report the usages of debugging functions in optimized mode ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found