← All lints

getter_parens

L0206Stylewarn

Built-in getter called with ()

.len(), .is_empty(), .first(), .last(), .rev(), .items() are read without ()

Flagged
let xs = [1, 2, 3]
print(xs.len())
Write instead
let xs = [1, 2, 3]
print(xs.len)

Why

Built-in getters (len, is_empty, first, last, rev, items) are read as properties without parentheses. cpl fix drops the empty ().

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 xs = [3, 1, 2]
print(xs.sorted())

Turn it off

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

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