Skip to content

Conversation

@fasttime
Copy link
Member

@fasttime fasttime commented Dec 4, 2025

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-imports rule 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:

/* eslint no-restricted-imports: ["error", {
	name: "some-module",
	importNames: ["Foo", "Bar", "Baz"],
}] */

export * from "some-module";

Playground link

Before:

import is invalid because 'Foo,Bar,Baz' from 'some-module' is restricted.

After:

import is invalid because 'Foo', 'Bar', and 'Baz' from 'some-module' are restricted.

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 Dec 4, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Dec 4, 2025
@netlify
Copy link

netlify bot commented Dec 4, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 22f9b2f
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/69319c4d689afd0008de18c4

@github-actions github-actions bot added the rule Relates to ESLint's core rules label Dec 4, 2025
@fasttime fasttime marked this pull request as ready for review December 4, 2025 15:00
@fasttime fasttime requested a review from a team as a code owner December 4, 2025 15:00
* @returns {string} The formatted import names.
*/
function formatImportNames(importNames) {
return new Intl.ListFormat("en-US").format(
Copy link
Contributor

@DMartens DMartens Dec 4, 2025

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.

Copy link
Member

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:

`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.`,

Copy link
Contributor

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)` : ''}`;
}

Copy link
Member Author

@fasttime fasttime Dec 5, 2025

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):

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?

Copy link
Contributor

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.

Copy link
Contributor

@snitin315 snitin315 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!

@snitin315 snitin315 moved this from Needs Triage to Implementing in Triage Dec 5, 2025
@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Dec 5, 2025
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!

@mdjermanovic mdjermanovic merged commit b017f09 into main Dec 5, 2025
31 checks passed
@mdjermanovic mdjermanovic deleted the fix-no-restricted-import-message branch December 5, 2025 16:10
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

5 participants