Skip to content

feat(prefer-charcode-at-in-loop): add rule#138

Merged
43081j merged 1 commit into
e18e:mainfrom
webpro:rule-prefer-charcode-at-in-loop
Jun 27, 2026
Merged

feat(prefer-charcode-at-in-loop): add rule#138
43081j merged 1 commit into
e18e:mainfrom
webpro:rule-prefer-charcode-at-in-loop

Conversation

@webpro

@webpro webpro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add opt-in prefer-charcode-at-in-loop
  • report single-code-unit string comparisons inside loops when the indexed receiver is known to be a string
  • provide suggestions to compare charCodeAt(index) against the numeric code unit instead of comparing one-character strings

Notes

This is suggestion-only and not part of the recommended config. It intentionally keeps unknown indexed access valid unless the receiver is a string literal/template or has string type information.

Node v24.9.0 benchmark on consumer-shaped loops:

  • leading-space scan: indexed compare 759.7ms, charCodeAt compare 660.9ms
  • first-character filter: indexed compare 14.7ms, charCodeAt compare 13.4ms

Test plan

  • npm test -- src/rules/prefer-charcode-at-in-loop.test.ts
  • npm run lint
  • npm run build

@webpro webpro force-pushed the rule-prefer-charcode-at-in-loop branch from 8c89460 to 6fe5710 Compare June 27, 2026 13:44
@43081j 43081j merged commit 8ad942c into e18e:main Jun 27, 2026
3 checks passed
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.

2 participants