Pattern test x is p in if/elif/while header
if/elif/while headers bind with let p = x, not x is p
let x: ?Int = Some(3)
if x is v and v > 0:
print(v)let x: ?Int = Some(3)
if let v = x, v > 0:
print(v)Why
In if, elif, and while headers, bind with if let p = x / while let p = x and chain extra guards with , cond. Keep x is pat for value position where a Bool is wanted. cpl fix rewrites if/elif/while is headers to let.
The practice it serves
Spelling that hides what the code means. Family: N. Naming and spelling.
Not flagged
A near miss: close to the pattern, but not it.
let x: ?Int = Some(3)
if let v = x:
if v > 0: print(v)Turn it off
For one block, wrap it in with lint(is_in_cond_header: allow):. For a project, add is_in_cond_header = "allow" under [lints] in cp.toml.
Generated from spec/lints/is_in_cond_header, the same record the linter is built from.