mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
9a8730f31e
## Why Bazel clippy now catches lints that `cargo clippy` can still miss when a crate under `codex-rs` forgets to opt into workspace lints. The concrete example here was `codex-rs/app-server/tests/common/Cargo.toml`: Bazel flagged a clippy violation in `models_cache.rs`, but Cargo did not because that crate inherited workspace package metadata without declaring `[lints] workspace = true`. We already mirror the workspace clippy deny list into Bazel after [#15955](https://github.com/openai/codex/pull/15955), so we also need a repo-side check that keeps every `codex-rs` manifest opted into the same workspace settings. ## What changed - add `.github/scripts/verify_cargo_workspace_manifests.py`, which parses every `codex-rs/**/Cargo.toml` with `tomllib` and verifies: - `version.workspace = true` - `edition.workspace = true` - `license.workspace = true` - `[lints] workspace = true` - top-level crate names follow the `codex-*` / `codex-utils-*` conventions, with explicit exceptions for `windows-sandbox-rs` and `utils/path-utils` - run that script in `.github/workflows/ci.yml` - update the current outlier manifests so the check is enforceable immediately - fix the newly exposed clippy violations in the affected crates (`app-server/tests/common`, `file-search`, `feedback`, `shell-escalation`, and `debug-client`) --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/16353). * #16351 * __->__ #16353
84 lines
2.9 KiB
Rust
84 lines
2.9 KiB
Rust
use std::io::IsTerminal;
|
|
use std::path::Path;
|
|
|
|
use clap::Parser;
|
|
use codex_file_search::Cli;
|
|
use codex_file_search::FileMatch;
|
|
use codex_file_search::Reporter;
|
|
use codex_file_search::run_main;
|
|
use serde_json::json;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let cli = Cli::parse();
|
|
let reporter = StdioReporter {
|
|
write_output_as_json: cli.json,
|
|
show_indices: cli.compute_indices && std::io::stdout().is_terminal(),
|
|
};
|
|
run_main(cli, reporter).await?;
|
|
Ok(())
|
|
}
|
|
|
|
struct StdioReporter {
|
|
write_output_as_json: bool,
|
|
show_indices: bool,
|
|
}
|
|
|
|
impl Reporter for StdioReporter {
|
|
fn report_match(&self, file_match: &FileMatch) {
|
|
if self.write_output_as_json {
|
|
#[allow(clippy::unwrap_used)]
|
|
let json = serde_json::to_string(file_match).unwrap();
|
|
println!("{json}");
|
|
} else if self.show_indices {
|
|
#[allow(clippy::expect_used)]
|
|
let indices = file_match
|
|
.indices
|
|
.as_ref()
|
|
.expect("--compute-indices was specified");
|
|
// `indices` is guaranteed to be sorted in ascending order. Instead
|
|
// of calling `contains` for every character (which would be O(N^2)
|
|
// in the worst-case), walk through the `indices` vector once while
|
|
// iterating over the characters.
|
|
let mut indices_iter = indices.iter().peekable();
|
|
|
|
for (i, c) in file_match.path.to_string_lossy().chars().enumerate() {
|
|
match indices_iter.peek() {
|
|
Some(next) if **next == i as u32 => {
|
|
// ANSI escape code for bold: \x1b[1m ... \x1b[0m
|
|
print!("\x1b[1m{c}\x1b[0m");
|
|
// advance the iterator since we've consumed this index
|
|
indices_iter.next();
|
|
}
|
|
_ => {
|
|
print!("{c}");
|
|
}
|
|
}
|
|
}
|
|
println!();
|
|
} else {
|
|
println!("{}", file_match.path.to_string_lossy());
|
|
}
|
|
}
|
|
|
|
fn warn_matches_truncated(&self, total_match_count: usize, shown_match_count: usize) {
|
|
if self.write_output_as_json {
|
|
let value = json!({"matches_truncated": true});
|
|
#[allow(clippy::unwrap_used)]
|
|
let json = serde_json::to_string(&value).unwrap();
|
|
println!("{json}");
|
|
} else {
|
|
eprintln!(
|
|
"Warning: showing {shown_match_count} out of {total_match_count} results. Provide a more specific pattern or increase the --limit.",
|
|
);
|
|
}
|
|
}
|
|
|
|
fn warn_no_search_pattern(&self, search_directory: &Path) {
|
|
eprintln!(
|
|
"No search pattern specified. Showing the contents of the current directory ({}):",
|
|
search_directory.to_string_lossy()
|
|
);
|
|
}
|
|
}
|