Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: prefer-code-point #1490

Closed
fisker opened this issue Aug 16, 2021 · 3 comments Β· Fixed by #1584
Closed

Rule proposal: prefer-code-point #1490

fisker opened this issue Aug 16, 2021 · 3 comments Β· Fixed by #1584

Comments

@fisker
Copy link
Collaborator

fisker commented Aug 16, 2021

Prefer String#codePointAt() over String#charCodeAt()
Prefer String.fromCodePoint() over String.fromCharCode()

Fail

const unicorn = 'πŸ¦„'.charCodeAt(0).toString(16)
// -> 'd83e'
const unicorn = String.fromCharCode(0x1f984)
// -> '濾'

Pass

const unicorn = 'πŸ¦„'.codePointAt(0).toString(16)
// -> '1f984'
const unicorn = String.fromCodePoint(0x1f984)
// -> 'πŸ¦„'

This rule should use suggestions instead of auto-fix.

@fregante
Copy link
Collaborator

This rule should use suggestions instead of auto-fix.

Why? Only due to support?

@fisker
Copy link
Collaborator Author

fisker commented Aug 17, 2021

Because it result differently.

@sindresorhus
Copy link
Owner

This is now accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants