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.

RegExp parse errors in regexpp are not tolerated and crash eslint

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.2.1
  • Node Version: 12.6.0
  • npm Version: yarn 1.17.3

What parser (default, Babel-ESLint, etc.) are you using? @typescript-eslint/parser, but the crash is in the regexpp instance used by the no-misleading-character-class rule.

Please show your full configuration:

Configuration
// too big to share, but this in any file should be enough
/* eslint no-misleading-character-class: 1 */

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

/{/u

It happens on the command line as well but this is particularly bothersome with editor plugins (e.g. vscode integration), as you get plugin crash messages while typing up regexps.

What did you expect to happen? No crash, at worst just an “invalid regexp” lint.

What actually happened? Please include the actual, raw output from ESLint.

[Error - 1:37:37 PM] SyntaxError: Invalid regular expression: /{/u: Lone quantifier brackets
Occurred while linting .../test.js:9
    at RegExpValidator.raise (.../node_modules/regexpp/index.js:5643:15)
    at RegExpValidator.disjunction (.../node_modules/regexpp/index.js:5747:18)
    at RegExpValidator.pattern (.../node_modules/regexpp/index.js:5681:14)
    at RegExpValidator.validatePattern (.../node_modules/regexpp/index.js:5461:14)
    at RegExpParser.parsePattern (.../node_modules/regexpp/index.js:6889:25)
    at verify (.../node_modules/eslint/lib/rules/no-misleading-character-class.js:134:40)
    at Literal[regex] (.../node_modules/eslint/lib/rules/no-misleading-character-class.js:168:17)
    at listeners.(anonymous function).forEach.listener (.../node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (.../node_modules/eslint/lib/linter/safe-emitter.js:45:38)

To be clear, this is indeed a syntax error, it’s not a false positive on my input code; rather, it’s an unhandled error happening inside the rule when a regexp is invalid.

Are you willing to submit a pull request to fix this bug? Maybe, I don’t know how this should be handled.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, Aug 27, 2019

I think that ignoring syntax errors makes sense. Syntax errors should be reported by parsers and the purpose of no-misleading-character-class rule is to report the character classes that behave unexpectedly due to multiple code unit characters.

1reaction
mdjermanoviccommented, Aug 31, 2019

The rule will also crash with the default parser on this:

/*eslint no-misleading-character-class: error */

new RegExp("{", "u");

so this isn’t just an issue with @typescript-eslint/parser

The other 3 rules that use regexpp (no-control-regex, no-invalid-regexp and prefer-named-capture-group) already have try/catch.

@Jessidhia would you like to submit a PR for this fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-invalid-regexp - ESLint - Pluggable JavaScript Linter
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 >
es-lint-security flagging an unsafe regular expression
I've recently added the eslint-config-security plugin and it has flagged the above regex as unsafe due to the detect-unsafe-regex rule. It does ...
Read more >
jest-regex-util | Yarn - Package Manager
Fixed jest-editor-support 's parser to not crash on incomplete ASTs. (#3259); Fixed jest-resolve to use is-builtin-module instead of resolve.isCore .
Read more >
Language Server Extension Guide - Visual Studio Code
When we were improving PHP support in VS Code, we realized the official PHP parser is not error tolerant and cannot be reused...
Read more >
Medium level issues - Embold Help Center
Maintainability, https://eslint.org/docs/rules/no-div-regex ... classes in regular expressions do not match anything, they might be typing mistakes.
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