← All lints

prefix_twin

L0513Idiomswarn

Dimension-suffixed prefix or diff helper instead of Prefix/Diff

prefix1/prefix2/prefix_n, Prefix1/Prefix2/PrefixN, Diff1/Diff2: write Prefix or Diff

Flagged
let xs = [3, 1, 4]
let p = prefix_n(xs)
print(p.fold(0..3))
Write instead
let xs = [3, 1, 4]
let p = Prefix(xs)
print(p.fold(0..3))

Why

Prefix(a) dispatches by shape across [D]T, [R, C]T, and List<T> under one Prefix type family, and Diff covers both 1-D Diff<D, T> and 2-D Diff<R, C, T>. cpl fix rewrites the removed arity-suffixed names (prefix1, prefix2, prefix_n, Prefix1, Prefix2, PrefixN, Diff1, Diff2) to Prefix and Diff.

The practice it serves

A hand-written pattern the language or the standard library already says in one step. Family: S.prefix: prefix, difference and sliding structures.

Not flagged

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

Near miss
let xs = [3, 1, 4]
let p = Prefix(xs)
print(p.fold(0..3))

Turn it off

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

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