1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

Style: forbid .zip and .chain (#8188)

The `zip(a, b)` variant produces clearer code imho.

Downside: added dependency on `itertools`
This commit is contained in:
Emil Ernerfeldt
2026-05-22 12:25:34 +02:00
committed by GitHub
parent ac2496318f
commit 27373b06d0
18 changed files with 68 additions and 69 deletions

View File

@@ -72,6 +72,16 @@ def lint_lines(filepath, lines_in):
f"{filepath}:{line_nr}: write 'TODO(username):' instead"
)
if re.search(r"\.zip\(", line):
errors.append(
f"{filepath}:{line_nr}: use `std::iter::zip` or `itertools::izip!` instead of `.zip(`"
)
if re.search(r"\.chain\(", line):
errors.append(
f"{filepath}:{line_nr}: use `std::iter::chain` or `itertools::chain!` instead of `.chain(`"
)
if (
"(target_os" in line
and filepath.startswith("./crates/egui/")
@@ -105,6 +115,10 @@ def test_lint():
self
}
""",
"for (a, b) in std::iter::zip(xs, ys) {}",
"for (a, b, c) in itertools::izip!(xs, ys, zs) {}",
"for x in std::iter::chain(xs, ys) {}",
"for x in itertools::chain!(xs, ys, zs) {}",
]
should_fail = [
@@ -121,6 +135,8 @@ def test_lint():
self
}
""",
"for (a, b) in xs.iter().zip(ys) {}",
"for x in xs.iter().chain(ys) {}",
]
for code in should_pass: