From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/tools/src/bin/pre-commit.rs | 13 ++----------- crates/tools/src/lib.rs | 38 ++++++++------------------------------ crates/tools/src/main.rs | 10 ++-------- crates/tools/tests/cli.rs | 10 ++-------- 4 files changed, 14 insertions(+), 57 deletions(-) (limited to 'crates/tools') diff --git a/crates/tools/src/bin/pre-commit.rs b/crates/tools/src/bin/pre-commit.rs index e00bd0d3d..ea18c0863 100644 --- a/crates/tools/src/bin/pre-commit.rs +++ b/crates/tools/src/bin/pre-commit.rs @@ -19,19 +19,10 @@ fn update_staged() -> Result<()> { .current_dir(&root) .output()?; if !output.status.success() { - bail!( - "`git diff --diff-filter=MAR --name-only --cached` exited with {}", - output.status - ); + bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status); } for line in String::from_utf8(output.stdout)?.lines() { - run( - &format!( - "git update-index --add {}", - root.join(line).to_string_lossy() - ), - ".", - )?; + run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; } Ok(()) } diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 311bcb4d8..ef9c613a7 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -58,10 +58,8 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { None => continue 'outer, } }; - let text: String = itertools::join( - block.map(|(_, line)| line).chain(::std::iter::once("")), - "\n", - ); + let text: String = + itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n"); assert!(!text.trim().is_empty() && text.ends_with('\n')); res.push((start_line, Test { name, text, ok })) } @@ -78,11 +76,7 @@ pub fn generate(mode: Mode) -> Result<()> { } pub fn project_root() -> PathBuf { - Path::new(&env!("CARGO_MANIFEST_DIR")) - .ancestors() - .nth(2) - .unwrap() - .to_path_buf() + Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() } pub fn run(cmdline: &str, dir: &str) -> Result<()> { @@ -90,10 +84,7 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { let project_dir = project_root().join(dir); let mut args = cmdline.split_whitespace(); let exec = args.next().unwrap(); - let status = Command::new(exec) - .args(args) - .current_dir(project_dir) - .status()?; + let status = Command::new(exec).args(args).current_dir(project_dir).status()?; if !status.success() { bail!("`{}` exited with {}", cmdline, status); } @@ -112,10 +103,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { }; if mode == Verify { - run( - &format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), - ".", - )?; + run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; } else { run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; } @@ -124,10 +112,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { pub fn install_rustfmt() -> Result<()> { run(&format!("rustup install {}", TOOLCHAIN), ".")?; - run( - &format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), - ".", - ) + run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") } pub fn install_format_hook() -> Result<()> { @@ -156,10 +141,7 @@ pub fn run_fuzzer() -> Result<()> { _ => run("cargo install cargo-fuzz", ".")?, }; - run( - "rustup run nightly -- cargo fuzz run parser", - "./crates/ra_syntax", - ) + run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") } pub fn gen_tests(mode: Mode) -> Result<()> { @@ -245,11 +227,7 @@ fn existing_tests(dir: &Path, ok: bool) -> Result Result<()> { .subcommand(SubCommand::with_name("format-hook")) .subcommand(SubCommand::with_name("fuzz-tests")) .get_matches(); - match matches - .subcommand_name() - .expect("Subcommand must be specified") - { + match matches.subcommand_name().expect("Subcommand must be specified") { "install-code" => install_code_extension()?, "gen-tests" => gen_tests(Overwrite)?, "gen-syntax" => generate(Overwrite)?, @@ -45,10 +42,7 @@ fn install_code_extension() -> Result<()> { "./editors/code", )?; } else { - run( - r"code --install-extension ./ra-lsp-0.0.1.vsix --force", - "./editors/code", - )?; + run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?; } Ok(()) } diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs index 2ee4b5223..aab52a4aa 100644 --- a/crates/tools/tests/cli.rs +++ b/crates/tools/tests/cli.rs @@ -10,19 +10,13 @@ fn generated_grammar_is_fresh() { #[test] fn generated_tests_are_fresh() { if let Err(error) = gen_tests(Verify) { - panic!( - "{}. Please update tests by running `cargo gen-tests`", - error - ); + panic!("{}. Please update tests by running `cargo gen-tests`", error); } } #[test] fn check_code_formatting() { if let Err(error) = run_rustfmt(Verify) { - panic!( - "{}. Please format the code by running `cargo format`", - error - ); + panic!("{}. Please format the code by running `cargo format`", error); } } -- cgit v1.2.3