Skip to content

Commit

Permalink
more unfixable cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin-Yeung committed Sep 4, 2023
1 parent 19cf727 commit 60bf61b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,24 @@ impl Rule for NoUnnecessaryAwait {
if !not_promise(&expr.argument) {
return;
}
if
// Removing `await` may change them to a declaration, if there is no `id` will cause SyntaxError
matches!(expr.argument, Expression::FunctionExpression(_))
|| matches!(expr.argument, Expression::ClassExpression(_))
// TODO: `+await +1` -> `++1`
{
if {
// Removing `await` may change them to a declaration, if there is no `id` will cause SyntaxError
matches!(expr.argument, Expression::FunctionExpression(_))
|| matches!(expr.argument, Expression::ClassExpression(_))
} || {
// `+await +1` -> `++1`
ctx.nodes().parent_node(node.id()).map_or(false, |parent| {
if let (
AstKind::UnaryExpression(parent_unary),
Expression::UnaryExpression(inner_unary),
) = (parent.kind(), &expr.argument)
{
parent_unary.operator == inner_unary.operator
} else {
false
}
})
} {
ctx.diagnostic(NoUnnecessaryAwaitDiagnostic(expr.span));
} else {
ctx.diagnostic_with_fix(NoUnnecessaryAwaitDiagnostic(expr.span), || {
Expand Down Expand Up @@ -138,9 +150,12 @@ fn test() {
let fix = vec![
("await []", "[]", None),
("await (a == b)", "(a == b)", None),
("+await -1", "+ -1", None),
("-await +1", "- +1", None),
("await function() {}", "await function() {}", None), // no autofix
("await class {}", "await class {}", None), // no autofix
// ("+await +1", "+await +1", None), // no autofix
("+await +1", "+await +1", None), // no autofix
("-await -1", "-await -1", None), // no autofix
];

Tester::new(NoUnnecessaryAwait::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Expand Down

0 comments on commit 60bf61b

Please sign in to comment.