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.

`no-regex-spaces`: Add RegExp object form

See original GitHub issue

The docs for this rule specifically call out that the following will not be considered a warning:

/*eslint no-regex-spaces: 2*/

var re = new RegExp("foo   bar");

This seems to be a limitation, as it is not asserted in the tests, and intuitively it seems that the RegExp object format should be treated the same way as a literal, multiple spaces are equally hard to read in both.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
IanVScommented, Sep 1, 2015

From the rule docs:

The following patterns are considered warnings:

var re = /foo   bar/;

The following patterns are not warnings:

var re = new RegExp("foo   bar");

In most of the docs, the “not warnings” section is used to show how to “fix” the code so that the rule will no longer flag. So, what I’m proposing is:

The following patterns are considered warnings:

var re = /foo   bar/;

The following patterns are not warnings:

var re = /foo {3}bar/;

Known Limitations

This rule does not apply to the constructor form of RegExp, and therefore the following will not warn:

var re = new RegExp("foo   bar");
0reactions
IanVScommented, Jun 6, 2016

Cool, I’d be all for that, and @nzakas has said

I’m not against adding it

So I’d say go for it. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

RegExp - JavaScript - MDN Web Docs - Mozilla
Chrome Edge RegExp Full support. Chrome1. Toggle history Full support. Edge12. Toggle history @@match Full support. Chrome50. Toggle history Full support. Edge13. Toggle history @@matchAll Full...
Read more >
Rules - 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 >
Passing regex modifier options to RegExp object
You need to pass the second parameter: var r = new RegExp(keyword, "i");. You will also need to escape any special characters in...
Read more >
Regular Expression (Regex) Tutorial
lookingAt(), which tries to match from the START of the input (^. ... There are two sets of methods, issue via a RegEx...
Read more >
JavaScript RegExp Object - Regular Expressions - W3Schools
A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and...
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