diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-04 23:14:46 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-04 23:14:46 +0100 |
commit | 5deb907b4321d8328978d3322b0826b781814452 (patch) | |
tree | 2baa3b75b1ef62c02617c37ba9b800c41a3dd102 /crates/tools/src | |
parent | 8bd0e844247dc28d6ceb24b00f3cc3396bd5bf03 (diff) | |
parent | aa30c4909ebb1e85f1591f465c9e2875aa4d394e (diff) |
Merge #1374
1374: Implement `cargo lint` and fix some clippy errors r=alanhdu a=alanhdu
This creates a `cargo lint` command that runs clippy with certain lints disabled. I've also gone ahead and fixed some of the lint errors, although there are many more still to go.
cc #848
Co-authored-by: Alan Du <[email protected]>
Diffstat (limited to 'crates/tools/src')
-rw-r--r-- | crates/tools/src/lib.rs | 34 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 6 |
2 files changed, 38 insertions, 2 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 11b52ccb7..2446fdf28 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -133,6 +133,40 @@ pub fn install_format_hook() -> Result<()> { | |||
133 | Ok(()) | 133 | Ok(()) |
134 | } | 134 | } |
135 | 135 | ||
136 | pub fn run_clippy() -> Result<()> { | ||
137 | match Command::new("rustup") | ||
138 | .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"]) | ||
139 | .stderr(Stdio::null()) | ||
140 | .stdout(Stdio::null()) | ||
141 | .status() | ||
142 | { | ||
143 | Ok(status) if status.success() => (), | ||
144 | _ => install_clippy()?, | ||
145 | }; | ||
146 | |||
147 | let allowed_lints = [ | ||
148 | "clippy::collapsible_if", | ||
149 | "clippy::map_clone", // FIXME: remove when Iterator::copied stabilizes (1.36.0) | ||
150 | "clippy::needless_pass_by_value", | ||
151 | "clippy::nonminimal_bool", | ||
152 | "clippy::redundant_pattern_matching", | ||
153 | ]; | ||
154 | run( | ||
155 | &format!( | ||
156 | "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", | ||
157 | TOOLCHAIN, | ||
158 | allowed_lints.join(" -A ") | ||
159 | ), | ||
160 | ".", | ||
161 | )?; | ||
162 | Ok(()) | ||
163 | } | ||
164 | |||
165 | pub fn install_clippy() -> Result<()> { | ||
166 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | ||
167 | run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".") | ||
168 | } | ||
169 | |||
136 | pub fn run_fuzzer() -> Result<()> { | 170 | pub fn run_fuzzer() -> Result<()> { |
137 | match Command::new("cargo") | 171 | match Command::new("cargo") |
138 | .args(&["fuzz", "--help"]) | 172 | .args(&["fuzz", "--help"]) |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 0c3339685..8027ff833 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -3,7 +3,7 @@ use core::str; | |||
3 | use failure::bail; | 3 | use failure::bail; |
4 | use tools::{ | 4 | use tools::{ |
5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, | 5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, |
6 | Overwrite, Result, run_fuzzer, | 6 | Overwrite, Result, run_fuzzer, run_clippy, |
7 | }; | 7 | }; |
8 | use std::{path::{PathBuf}, env}; | 8 | use std::{path::{PathBuf}, env}; |
9 | 9 | ||
@@ -16,6 +16,7 @@ fn main() -> Result<()> { | |||
16 | .subcommand(SubCommand::with_name("format")) | 16 | .subcommand(SubCommand::with_name("format")) |
17 | .subcommand(SubCommand::with_name("format-hook")) | 17 | .subcommand(SubCommand::with_name("format-hook")) |
18 | .subcommand(SubCommand::with_name("fuzz-tests")) | 18 | .subcommand(SubCommand::with_name("fuzz-tests")) |
19 | .subcommand(SubCommand::with_name("lint")) | ||
19 | .get_matches(); | 20 | .get_matches(); |
20 | match matches.subcommand_name().expect("Subcommand must be specified") { | 21 | match matches.subcommand_name().expect("Subcommand must be specified") { |
21 | "install-code" => { | 22 | "install-code" => { |
@@ -28,6 +29,7 @@ fn main() -> Result<()> { | |||
28 | "gen-syntax" => generate(Overwrite)?, | 29 | "gen-syntax" => generate(Overwrite)?, |
29 | "format" => run_rustfmt(Overwrite)?, | 30 | "format" => run_rustfmt(Overwrite)?, |
30 | "format-hook" => install_format_hook()?, | 31 | "format-hook" => install_format_hook()?, |
32 | "lint" => run_clippy()?, | ||
31 | "fuzz-tests" => run_fuzzer()?, | 33 | "fuzz-tests" => run_fuzzer()?, |
32 | _ => unreachable!(), | 34 | _ => unreachable!(), |
33 | } | 35 | } |
@@ -82,7 +84,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
82 | 84 | ||
83 | [ROOT_DIR, &home_dir] | 85 | [ROOT_DIR, &home_dir] |
84 | .iter() | 86 | .iter() |
85 | .map(|dir| String::from(dir.clone()) + COMMON_APP_PATH) | 87 | .map(|dir| String::from(*dir) + COMMON_APP_PATH) |
86 | .map(PathBuf::from) | 88 | .map(PathBuf::from) |
87 | .filter(|path| path.exists()) | 89 | .filter(|path| path.exists()) |
88 | .collect() | 90 | .collect() |