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.

Rule: disable regular expression literal

See original GitHub issue

Please describe what the rule should do:

Do not allow Regular Expression Literal.

What category of rule is this? (place an “X” next to just one item)

[X] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Enforces code style (layout) [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

(new RegExp("a\bc")).test("a\bc")  // true
/a\bc/.test("a\bc")                // false

Why should this rule be included in ESLint (instead of a plugin)? Beacuse this is very important.

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

No.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
g-planecommented, Mar 22, 2019

@LuoZijun Example of usage no-restricted-syntax. I’ve not tested it yet so I’m not sure if it’s OK.

{
    "rules": {
        "no-restricted-syntax": ["error", "Literal[regex]"]
    }
}
1reaction
g-planecommented, Mar 24, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disallow use of the `RegExp` constructor in favor of regular ...
This rule disallows the use of the RegExp constructor function with string literals as its arguments. ... and String.raw tagged template literals ......
Read more >
prefer-regex-literals - ESLint - Pluggable JavaScript Linter
Rule Details​​ This rule disallows the use of the RegExp constructor function with string literals as its arguments. This rule also disallows the...
Read more >
Disable Unnecessary escape character: \/ no-useless-escape
To disable all rules on a specific line, use a line or block ... See https://www.regular-expressions.info/charclass.html for more info, ...
Read more >
Regex Tutorial - Turning Modes On and Off for Only Part of ...
In a programming language, you pass them as a flag to the regex constructor or append them to the regex literal. In an...
Read more >
Regular Expression (Regex) Tutorial
as . has special meaning in regex. The \ is known as the escape code, which restore the original literal meaning of the...
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