Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust rewrite check_diff (Skeleton) #6166

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions check_diff/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
237 changes: 237 additions & 0 deletions check_diff/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions check_diff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "check_diff"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.4.2", features = ["derive"] }
25 changes: 25 additions & 0 deletions check_diff/src/main.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure to run rustfmt built from source on these files cargo run --bin rustfmt -- check_diff/src/main.rs I believe there are certain lines that exceed the max_width.

It would probably be worth adding the check_diff crate to rustfmt's self_test to ensure that these files stay formatted:

rustfmt/src/test/mod.rs

Lines 382 to 411 in 871113e

#[test]
fn self_tests() {
init_log();
let mut files = get_test_files(Path::new("tests"), false);
let bin_directories = vec!["cargo-fmt", "git-rustfmt", "bin", "format-diff"];
for dir in bin_directories {
let mut path = PathBuf::from("src");
path.push(dir);
path.push("main.rs");
files.push(path);
}
files.push(PathBuf::from("src/lib.rs"));
let (reports, count, fails) = check_files(files, &Some(PathBuf::from("rustfmt.toml")));
let mut warnings = 0;
// Display results.
println!("Ran {count} self tests.");
assert_eq!(fails, 0, "{fails} self tests failed");
for format_report in reports {
println!(
"{}",
FormatReportFormatterBuilder::new(&format_report).build()
);
warnings += format_report.warning_count();
}
assert_eq!(warnings, 0, "Rustfmt's code generated {warnings} warnings");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some code here to deal with external crates instead of modifying the existing loop.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use clap::Parser;
/// Inputs for the check_diff script
#[derive(Parser)]
struct CliInputs {
/// Git url of a rustfmt fork to compare against the latest master rustfmt
remote_repo_url: String,
/// Name of the feature branch on the forked repo
feature_branch: String,
/// Optional commit hash from the feature branch
#[arg(short, long)]
commit_hash: Option<String>,
/// Optional comma separated list of rustfmt config options to
/// pass when running the feature branch
#[arg(value_delimiter = ',', short, long, num_args = 1..)]
rustfmt_config: Option<Vec<String>>,
}

fn main() {
let args = CliInputs::parse();
println!(
"remote_repo_url: {:?}, feature_branch: {:?},
optional_commit_hash: {:?}, optional_rustfmt_config: {:?}",
args.remote_repo_url, args.feature_branch, args.commit_hash, args.rustfmt_config
);
}
8 changes: 8 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ fn self_tests() {
path.push("main.rs");
files.push(path);
}
// for crates that need to be included but lies outside src
let external_crates = vec!["check_diff"];
for external_crate in external_crates {
let mut path = PathBuf::from(external_crate);
path.push("src");
path.push("main.rs");
files.push(path);
}
Comment on lines +394 to +400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to note that if we add a lib.rs at some point then we'll need to remember to add that here too

files.push(PathBuf::from("src/lib.rs"));

let (reports, count, fails) = check_files(files, &Some(PathBuf::from("rustfmt.toml")));
Expand Down
Loading