| 1 |
--- |
| 2 |
name: code-review |
| 3 |
description: Review a pull request or diff in uutils/coreutils. Checks GPL/GNU provenance, GNU behavior compatibility, tests, error handling, style, performance and commit hygiene, and produces short, actionable, line-level comments. |
| 4 |
--- |
| 5 |
|
| 6 |
# Code review for uutils/coreutils |
| 7 |
|
| 8 |
uutils coreutils is a cross-platform reimplementation of the GNU coreutils in Rust. |
| 9 |
Reviews are about keeping it *original*, *GNU-compatible*, *tested*, and *small*. |
| 10 |
|
| 11 |
## How to write the review |
| 12 |
|
| 13 |
- One-line, actionable comments anchored to the specific line. Say what to change, |
| 14 |
not why it matters in three paragraphs. |
| 15 |
- Push back on long-winded code, duplication, needless complexity, and changes |
| 16 |
without tests. |
| 17 |
- Don't restate the diff back to the author, don't praise, don't pad. |
| 18 |
- Keep the tone that of a human reviewer: plain, direct, no generated-sounding prose. |
| 19 |
- If nothing is wrong, say so in one line rather than inventing findings. |
| 20 |
|
| 21 |
## The one rule that cannot be bent |
| 22 |
|
| 23 |
uutils is **original** code. It cannot contain code derived from GNU or any other |
| 24 |
GPL/LGPL implementation, and a PR must not even link to the GNU source. |
| 25 |
|
| 26 |
Flag as blocking: |
| 27 |
|
| 28 |
- Code, structure, comments, variable names or file layout that mirror GNU's. |
| 29 |
- Tests ported verbatim from the GNU test suite — including the *fixtures*: input |
| 30 |
strings, byte sequences, delimiters, field ranges and expected outputs. "It's only |
| 31 |
a few chars" is not an exception; GNU tests are GPLv3+. |
| 32 |
- Links or references to GNU source/test paths in code comments, commit messages or |
| 33 |
the PR description. |
| 34 |
|
| 35 |
Reading the GNU *manual* and man pages is fine, as are permissively-licensed |
| 36 |
implementations (Apple file_cmds, OpenBSD). Be extra careful with AI-assisted |
| 37 |
patches: assistants can reproduce GPL sources verbatim. |
| 38 |
|
| 39 |
## Correctness and GNU compatibility |
| 40 |
|
| 41 |
- Behavior, options, output and exit codes should match GNU, checked |
| 42 |
with `LC_ALL=C` (GNU messages are localized; the GNU tests run under `C`). |
| 43 |
Error messages can be different when better. |
| 44 |
- A "GNU does X" claim in a PR should name the version it was checked |
| 45 |
against. And it should be a recent version. |
| 46 |
- GNU compatibility must not regress (`util/run-gnu-test.sh`, |
| 47 |
`util/remaining-gnu-error.py`). A compatibility fix should mention the test it makes |
| 48 |
pass. |
| 49 |
- Watch security-sensitive output that scripts parse: character classes |
| 50 |
(`[:graph:]`, `[:print:]`, `[:alnum:]`) in `tr`/`sort`/`cut`, real vs effective |
| 51 |
uid/gid in `id`/`groups`/`stat`/`whoami`, `--preserve-root` canonicalization, |
| 52 |
and flags that must work independently of each other (e.g. `ln --no-dereference` |
| 53 |
without `--force`). |
| 54 |
|
| 55 |
## Safety |
| 56 |
|
| 57 |
- **TOCTOU**: reject check-then-act on paths (stat/exists/permission check followed by |
| 58 |
a separate open/unlink/chmod). Prefer `openat()` / `O_NOFOLLOW` / fd-relative |
| 59 |
operations, especially in `cp`, `mv`, `rm`, `chown`, `chmod`, `chgrp`, `install`. |
| 60 |
- Recursive traversal must not follow symlinks out of the intended tree. |
| 61 |
- Untrusted input: no unbounded allocations, no integer overflow, no path-traversal |
| 62 |
foot-guns. |
| 63 |
|
| 64 |
## Rust style |
| 65 |
|
| 66 |
- No `panic!`, `.unwrap()`, `expect()` on fallible paths, or stray `println!`. |
| 67 |
`unreachable!` needs a comment justifying why the branch can't happen. |
| 68 |
- Avoid `std::process::exit` in reusable utility logic; return `Result` and use `uucore::error`. Allow process-level entry points and platform/tooling paths that must terminate explicitly. |
| 69 |
- `OsStr`/`Path` for paths, not `String`/`str`. |
| 70 |
- Keep `unsafe` minimal; prefer FFI, allow rare documented non-FFI exceptions, and require a `// SAFETY:` comment. |
| 71 |
- `thiserror`, not `quick-error`; `rustix` preferred over `nix`. |
| 72 |
- Strip `(os error N)` from messages (`strip_errno`). |
| 73 |
- Descriptive names, no cryptic abbreviations. Avoid single-call wrapper functions |
| 74 |
and gratuitous macros. |
| 75 |
- Do not use `#[allow(...)]` to hide warnings without a documented, narrowly scoped reason; prefer `#[expect(..., reason = "...")]` for justified exceptions. |
| 76 |
- Clippy runs with `all` + `cargo` + `pedantic` + `use_self`; CI fails on any warning. |
| 77 |
Common ones worth catching in review: `redundant_closure_for_method_calls`, |
| 78 |
`map_unwrap_or`, `needless_for_each`, `items_after_statements`, `unnecessary_wraps`, |
| 79 |
`assigning_clones`, `needless_continue`, `unreadable_literal`. |
| 80 |
- Avoid one-line functions |
| 81 |
- If the code has a lot of platform specific modifications (#cfg), suggest to create a new platform specific file. |
| 82 |
|
| 83 |
## Tests |
| 84 |
|
| 85 |
- New or change of behavior comes with a test. Integration tests live in |
| 86 |
`tests/by-util/test_<utility>.rs`; unit tests next to the code. |
| 87 |
- Tests must be original (see the provenance rule above) and pick values that are |
| 88 |
clearly distinct from GNU's fixtures. |
| 89 |
- Use `.no_output()` rather than `.no_stdout().no_stderr()`. |
| 90 |
- Anything that can't run under WASI needs `#[cfg_attr(wasi_runner, ignore)]`. |
| 91 |
- If a GNU test was failing while the Rust suite passed, the PR should add a Rust |
| 92 |
test so the gap can't reopen. |
| 93 |
|
| 94 |
## Docs, help and i18n |
| 95 |
|
| 96 |
- New options or user-visible behavior should update the relevant `--help`/docs sources and generated man page as applicable, plus the appropriate `en-US.ftl` (utility, `uucore`, or shared crate). |
| 97 |
- User-facing strings go through `translate!` with a namespaced key, not hardcoded. |
| 98 |
|
| 99 |
## Performance and size |
| 100 |
|
| 101 |
- Compare runtime changes with representative benchmarks, and apply the repository's established binary-size threshold rather than a blanket 3% limit. |
| 102 |
- Extra memory is acceptable when it buys real speed or correctness. |
| 103 |
- Watch for per-item work added to hot loops: new allocations, an extra pass over the |
| 104 |
data, newly non-inlined cross-crate calls, and — very common — error context |
| 105 |
(`format!`, `translate!`, `to_string()`) built eagerly on the *success* path. |
| 106 |
Error messages must be materialized only inside the `Err` arm. |
| 107 |
|
| 108 |
## Scope, dependencies and commits |
| 109 |
|
| 110 |
- Avoid code duplication at all costs. Look in uucore if the feature/function isn't there. |
| 111 |
- Small and self-contained. Unrelated refactors, formatting-only churn, and |
| 112 |
dependency/lockfile bumps belong in their own PR. Pure code moves get their own commit. |
| 113 |
- When a PR mixes several logical changes, ask for a split and point the author at the |
| 114 |
`gh stack` extension to keep the pieces reviewable in order. |
| 115 |
- New dependencies must be discussed and justified: build time, binary size, audit |
| 116 |
surface, license compatibility. |
| 117 |
- Descriptive title prefixed with the utility: `ls: fix version sort order`, not |
| 118 |
`Fix #1234`. Same for commits: `<program>: <description>`. |
| 119 |
|
| 120 |
## Before approving |
| 121 |
|
| 122 |
CI green (fmt, clippy `-D warnings`, tests) on Linux, macOS and Windows, with |
| 123 |
`#[cfg(...)]` used for platform-specific code rather than breaking other targets. |