-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: correct no-restricted-import messages
#20374
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
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
| * @returns {string} The formatted import names. | ||
| */ | ||
| function formatImportNames(importNames) { | ||
| return new Intl.ListFormat("en-US").format( |
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.
This could throw an error if Node.js is built without ICU as Intl is then not available.
Or in general I think this should be a utility as other rules also use lists in their messages.
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.
We're already using the same here, so if it's problematic then we should replace it:
Line 683 in e593aa0
| `The ${uncloneableOptionKeys.length === 1 ? "option" : "options"} ${new Intl.ListFormat("en-US").format(uncloneableOptionKeys.map(key => `"${key}"`))} cannot be cloned. When concurrency is enabled, all options must be cloneable values (JSON values). Remove uncloneable options or use an options module.`, |
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.
I should've make my point more clear: I would not lower our compatibility (some runtimes may not support Intl for any reason) for the two instances of Intl as it is easily inlineable as the locale is fixed:
function formatList(list) {
return `${list.slice(0, -1).join(', ')}${list.length > 1 ? ` and ${list.at(-1)` : ''}`;
}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.
If we want to add support for environments that don't support Intl, such as custom Node.js builds, I think we should replace all usages of Intl. There aren't many, but here is another one that should be also addressed, in addition to the other occurrence of Intl.ListFormat shown in #20374 (comment):
eslint/lib/shared/string-utils.js
Line 44 in 129882d
| segmenter ??= new Intl.Segmenter("en-US"); // en-US locale should be supported everywhere |
Since that would be a new feature outside the scope of this PR, maybe it's better to discuss it in a separate issue?
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.
Yes, let's discuss this in a separate issue, created #20380 for tracking.
snitin315
left a comment
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, thanks!
mdjermanovic
left a comment
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, thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[X] 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
[ ] Other, please explain:
What changes did you make? (Give an overview)
This PR fixes several violation messages in the
no-restricted-importsrule to make them more grammatically correct, and to avoid formatting arrays as strings in the message data, which results in incorrect spacing and missing quotes.Example:
Playground link
Before:
After:
Is there anything you'd like reviewers to focus on?