Skip to content

build: add no-useless-format ESLint rule - #14519

Open
Planeshifter wants to merge 1 commit into
developfrom
philipp/no-useless-format-lint-rule
Open

build: add no-useless-format ESLint rule#14519
Planeshifter wants to merge 1 commit into
developfrom
philipp/no-useless-format-lint-rule

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Resolves stdlib-js/metr-issue-tracker#1214.

Description

What is the purpose of this pull request?

This pull request:

  • adds a custom ESLint rule (stdlib/no-useless-format) which disallows calls to the format function exported by @stdlib/string/format when the format string does not contain any placeholders (i.e., no string interpolation is performed).
  • the rule is auto-fixable: the fixer replaces the format call with the string literal argument.
  • registers the rule in the rules namespace and enables the rule in the ESLint configuration.

Implementation notes:

  • The rule uses @stdlib/string/base/format-tokenize to tokenize the format string. If every token is a plain string (no placeholder objects), the format call is flagged as unnecessary.
  • Escaped percent signs (%%) produce plain string tokens, so format( '100%%' ) is correctly flagged.
  • The rule resolves each call expression's callee symbol via scope analysis (walking parent scopes and inspecting the nearest binding), guarding against shadowed and unrelated symbols.
  • The rule skips calls via #.call/#.apply and calls where the first argument is not a string literal.

Running the rule over the entire repository found 37 files with violations. Fixes are submitted separately in a companion PR.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request?

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 by Claude Code under my direction and instructions.


@stdlib-js/reviewers

🤖 Generated with Claude Code

@Planeshifter
Planeshifter force-pushed the philipp/no-useless-format-lint-rule branch from 1608ede to 5ed2eaa Compare August 22, 2026 06:20
@@ -1 +1 @@
/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Automatically removed by our ESLint autofix because these are not needed anymore here.

@Planeshifter
Planeshifter force-pushed the philipp/no-useless-format-lint-rule branch 3 times, most recently from 44723ab to 6cd4524 Compare August 22, 2026 06:36
Adds a custom ESLint rule which disallows calls to the format function
exported by `@stdlib/string/format` when the format string does not
contain any placeholders. Such calls are unnecessary, as the format
function simply returns the input string unchanged. The rule is
auto-fixable: the fixer replaces the format call with the string
literal argument.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter
Planeshifter force-pushed the philipp/no-useless-format-lint-rule branch from 6cd4524 to 4038496 Compare August 22, 2026 06:37
@Planeshifter Planeshifter changed the title feat: add no-useless-format ESLint rule build: add no-useless-format ESLint rule Aug 22, 2026
@Planeshifter
Planeshifter marked this pull request as ready for review August 22, 2026 06:39
@Planeshifter
Planeshifter requested a review from a team August 22, 2026 06:39
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 22, 2026
@kgryte

kgryte commented Aug 22, 2026

Copy link
Copy Markdown
Member

To ensure consistent naming (e.g., see https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/_tools/eslint/rules/no-unnecessary-nested-functions), can we rename this rule to no-unnecessary-format?

kgryte pushed a commit that referenced this pull request Aug 22, 2026
PR-URL: #14520
Reviewed-by: Athan Reines <kgryte@gmail.com>
Ref: #14519
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add no-useless-format ESLint rule

3 participants