Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ foo ?? 'a string';

### `ignoreConditionalTests`

Setting this option to `true` will cause the rule to ignore any cases that are located within a conditional test. This is set to `false` by default.
Setting this option to `false` will cause the rule to also check cases that are located within a conditional test. This is set to `true` by default.

Generally expressions within conditional tests intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default createRule<Options, MessageIds>({
defaultOptions: [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
ignoreConditionalTests: false,
ignoreConditionalTests: true,
ignoreTernaryTests: false,
ignoreMixedLogicalExpressions: false,
ignorePrimitives: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,30 @@ x === null ? x : y;
declare const x: ${type} | ${nullish};
x || 'foo' ? null : null;
`,
options: [{ ignoreConditionalTests: true }],
})),
...nullishTypeValidTest((nullish, type) => ({
code: `
declare const x: ${type} | ${nullish};
if (x || 'foo') {}
`,
options: [{ ignoreConditionalTests: true }],
})),
...nullishTypeValidTest((nullish, type) => ({
code: `
declare const x: ${type} | ${nullish};
do {} while (x || 'foo')
`,
options: [{ ignoreConditionalTests: true }],
})),
...nullishTypeValidTest((nullish, type) => ({
code: `
declare const x: ${type} | ${nullish};
for (;x || 'foo';) {}
`,
options: [{ ignoreConditionalTests: true }],
})),
...nullishTypeValidTest((nullish, type) => ({
code: `
declare const x: ${type} | ${nullish};
while (x || 'foo') {}
`,
options: [{ ignoreConditionalTests: true }],
})),

// ignoreMixedLogicalExpressions
Expand Down Expand Up @@ -706,7 +701,6 @@ declare const x: ${type} | ${nullish};
if (() => x || 'foo') {}
`,
output: null,
options: [{ ignoreConditionalTests: true }],
errors: [
{
messageId: 'preferNullishOverOr',
Expand All @@ -732,7 +726,6 @@ declare const x: ${type} | ${nullish};
if (function werid() { return x || 'foo' }) {}
`,
output: null,
options: [{ ignoreConditionalTests: true }],
errors: [
{
messageId: 'preferNullishOverOr',
Expand Down