← All lints

bool_ternary_print

L0524Idiomswarn

Answer words written out

if ok: "YES" else: "NO": the answer word is yes(ok)

Flagged
let n: Int = read()
print(if n % 2 == 0: "YES" else: "NO")
Write instead
let n: Int = read()
print(yes(n % 2 == 0))

Why

print(if ok: "YES" else: "NO") writes the answer words at every print, and a problem that wants Yes/No needs every copy changed. yes(ok) takes the words from io.answers: YES/NO by default, the judge profile's answers, or with io(answers: ("Yes", "No")) for a scope. There is no automatic fix, because which words yes prints depends on the judge profile; the help names the with io(...) that keeps the words you wrote.

The practice it serves

A hand-written pattern the language or the standard library already says in one step. Family: I. Input and output.

Not flagged

A near miss: close to the pattern, but not it.

Near miss
let n: Int = read()
print(if n % 2 == 0: "Alice" else: "Bob")

Turn it off

For one block, wrap it in with lint(bool_ternary_print: allow):. For a project, add bool_ternary_print = "allow" under [lints] in cp.toml.

Generated from spec/lints/bool_ternary_print, the same record the linter is built from.