Skip to content

style(eslint): enable prefer-string-starts-ends-with rule - #12332

Merged
pkuczynski merged 4 commits into
masterfrom
style/eslint-prefer-nullish-coalescing
Apr 10, 2026
Merged

pkuczynski merged 4 commits into
masterfrom
style/eslint-prefer-nullish-coalescing

Conversation

@pkuczynski

@pkuczynski pkuczynski commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

Enable @typescript-eslint/prefer-string-starts-ends-with as suggested in #12255. The codebase already conforms — this rule prevents future regressions.

@pkuczynski pkuczynski self-assigned this Apr 9, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3)   📘 Rule violations (0)   📎 Requirement gaps (0)   🎨 UX Issues (0)
🐞\ ☼ Reliability (1) ⚙ Maintainability (1) ◔ Observability (1)

Grey Divider


Action required

1. startsWith rule already violated 🐞 ☼
Description
@typescript-eslint/prefer-string-starts-ends-with is enabled as an error, but the codebase contains
existing string prefix checks using indexOf(...) === 0 (e.g., udtName.indexOf("_") === 0) that this
rule will flag, causing lint failures.
Code

eslint.config.mjs[41]

+            "@typescript-eslint/prefer-string-starts-ends-with": "error",
Evidence
The ESLint config enables prefer-string-starts-ends-with for all TypeScript files. Multiple TS
source files currently use string prefix checks via indexOf(...) === 0, which the rule flags and
requires converting to startsWith(...).

eslint.config.mjs[19-46]
src/driver/cockroachdb/CockroachQueryRunner.ts[3443-3446]
src/driver/cockroachdb/CockroachQueryRunner.ts[4457-4460]
src/driver/postgres/PostgresQueryRunner.ts[5108-5111]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`@typescript-eslint/prefer-string-starts-ends-with` is enabled as `error`, but there are existing prefix checks implemented as `str.indexOf("_") === 0`, which will fail lint.
## Issue Context
These checks should be rewritten to `str.startsWith("_")` (or otherwise refactored) to comply with the rule.
## Fix Focus Areas
- src/driver/cockroachdb/CockroachQueryRunner.ts[3443-3446]
- src/driver/cockroachdb/CockroachQueryRunner.ts[4457-4460]
- src/driver/postgres/PostgresQueryRunner.ts[5108-5111]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Nullish coalescing rule violated ☑ 🐞 ☼
Description
@typescript-eslint/prefer-nullish-coalescing is enabled as an error, but the codebase contains
existing fallbacks using || on optional values (e.g., options: options || {}), which the rule
will flag and cause lint failures.
Code

eslint.config.mjs[40]

+            "@typescript-eslint/prefer-nullish-coalescing": "error",
Evidence
The ESLint config enables prefer-nullish-coalescing for all TypeScript files. At least one TS file
uses || to provide a default for an optional parameter (options?: ColumnOptions), which this
rule flags and expects to be rewritten using ??.

eslint.config.mjs[19-46]
src/decorator/columns/CreateDateColumn.ts[12-19]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`@typescript-eslint/prefer-nullish-coalescing` is enabled as `error`, but there are existing patterns like `options || {}` where `options` is optional, which will fail lint.
## Issue Context
Update nullish-defaulting sites to use `??` instead of `||` when the intent is to default only on `null`/`undefined`.
## Fix Focus Areas
- src/decorator/columns/CreateDateColumn.ts[12-19]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Nullish rule not enabled 🐞 ⚙
Description
The PR title/description claims @typescript-eslint/prefer-nullish-coalescing is being enabled, but
the ESLint config does not add that rule anywhere. This means the intended regression-prevention for
?? is not actually enforced.
Code

eslint.config.mjs[R37-43]

         // custom rules
         "@typescript-eslint/consistent-type-exports": "error",
         "@typescript-eslint/consistent-type-imports": "error",
+            "@typescript-eslint/prefer-string-starts-ends-with": "error",
         // exceptions from typescript-eslint/recommended
         "@typescript-eslint/ban-ts-comment": "warn",
Evidence
In the main TypeScript ruleset, only @typescript-eslint/prefer-string-starts-ends-with is added;
there is no @typescript-eslint/prefer-nullish-coalescing entry present in the rules block.

eslint.config.mjs[35-61]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
PR metadata says `@typescript-eslint/prefer-nullish-coalescing` is enabled, but the config doesn't include it.
## Issue Context
This creates a mismatch between the PR intent and actual enforcement.
## Fix Focus Areas
- eslint.config.mjs[35-61]
## Suggested change
Add the rule to the `rules` block, e.g.:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

4. Error logging edge-case regression 🐞 ◔
Description
Sample apps changed error.stack ? error.stack : error to error.stack ?? error, which changes
behavior when error.stack is an empty string. In that case the new code logs an empty string
instead of the error object, reducing debugging output.
Code

sample/sample10-mixed/app.ts[54]

+            .catch((error) => console.log(error.stack ?? error))
Evidence
The new logging uses nullish coalescing. Unlike the previous truthiness check, ?? will not fall
back when error.stack is "" (empty string).

sample/sample10-mixed/app.ts[51-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`error.stack ?? error` differs from the previous `error.stack ? error.stack : error` when `error.stack` is an empty string.
## Issue Context
This only affects sample apps and is an edge case, but it can reduce log usefulness.
## Fix Focus Areas
- sample/sample10-mixed/app.ts[51-56]
## Suggested change
If you want to preserve the old behavior, use a truthy check:

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 5480daf

@pkuczynski pkuczynski changed the title style(eslint): enable prefer-nullish-coalescing and prefer-string-starts-ends-with rules style(eslint): enable prefer-string-starts-ends-with rule Apr 10, 2026
@pkuczynski
pkuczynski requested a review from OSA413 April 10, 2026 00:37
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 29d9ea9

@pkuczynski
pkuczynski enabled auto-merge (squash) April 10, 2026 17:50
@sonarqubecloud

Copy link
Copy Markdown

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit b924800

@pkuczynski
pkuczynski merged commit b2adef8 into master Apr 10, 2026
15 checks passed
@pkuczynski
pkuczynski deleted the style/eslint-prefer-nullish-coalescing branch April 10, 2026 17:53
@github-actions github-actions Bot added this to the 1.0 milestone Apr 10, 2026
Nosfistis pushed a commit to Nosfistis/typeorm that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants