Skip to content

feat(lint/js): add useStringStartsEndsWith#9796

Open
dyc3 wants to merge 1 commit intomainfrom
dyc3/useStringStartsEndsWith
Open

feat(lint/js): add useStringStartsEndsWith#9796
dyc3 wants to merge 1 commit intomainfrom
dyc3/useStringStartsEndsWith

Conversation

@dyc3
Copy link
Copy Markdown
Contributor

@dyc3 dyc3 commented Apr 4, 2026

Summary

This adds useStringStartsEndsWith, which is a port of https://typescript-eslint.io/rules/prefer-string-starts-ends-with/

I chose to use type info (like the source rule) because my hunch is that there would be way too many false positives otherwise. Also, I chose to split the invalid tests into a bunch of files because the rule is very complex, and it makes it easier to spot whether diagnostics are getting emitted.

generated by gpt 5.4, but heavily guided to stop it from doing dumb things.

closes #7653
supersedes and closes #8582

Test Plan

all the tests are from the source rule, excluding the ones depending on the source rule's option

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 4, 2026

🦋 Changeset detected

Latest commit: 0abca04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Apr 4, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 4, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 196 skipped benchmarks1


Comparing dyc3/useStringStartsEndsWith (0abca04) with main (1d09f0f)

Open in CodSpeed

Footnotes

  1. 196 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions github-actions bot added the A-CLI Area: CLI label Apr 4, 2026
@dyc3 dyc3 force-pushed the dyc3/useStringStartsEndsWith branch from 6cc3176 to 5c6f564 Compare April 4, 2026 22:42
@dyc3 dyc3 marked this pull request as ready for review April 4, 2026 23:06
@dyc3 dyc3 force-pushed the dyc3/useStringStartsEndsWith branch from c6082cc to 328c0e5 Compare April 4, 2026 23:10
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

Walkthrough

A new linter rule useStringStartsEndsWith was added to the Biome JS/TS analyser. It detects string prefix/suffix checks expressed via binary comparisons and string/regex methods (e.g. indexOf, charAt, match, slice, substring, anchored RegExp.test) and emits diagnostics with optional automatic fixes rewriting to startsWith()/endsWith(). Changes include the rule implementation, a RuleState type and fix plan logic, an empty options struct and module export, and comprehensive valid/invalid test fixtures.

Suggested reviewers

  • ematipico
  • Netail
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(lint/js): add useStringStartsEndsWith' clearly summarises the main change: adding a new JavaScript linter rule.
Description check ✅ Passed The description explains the motivation (porting typescript-eslint rule), implementation choices (type info to avoid false positives), test structure, and references linked issues.
Linked Issues check ✅ Passed The PR implements all coding requirements from #7653 and #8582: it ports the prefer-string-starts-ends-with rule to Biome with type-aware detection and comprehensive test coverage matching the source rule.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the new rule: rule definition, test fixtures, rule options, and module registration. No extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dyc3/useStringStartsEndsWith

Comment @coderabbitai help to get the list of available commands and usage tips.

@dyc3 dyc3 requested review from a team April 5, 2026 03:29
@dyc3 dyc3 force-pushed the dyc3/useStringStartsEndsWith branch from 328c0e5 to 0abca04 Compare April 6, 2026 14:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.changeset/rude-apples-prove.md (1)

5-7: Changeset description is clear and user-focused.

The description accurately conveys the rule's purpose and its type-aware behaviour. A minor clarity improvement: consider adding a comma after "strings" to make the compound structure clearer.

📝 Optional clarity tweak
-The rule uses type information, so it only reports on strings and skips array lookups such as `items[0] === "a"`.
+The rule uses type information, so it only reports on strings, and skips array lookups such as `items[0] === "a"`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/rude-apples-prove.md around lines 5 - 7, The changeset sentence
describing the rule's type-aware behavior needs a comma for clarity: update the
sentence that mentions the rule "uses type information" so that the clause reads
"so it only reports on strings, and skips array lookups such as `items[0] ===
\"a\"`" — modify the text referring to useStringStartsEndsWith to insert the
comma after "strings" to improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.changeset/rude-apples-prove.md:
- Around line 5-7: The changeset sentence describing the rule's type-aware
behavior needs a comma for clarity: update the sentence that mentions the rule
"uses type information" so that the clause reads "so it only reports on strings,
and skips array lookups such as `items[0] === \"a\"`" — modify the text
referring to useStringStartsEndsWith to insert the comma after "strings" to
improve readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 16cea3ab-836c-48e7-b2c0-84534420d57f

📥 Commits

Reviewing files that changed from the base of the PR and between 328c0e5 and 0abca04.

⛔ Files ignored due to path filters (14)
  • crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs is excluded by !**/migrate/eslint_any_rule_to_biome.rs and included by **
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_configuration/src/generated/domain_selector.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_configuration/src/generated/linter_options_check.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidCharAt.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidIndex.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidNoFix.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidRegex.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSearch.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSlice.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/valid.ts.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (11)
  • .changeset/rude-apples-prove.md
  • crates/biome_js_analyze/src/lint/nursery/use_string_starts_ends_with.rs
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidCharAt.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidIndex.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidNoFix.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidRegex.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSearch.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSlice.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/valid.ts
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/use_string_starts_ends_with.rs
✅ Files skipped from review due to trivial changes (9)
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSlice.ts
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidSearch.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidRegex.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidNoFix.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidIndex.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/invalidCharAt.ts
  • crates/biome_js_analyze/tests/specs/nursery/useStringStartsEndsWith/valid.ts
  • crates/biome_rule_options/src/use_string_starts_ends_with.rs

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

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port prefer-string-starts-ends-with from typescript-eslint

1 participant