diff options
-rw-r--r-- | .cargo/config | 3 | ||||
-rw-r--r-- | crates/tools/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 4 |
3 files changed, 34 insertions, 1 deletions
diff --git a/.cargo/config b/.cargo/config index b12f407e6..51ae33910 100644 --- a/.cargo/config +++ b/.cargo/config | |||
@@ -12,6 +12,9 @@ install-code = "run --package tools --bin tools -- install-code" | |||
12 | # Formats the full repository or installs the git hook to do it automatically. | 12 | # Formats the full repository or installs the git hook to do it automatically. |
13 | format = "run --package tools --bin tools -- format" | 13 | format = "run --package tools --bin tools -- format" |
14 | format-hook = "run --package tools --bin tools -- format-hook" | 14 | format-hook = "run --package tools --bin tools -- format-hook" |
15 | # Run clippy | ||
16 | lint = "run --package tools --bin tools -- lint" | ||
17 | |||
15 | # Runs the fuzzing test suite (currently only parser) | 18 | # Runs the fuzzing test suite (currently only parser) |
16 | fuzz-tests = "run --package tools --bin tools -- fuzz-tests" | 19 | fuzz-tests = "run --package tools --bin tools -- fuzz-tests" |
17 | 20 | ||
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 11b52ccb7..92634655d 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -133,6 +133,34 @@ 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 = ["clippy::collapsible_if", "clippy::nonminimal_bool"]; | ||
148 | run( | ||
149 | &format!( | ||
150 | "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", | ||
151 | TOOLCHAIN, | ||
152 | allowed_lints.join(" -A ") | ||
153 | ), | ||
154 | ".", | ||
155 | )?; | ||
156 | Ok(()) | ||
157 | } | ||
158 | |||
159 | pub fn install_clippy() -> Result<()> { | ||
160 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | ||
161 | run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".") | ||
162 | } | ||
163 | |||
136 | pub fn run_fuzzer() -> Result<()> { | 164 | pub fn run_fuzzer() -> Result<()> { |
137 | match Command::new("cargo") | 165 | match Command::new("cargo") |
138 | .args(&["fuzz", "--help"]) | 166 | .args(&["fuzz", "--help"]) |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 0c3339685..cf189bf1c 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 | } |