Skip to content

Commit 864fa0e

Browse files
committed
fix(linter/no-unused-expression): false positive with satisfies expressions (#14259)
fixes #14248 using `x satisfies never` is a common way to perform an exhaustiveness check. this PR allows satisfies expressions (aligning it with the typescript-eslint rule)
1 parent 8217dce commit 864fa0e

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

crates/oxc_linter/src/rules/eslint/no_unused_expressions.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl NoUnusedExpressions {
154154
| Expression::CallExpression(_)
155155
| Expression::V8IntrinsicExpression(_)
156156
| Expression::UpdateExpression(_)
157+
| Expression::TSSatisfiesExpression(_)
157158
| Expression::YieldExpression(_) => false,
158159
Expression::ConditionalExpression(conditional_expression) => {
159160
if self.0.allow_ternary {
@@ -179,9 +180,6 @@ impl NoUnusedExpressions {
179180
Expression::TSAsExpression(ts_as_expression) => {
180181
self.is_disallowed(&ts_as_expression.expression)
181182
}
182-
Expression::TSSatisfiesExpression(ts_satisfies_expression) => {
183-
self.is_disallowed(&ts_satisfies_expression.expression)
184-
}
185183
Expression::TSTypeAssertion(ts_type_assertion) => {
186184
self.is_disallowed(&ts_type_assertion.expression)
187185
}
@@ -342,6 +340,24 @@ fn test() {
342340
Some(serde_json::json!([{ "allowTernary": true }])),
343341
),
344342
("const _func = (value: number) => value + 1;", None),
343+
(
344+
"
345+
type FooBarBaz = 'foo' | 'bar' | 'baz';
346+
export function satisfiesTest(c: FooBarBaz): string {
347+
switch(c) {
348+
case 'foo':
349+
return 'foo';
350+
case 'bar':
351+
return 'bar';
352+
default:
353+
c satisfies never;
354+
return '';
355+
}
356+
}
357+
",
358+
None,
359+
),
360+
("value satisfies number;", None),
345361
];
346362

347363
let fail = vec![

0 commit comments

Comments
 (0)