fix: nullish coalescing operator precedence (#240)

This commit is contained in:
Ash 2023-04-01 16:40:25 +01:00 committed by GitHub
parent b11f774c41
commit ab2ef4f89b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -217,7 +217,7 @@ const PRECEDENCES: [u8; 27] = [
4, 3,
9, 9,
2,
9,
3
];
const ARITHMETIC: &[&str] = &OPERATORS[..6];
@ -296,6 +296,7 @@ fn test() {
("x ? a && b : 0", Some(json!([{ "groups": [["&&", "||", "?:"]] }]))),
("x ? 0 : a && b", Some(json!([{ "groups": [["&&", "||", "?:"]] }]))),
("a + b ?? c", Some(json!([{ "groups": [["+", "??"]] }]))),
("a in b ?? c", Some(json!([{ "groups": [["in", "??"]] }]))),
];
Tester::new(NoMixedOperators::NAME, pass, fail).test_and_snapshot();

View file

@ -108,3 +108,10 @@ expression: no_mixed_operators
╰────
help: Use parentheses to clarify the intended order of operations.
⚠ eslint(no-mixed-operators): Unexpected mix of in with ??
╭─[no_mixed_operators.tsx:1:1]
1 │ a in b ?? c
· ── ──
╰────
help: Use parentheses to clarify the intended order of operations.