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 proposal: `prefer-regexp-code-point-escape`

See original GitHub issue

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.

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}';

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Jan 3, 2021

And I prefer const foo = ‘\u007A’; over const foo = ‘\u{7A}’;

Did you see my arguments for why \u{7A} is better? It’s shorter and it lets you use the same syntax always.

It also makes escapes stand out more because of the braces, which makes strings with a lot of escapes more readable.

0reactions
sindresorhuscommented, Feb 9, 2021

This is now accepted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >
SEC proposes substantive changes in 4 stock market rules
The proposed amendments would expand the scope of entities subject to Rule 605, modify the information required to be reported under the rule, ......
Read more >
SEC Proposes Equity Market Overhaul and Best Execution Rule
The SEC is proposing to amend Regulation NMS to (1) amend the tick sizes under Rule 612 to establish a variable minimum pricing...
Read more >
sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal: Require comparator function for `Array#sort()`. Unfunded#2014created bybmish ... Rule proposal: `prefer-regexp-code-point-escape`.
Read more >
SEC Proposes Amendments to the Shareholder Proposal Rules
The SEC proposed modifying certain bases for excluding shareholder proposals from company proxy statements. If adopted, these amendments are ...
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