Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0542

Docs

XO0542: an operator after a `??` default

warning · reported by the vet

?? binds loosest of the binary operators (core 15), so m.get(w) ?? 0 + 1 adds 1 to the default only: a key that is present gives its count unchanged and a missing one gives 1. xo vet reports a literal default followed by a tighter operator. Parenthesize what was meant: (m.get(w) ?? 0) + 1, or m.get(w) ?? (0 + 1) when the sum was the default.

Example

let n = counts.get(w) ?? 0 + 1

Fix

let n = (counts.get(w) ?? 0) + 1

Run xo explain XO0542 for this text in a terminal, or see section 10.6 of the specification.