Skip to content

style: disallow format calls without interpolation placeholders - #13404

Closed
Planeshifter wants to merge 3 commits into
developfrom
philipp/no-format-without-interpolation
Closed

Planeshifter wants to merge 3 commits into
developfrom
philipp/no-format-without-interpolation

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • adds a no-restricted-syntax ESLint entry which disallows calling format (from string/format) with a single string literal containing no interpolation placeholders (e.g., format( 'invalid argument. Third argument must not be an empty string.' )), as such calls are unnecessary overhead and the string can be used directly
  • fixes the 53 existing violations across 37 files by unwrapping the format call and removing format requires which became unused

Note that single-argument calls whose string contains % (e.g., %% escapes) remain allowed, as those do perform work.

This should help with AI agents or humans adding format for strings where it is not needed.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was written primarily by Claude Code, with the lint rule selector and all call-site fixes verified locally against the repository ESLint configuration.


@stdlib-js/reviewers

Comment thread etc/eslint/rules/style.js Outdated

// format without interpolation
{
'selector': 'CallExpression[callee.name="format"][arguments.length=1][arguments.0.value=/^[^%]*$/]',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a little tricky, as this supposes we never use format as an alias for something else which is not string interpolation. E.g., we could have a "format" function which does some other kind of formatting and does not operate on a formatting string, and devs will get spurious lint errors.

@Planeshifter

Copy link
Copy Markdown
Member Author

This is now handled via #14519.

@kgryte kgryte reopened this Sep 22, 2026
@kgryte kgryte closed this Sep 22, 2026
@kgryte
kgryte deleted the philipp/no-format-without-interpolation branch September 22, 2026 19:56
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

No coverage information available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants