Skip to content

feat(prefer-slice-over-split-index): add rule#137

Merged
43081j merged 3 commits into
e18e:mainfrom
webpro:rule-prefer-slice-over-split-index
Jun 28, 2026
Merged

feat(prefer-slice-over-split-index): add rule#137
43081j merged 3 commits into
e18e:mainfrom
webpro:rule-prefer-slice-over-split-index

Conversation

@webpro

@webpro webpro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Add prefer-slice-over-split-index to report split(<string>)[0] and split(<string>)[1] when only one piece is needed.

The rule targets non-empty string separators and skips regex separators, unknown separators, empty-string splits, and split limits that change the indexed result.

This is opt-in only and is not enabled in the recommended/performance config by default.

A quick benchmark on Node 24 showed equivalent indexOf()/slice() forms were roughly 3x-4.5x faster than split()[0|1].

Verification

  • npm test -- src/rules/prefer-slice-over-split-index.test.ts
  • npm run lint
  • npm run build
  • npm test

Comment thread src/rules/prefer-slice-over-split-index.ts Outdated
Comment thread src/rules/prefer-slice-over-split-index.ts Outdated
Comment thread src/rules/prefer-slice-over-split-index.ts Outdated
Comment thread src/rules/prefer-slice-over-split-index.ts Outdated
@43081j 43081j force-pushed the rule-prefer-slice-over-split-index branch from 1db02c1 to e03b1da Compare June 28, 2026 13:34
@43081j 43081j merged commit 6aa3906 into e18e:main Jun 28, 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