sindresorhus/eslint-plugin-unicorn
Rule proposal: `prefer-regexp-code-point-escape`
Chiusa
#989 aperta il 2 gen 2021
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 1g 16h) (399 PR mergiate in 30 g)
Descrizione
Unicode code point escapes are new in ES6. They support more bits than older escapes and it's better to always use them for consistency, even when they're not required.
- https://exploringjs.com/es6/ch_unicode.html#sec_escape-sequences
- https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point
This overlaps with the no-hex-escapes rule. Not sure whether we should deprecate that one. It's plausible that someone wants to prevent Hex escapes, but not prefer code point escapes. Opinions welcome.
Inspired by https://github.com/eslint/eslint/issues/12488.
Fail
const foo = '\123'; // Octal
const foo = '\cA'; // Control escape sequence
const foo = '\x7A'; // Hex
const foo = '\u2661'; // Unicode escape sequence
const foo = '\uD83D\uDCA9'; // Unicode surrogate pair
Pass
const foo = '\u{7A}';
const foo = '\u{1F4A9}';