You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PR enables @typescript-eslint/prefer-optional-chain as an error for all **/*.ts, but there
are still x && x.y patterns (e.g., this.options && this.options.data/reload/chunk) that the rule
will flag, causing npm run lint to fail.
ESLint is run repo-wide via npm run lint, and the new rule applies to all TS files. The current
branch still contains classic null-check && chains that match what prefer-optional-chain targets
(same base repeated with member access), so flipping the rule to error will introduce new lint
failures.
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-optional-chain` is now an **error**, but there are still `&&`-based null checks in the repo that will be reported by the rule (and fail `npm run lint`).
## Issue Context
The eslint flat config applies to `files: ["**/*.ts"]`, and `package.json` runs `eslint` without path restrictions.
## Fix Focus Areas
- Replace `this.options && this.options.data` with optional chaining (or an explicit undefined check if falsy values must be preserved).
- Replace `this.options && this.options.reload === false` with `this.options?.reload === false`.
- Refactor the chunk logic to avoid `this.options && this.options.chunk && this.options.chunk > 0` (e.g., store `const chunk = this.options?.chunk` and use `chunk && chunk > 0`).
### Files/lines to update
- eslint.config.mjs[31-41]
- package.json[78-91]
- src/persistence/EntityPersistExecutor.ts[46-69]
- src/persistence/SubjectExecutor.ts[431-476]
- src/persistence/SubjectExecutor.ts[587-600]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Match index check wrong 🐞≡
Description
OrmUtils.parseSqlCheckExpression uses if (enumMatch?.index) which skips valid matches at offset
0, preventing enum parsing when the CHECK-expression pattern starts at the beginning of the SQL
string.
String.match() sets match.index to 0 when the match is at the beginning; checking `if
(enumMatch?.index) treats 0` as falsy and incorrectly bypasses the parsing logic even though a
match exists.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`parseSqlCheckExpression` incorrectly uses a truthiness check on `enumMatch.index`, which fails when `index === 0`.
## Issue Context
When a regex match is at the start of the string, `match.index` is `0`.
## Fix Focus Areas
- Change the condition to an explicit undefined check, e.g. `if (enumMatch?.index !== undefined)` (or `!= null`).
### Files/lines to update
- src/util/OrmUtils.ts[314-327]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
opened to discuss this one - the rule is definitely a net benefit because it prevents bugs (e.g. what if the var = 0)
Any migration cost if we do this? Strange bugs from rewriting the existing checks? Test look good, and the semantic correctness is a net benefit. Just want to make sure we're not missing something with these sweeping changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable
@typescript-eslint/prefer-optional-chainas suggested in #12255, replacing verbose&&chains with optional chaining (?.).