Queue run by a head index
var head = 0; while head < q.len: q[head]: bfs or a Deque
domain V = 0..4
let next: [V]List<V> = [[V(1), V(2)], [V(3)], [V(3)], []]
var seen: [V]Bool = false
var q: List<V> = [V(0)]
seen[V(0)] = true
var head = 0
while head < q.len:
let u = q[head]
head += 1
for v in next[u] if not seen[v]:
seen[v] = true
q.push(v)
print(q)domain V = 0..4
let next: [V]List<V> = [[V(1), V(2)], [V(3)], [V(3)], []]
let p = bfs(next, from: [V(0)])
print(p[V(3)])Why
A C++ breadth-first search keeps its queue in a vector and a head index that walks it: while head < q.len: let u = q[head]; head += 1. bfs(next, from: [s]) from std.graph runs that queue and returns the distances, the parents and the visit order. A queue run by hand for anything else is a Deque with push and pop_front(), which says which end each step uses. There is no automatic fix, since what the loop computes decides which result replaces it.
The practice it serves
A hand-written pattern the language or the standard library already says in one step. Family: S.graph.
Not flagged
A near miss: close to the pattern, but not it.
domain V = 0..4
let next: [V]List<V> = [[V(1), V(2)], [V(3)], [V(3)], []]
let q: List<V> = [V(0)]
var head = 0
while head < q.len:
head += 1
print(q, head)Turn it off
For one block, wrap it in with lint(queue_head_index: allow):. For a project, add queue_head_index = "allow" under [lints] in cp.toml.
Generated from spec/lints/queue_head_index, the same record the linter is built from.