RegExp parse errors in regexpp are not tolerated and crash eslint
See original GitHub issueTell 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:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
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.The rule will also crash with the default parser on this:
so this isn’t just an issue with
@typescript-eslint/parser
The other 3 rules that use
regexpp
(no-control-regex
,no-invalid-regexp
andprefer-named-capture-group
) already have try/catch.@Jessidhia would you like to submit a PR for this fix?