← All lints

is_in_cond_header

L0207Stylewarn

Pattern test x is p in if/elif/while header

if/elif/while headers bind with let p = x, not x is p

Flagged
let x: ?Int = Some(3)
if x is v and v > 0:
    print(v)
Write instead
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.

Near miss
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.