Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_js_analyze): additional check for noNegationElse #3517

Merged
merged 1 commit into from
Oct 27, 2022
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 @@ -139,8 +139,8 @@ fn is_negation(node: &JsAnyExpression) -> Option<bool> {
match (expr.operator().ok(), expr.argument().ok()) {
(
Some(JsUnaryOperator::LogicalNot),
Some(JsAnyExpression::JsUnaryExpression(_)),
) => Some(false),
Some(JsAnyExpression::JsUnaryExpression(inner_unary)),
) => Some(inner_unary.operator().ok()? != JsUnaryOperator::LogicalNot),
_ => Some(true),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// valid
// invalid
function f() {
return !!specs.variables ? specs.variables(props) : {};
}
}
// valid
!-a ? b : c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,33 @@ expression: issue_3141.js
---
# Input
```js
// valid
// invalid
function f() {
return !!specs.variables ? specs.variables(props) : {};
}
// valid
!-a ? b : c
```

# Diagnostics
```
issue_3141.js:6:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Invert blocks when performing a negation test.

4 │ }
5 │ // valid
> 6 │ !-a ? b : c
│ ^^^^^^^^^^^

i Suggested fix: Exchange alternate and consequent of the node

4 4 │ }
5 5 │ // valid
6 │ - !-a·?·b·:·c
6 │ + -a·?·c·:·b


```