Skip to content

fix(eslint-plugin): [no-unnecessary-condition] downgrade fix to suggestion #11081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export type MessageId =
| 'neverOptionalChain'
| 'noOverlapBooleanExpression'
| 'noStrictNullCheck'
| 'suggestRemoveOptionalChain'
| 'typeGuardAlreadyIsType';

export default createRule<Options, MessageId>({
Expand All @@ -164,7 +165,7 @@ export default createRule<Options, MessageId>({
recommended: 'strict',
requiresTypeChecking: true,
},
fixable: 'code',
hasSuggestions: true,
messages: {
alwaysFalsy: 'Unnecessary conditional, value is always falsy.',
alwaysFalsyFunc:
Expand All @@ -184,6 +185,7 @@ export default createRule<Options, MessageId>({
'Unnecessary conditional, the types have no overlap.',
noStrictNullCheck:
'This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.',
suggestRemoveOptionalChain: 'Remove unnecessary optional chain',
typeGuardAlreadyIsType:
'Unnecessary conditional, expression already has the type being checked by the {{typeGuardOrAssertionFunction}}.',
},
Expand Down Expand Up @@ -863,9 +865,14 @@ export default createRule<Options, MessageId>({
loc: questionDotOperator.loc,
node,
messageId: 'neverOptionalChain',
fix(fixer) {
return fixer.replaceText(questionDotOperator, fix);
},
suggest: [
{
messageId: 'suggestRemoveOptionalChain',
fix(fixer) {
return fixer.replaceText(questionDotOperator, fix);
},
},
],
});
}

Expand Down
Loading
Loading