Skip to content
Draft
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 @@ -185,7 +185,7 @@ export default createRule<Options, MessageId>({
{
allowConstantLoopConditions: false,
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
checkTypePredicates: false,
checkTypePredicates: true,
},
],
create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,13 @@ declare function assert(x: unknown): asserts x;

assert(Math.random() > 0.5);
`,
options: [{ checkTypePredicates: true }],
},
{
code: `
declare function assert(x: unknown, y: unknown): asserts x;

assert(Math.random() > 0.5, true);
`,
options: [{ checkTypePredicates: true }],
},
{
// should not report because option is disabled.
Expand All @@ -993,7 +991,6 @@ class ThisAsserter {
const thisAsserter: ThisAsserter = new ThisAsserter();
thisAsserter.assertThis(true);
`,
options: [{ checkTypePredicates: true }],
},
{
// could be argued that this should report since `thisAsserter` is truthy.
Expand All @@ -1005,22 +1002,19 @@ class ThisAsserter {
const thisAsserter: ThisAsserter = new ThisAsserter();
thisAsserter.assertThis(Math.random());
`,
options: [{ checkTypePredicates: true }],
},
{
code: `
declare function assert(x: unknown): asserts x;
assert(...[]);
`,
options: [{ checkTypePredicates: true }],
},
{
// ok to report if we start unpacking spread params one day.
code: `
declare function assert(x: unknown): asserts x;
assert(...[], {});
`,
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -1044,15 +1038,13 @@ isString(a);
declare function assertString(x: unknown): asserts x is string;
assertString('falafel');
`,
options: [{ checkTypePredicates: true }],
},
{
// Technically, this has type 'falafel' and not string.
code: `
declare function isString(x: unknown): x is string;
isString('falafel');
`,
options: [{ checkTypePredicates: true }],
},
`
type A = { [name in Lowercase<string>]?: A };
Expand Down Expand Up @@ -2874,7 +2866,6 @@ assert(true);
messageId: 'alwaysTruthy',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2888,7 +2879,6 @@ assert(false);
messageId: 'alwaysFalsy',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2903,7 +2893,6 @@ assert(true, Math.random() > 0.5);
messageId: 'alwaysTruthy',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2917,7 +2906,6 @@ assert({});
messageId: 'alwaysTruthy',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2931,7 +2919,6 @@ assertsString(a);
messageId: 'typeGuardAlreadyIsType',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2945,7 +2932,6 @@ isString(a);
messageId: 'typeGuardAlreadyIsType',
},
],
options: [{ checkTypePredicates: true }],
},
{
code: `
Expand All @@ -2959,7 +2945,6 @@ isString('fa' + 'lafel');
messageId: 'typeGuardAlreadyIsType',
},
],
options: [{ checkTypePredicates: true }],
},

// "branded" types
Expand Down
Loading