sindresorhus/eslint-plugin-unicorn
Rule proposal: `prefer-regexp-code-point-escape`
クローズ
#989 opened on 2021/01/02
help wantednew rule
Repository metrics
- Stars
- (5,022 個のスター)
- PR merge metrics
- (平均マージ 4h 30m) (30d で 26 merged PRs)
説明
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}';