← All lints

parens_on_o1

L0608Stylewarn

Parentheses on an O(1)O(1) member

xs.len(): an O(1)O(1) member reads without ()

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

Why

Parentheses mark work in CP Lang (decision 140): a member reads without () exactly when it is O(1)O(1), so xs.len, xs.first, s.last and t.at read like fields because they are. xs.len() is the C++ and Python spelling and is reported as error E0304 with a fix that drops the (); cpl fix applies it.

The practice it serves

Spelling that hides what the code means.

Not flagged

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

Near miss
let xs = [1, 2, 3]
print(xs.sum())

Turn it off

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

Generated from spec/checker-lints/parens_on_o1, the same record the linter is built from.