-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
perf: don't use grapheme-splitter
on ASCII strings in key-spacing rule
#17122
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Since this code is so similar to what we have in id-length.js
would it be possible to move getStringLength()
to ast-utils
or to another shared file in order to avoid duplications? The different regex range should not be a problem: we could just use \u0000-\u007f
and be safe in all cases, even if id-length
would never use the lower part of the range, because it's not relevant to identifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
Improves performance of the
key-spacing
rule when used with options that enforce alignment of keys/values.What changes did you make? (Give an overview)
Similar to the logic we already have in the
id-length
rule, thekey-spacing
rule will now usegrapheme-splitter
only on non-ASCII strings. For ASCII strings, the length is simplyString#length
.To test the change, I configured the rule to enforce alignments:
and then ran
npm run lint
withTIMING=all
on the eslint codebase.Before the change
After the change
Linting time for this rule is reduced by ~50%.
Is there anything you'd like reviewers to focus on?