Repository navigation
chore(web): allow a locale-less Intl formatter only to read its resolvedOptions, with or without new - #1555
Merged
Conversation
…vedOptions, with or without new (ansvisor#1549 review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
The #1549 review's item, the rule's zero-argument Intl case: Done. The one selector replaces the two, as suggested.
What I checked:
- The rule. I read the six selectors from this PR's
eslint.config.mjsand ran them with ESLint 9.39.4 and@typescript-eslint/parser8.56.1 (Linter) over a probe of 41 cases. All 41 come out as intended; main's seven selectors get 33.- The two cases from the review:
Intl.DateTimeFormat().format(date)is now flagged;new Intl.DateTimeFormat().resolvedOptions().timeZoneis now allowed.
- Also flagged now: a zero-argument
Intl.DateTimeFormat()withoutnew, when its.formatToParts()is called, or it's stored in a variable or passed to a function. - Allowed now: any
resolvedOptions()read withnew, such asnew Intl.DateTimeFormat().resolvedOptions().localeandnew Intl.NumberFormat().resolvedOptions(). - Still allowed: a
resolvedOptions()read with?.(on the formatter or on the call), or destructured. - Unchanged:
- every other zero-argument
Intlformatter (NumberFormat,Collator,PluralRules,RelativeTimeFormat,ListFormat,Segmenter,DisplayNames) is still flagged, with or withoutnew; - the
undefinedand[]selectors; - the
toLocale*Stringselectors; - named locales,
localeCompare,Intl.supportedValuesOf('timeZone')andsupportedLocalesOfaren't flagged.
- every other zero-argument
- The JSX form
{new Intl.DateTimeFormat().format(d)}is flagged.
- The two cases from the review:
- The full config. With the real config file (main repo's packages, no cache), a probe with the PR's four lines flags the two formatting lines and not the two
resolvedOptions()reads. The same probe as a.test.tsis ignored, andlib/time-zone.tsandlib/format.tsare clean. - No false hits.
-
The merged tree's
web/srchas 738 non-test files, with 0 hits and 0 parse errors. The only matches are the two inlib/format.test.ts, which the config skips on purpose. -
Only three forms are newly flagged without formatting:
(Intl.DateTimeFormat() as X).resolvedOptions();Intl.DateTimeFormat()!.resolvedOptions();Intl.DateTimeFormat()['resolvedOptions']().
None is in the code, and the plain form reads the same.
-
- Merge.
- Before the API deploy. Lint config only, so nothing changes for users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up from the review of #1549. The
no-restricted-syntaxrule's zero-argumentIntlcase was off both ways:new Intl.DateTimeFormat().resolvedOptions().timeZone, a common way to read the browser's time zone, though it formats nothing.Intl.DateTimeFormat().format(date), which formats in the browser's locale.The maintainer's selector replaces the two old ones in
web/eslint.config.mjs. It allows a zero-argumentIntlformatter only when itsresolvedOptions()is read, with or withoutnew:":matches(NewExpression, CallExpression)[callee.object.name='Intl'][arguments.length=0]:not(MemberExpression[property.name='resolvedOptions'] > .object)"Checked on a probe file, since deleted:
Intl.DateTimeFormat().format(…),new Intl.DateTimeFormat().format(…),new Intl.NumberFormat(),Intl.NumberFormat()andnew Intl.Collator().Intl.DateTimeFormat().resolvedOptions().timeZone(lib/time-zone.ts),new Intl.DateTimeFormat().resolvedOptions().timeZoneandnew Intl.NumberFormat('en-US').Related issue
Follow-up to #1549 (no issue).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Line 1 is flagged and line 2 isn't.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings were already on mainyarn typecheckpasses (run fromweb/): lint config onlyyarn format:checkpasses (run fromweb/): lint config only, outside its globsA review agent checked the selector against yours, and that
:not(Parent > .object)looks at the direct parent only:foo(Intl.DateTimeFormat()).resolvedOptions()is still flagged.🤖 Generated with Claude Code