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

fix: switch grapheme-splitter to graphemer #17160

Merged
merged 4 commits into from May 8, 2023

Conversation

fisker
Copy link
Contributor

@fisker fisker commented May 6, 2023

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

Switch grapheme-splitter to graphemer.

> new (require("grapheme-splitter"))().countGraphemes("πŸ‘©β€πŸ¦°πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ³οΈβ€πŸŒˆ")
4

> new (require("graphemer").default)().countGraphemes("πŸ‘©β€πŸ¦°πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ³οΈβ€πŸŒˆ")
3

Use Intl.Segmenter when available.

What changes did you make? (Give an overview)

Is there anything you'd like reviewers to focus on?

@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label May 6, 2023
@netlify
Copy link

netlify bot commented May 6, 2023

βœ… Deploy Preview for docs-eslint canceled.

Name Link
πŸ”¨ Latest commit 6ceb819
πŸ” Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/6458c30cb810640008762b6f

@fisker fisker marked this pull request as ready for review May 6, 2023 13:35
@fisker fisker requested a review from a team as a code owner May 6, 2023 13:35
@fasttime
Copy link
Member

fasttime commented May 6, 2023

Thanks for the PR @fisker. I can see that the issue in your snippet is affecting the behavior of the key-spacing rule, so it should be probably treated as a bug.

For example:

/* eslint key-spacing: ["error", { align: "value" }] */

const foo = {
  "πŸ‘πŸ‘πŸ‘": 1, // false positive
  "πŸ‘©β€πŸ¦°πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ³οΈβ€πŸŒˆ": 2,
};

const bar = {
  "πŸ‘πŸ‘πŸ‘πŸ‘": 1,
  "πŸ‘©β€πŸ¦°πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ³οΈβ€πŸŒˆ": 2, // false negative
};

REPRO LINK

@fasttime fasttime added repro:yes rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels May 6, 2023
Comment on lines 45 to 51
if (typeof Intl !== "undefined" && typeof Intl.Segmenter !== "undefined") {
iterateGraphemes = Intl.Segmenter.prototype.segment.bind(new Intl.Segmenter());
} else {
const Graphemer = require("graphemer").default;

iterateGraphemes = Graphemer.prototype.iterateGraphemes.bind(new Graphemer());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two methods always give the same result? If we can't guarantee that, it would be better to switch to just graphemer now and then just Intl.Segmenter in the next major version (when we drop Node < 16), because we wouldn't want linting to produce different results in different environments.

@fisker fisker changed the title fix: improve getGraphemeCount fix: switch grapheme-splitter to graphemer May 8, 2023
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Leaving open for others to review, and waiting for #17116 to be closed before merging.

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mdjermanovic mdjermanovic merged commit 9682d66 into eslint:main May 8, 2023
22 checks passed
@fisker fisker deleted the getGraphemeCount branch May 9, 2023 01:09
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Nov 5, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly contributor pool repro:yes rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

3 participants