From 3c35491e309ac363e897d1aabcff64633daa42fb Mon Sep 17 00:00:00 2001 From: Chad Williamson Date: Fri, 1 Jan 2021 10:42:44 -0800 Subject: [PATCH] Add GitHub CI workflow and clippy fixes --- .github/workflows/ci.yml | 70 +++++++++++++++++++++++++++ src/find/matchers/exec.rs | 14 +++--- src/find/matchers/logical_matchers.rs | 16 ++---- src/find/matchers/mod.rs | 6 +-- src/find/matchers/perm.rs | 14 +++--- src/find/matchers/size.rs | 2 +- src/find/matchers/time.rs | 5 +- src/find/mod.rs | 13 +++-- src/testing/commandline/main.rs | 6 ++- 9 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f3235be --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +on: [push, pull_request] + +name: Basic CI + +jobs: + check: + name: cargo check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: cargo test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: cargo fmt --all -- --check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: cargo clippy -- -D warnings + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/src/find/matchers/exec.rs b/src/find/matchers/exec.rs index afc99ee..7898c4d 100644 --- a/src/find/matchers/exec.rs +++ b/src/find/matchers/exec.rs @@ -41,7 +41,7 @@ impl SingleExecMatcher { Ok(SingleExecMatcher { executable: executable.to_string(), args: transformed_args, - exec_in_parent_dir: exec_in_parent_dir, + exec_in_parent_dir, }) } @@ -72,9 +72,9 @@ impl Matcher for SingleExecMatcher { }; for arg in &self.args { - command.arg(match arg { - &Arg::LiteralArg(ref a) => a.as_os_str(), - &Arg::Filename => path_to_file.as_os_str(), + command.arg(match *arg { + Arg::LiteralArg(ref a) => a.as_os_str(), + Arg::Filename => path_to_file.as_os_str(), }); } if self.exec_in_parent_dir { @@ -85,16 +85,16 @@ impl Matcher for SingleExecMatcher { } } match command.status() { - Ok(status) => return status.success(), + Ok(status) => status.success(), Err(e) => { writeln!(&mut stderr(), "Failed to run {}: {}", self.executable, e).unwrap(); - return false; + false } } } fn has_side_effects(&self) -> bool { - return true; + true } } diff --git a/src/find/matchers/logical_matchers.rs b/src/find/matchers/logical_matchers.rs index bc24296..929b12a 100644 --- a/src/find/matchers/logical_matchers.rs +++ b/src/find/matchers/logical_matchers.rs @@ -26,9 +26,7 @@ pub struct AndMatcher { impl AndMatcher { pub fn new(submatchers: Vec>) -> AndMatcher { - AndMatcher { - submatchers: submatchers, - } + AndMatcher { submatchers } } } @@ -97,9 +95,7 @@ pub struct OrMatcher { impl OrMatcher { pub fn new(submatchers: Vec>) -> OrMatcher { - OrMatcher { - submatchers: submatchers, - } + OrMatcher { submatchers } } } @@ -189,9 +185,7 @@ pub struct ListMatcher { impl ListMatcher { pub fn new(submatchers: Vec>) -> ListMatcher { - ListMatcher { - submatchers: submatchers, - } + ListMatcher { submatchers } } } @@ -331,9 +325,7 @@ pub struct NotMatcher { impl NotMatcher { pub fn new(submatcher: Box) -> NotMatcher { - NotMatcher { - submatcher: submatcher, - } + NotMatcher { submatcher } } pub fn new_box(submatcher: Box) -> Box { diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index 0798dca..a62f80b 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -33,7 +33,7 @@ pub struct MatcherIO<'a> { impl<'a> MatcherIO<'a> { pub fn new(deps: &'a dyn Dependencies<'a>) -> MatcherIO<'a> { MatcherIO { - deps: deps, + deps, should_skip_dir: false, } } @@ -66,7 +66,7 @@ pub trait Matcher { /// collection of sub-Matchers. fn has_side_effects(&self) -> bool { // most matchers don't have side-effects, so supply a default implementation. - return false; + false } /// Notification that find has finished processing a given directory. @@ -213,7 +213,7 @@ fn build_matcher_tree( return Err(From::from(format!("missing argument to {}", args[i]))); } i += 1; - Some(name::NameMatcher::new_box(args[i].as_ref())?) + Some(name::NameMatcher::new_box(args[i])?) } "-iname" => { if i >= args.len() - 1 { diff --git a/src/find/matchers/perm.rs b/src/find/matchers/perm.rs index f28b57b..4076752 100644 --- a/src/find/matchers/perm.rs +++ b/src/find/matchers/perm.rs @@ -49,8 +49,8 @@ impl FromStr for ComparisonType { #[cfg(unix)] impl ComparisonType { - fn mode_bits_match(&self, pattern: u32, value: u32) -> bool { - match *self { + fn mode_bits_match(self, pattern: u32, value: u32) -> bool { + match self { ComparisonType::Exact => (0o7777 & value) == pattern, ComparisonType::AtLeast => (value & pattern) == pattern, ComparisonType::AnyOf => pattern == 0 || (value & pattern) > 0, @@ -89,7 +89,7 @@ mod parsing { state: ParserState::Beginning, bit_pattern: 0, comparison_type: ComparisonType::Exact, - string_pattern: string_pattern, + string_pattern, category_bit_pattern: 0, } } @@ -101,10 +101,10 @@ mod parsing { ))) } - fn handle_char(&mut self, char: &char) -> Result<(), Box> { + fn handle_char(&mut self, char: char) -> Result<(), Box> { if let ParserState::Beginning = self.state {}; - match *char { + match char { '-' => { if let ParserState::Beginning = self.state { self.comparison_type = ComparisonType::AtLeast; @@ -253,7 +253,7 @@ mod parsing { // no: so we've got a /u=rw,g=r form instead (or an invalid string). let mut p = Parser::new(string_value); for c in string_value.chars() { - p.handle_char(&c)?; + p.handle_char(c)?; } Ok((p.bit_pattern, p.comparison_type)) } @@ -274,7 +274,7 @@ impl PermMatcher { let (bit_pattern, comparison_type) = parsing::parse(pattern)?; Ok(PermMatcher { pattern: bit_pattern, - comparison_type: comparison_type, + comparison_type, }) } diff --git a/src/find/matchers/size.rs b/src/find/matchers/size.rs index 233df6f..409acf8 100644 --- a/src/find/matchers/size.rs +++ b/src/find/matchers/size.rs @@ -78,7 +78,7 @@ impl SizeMatcher { ) -> Result> { Ok(SizeMatcher { unit: suffix_string.parse()?, - value_to_match: value_to_match, + value_to_match, }) } diff --git a/src/find/matchers/time.rs b/src/find/matchers/time.rs index 4d1d1a1..9fe1005 100644 --- a/src/find/matchers/time.rs +++ b/src/find/matchers/time.rs @@ -4,7 +4,6 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -use std; use std::error::Error; use std::fs::{self, Metadata}; use std::io::{stderr, Write}; @@ -135,8 +134,8 @@ impl FileTimeMatcher { pub fn new(file_time_type: FileTimeType, days: ComparableValue) -> FileTimeMatcher { FileTimeMatcher { - file_time_type: file_time_type, - days: days, + file_time_type, + days, } } diff --git a/src/find/mod.rs b/src/find/mod.rs index 76f577a..b18e7e8 100644 --- a/src/find/mod.rs +++ b/src/find/mod.rs @@ -55,6 +55,12 @@ impl StandardDependencies { } } +impl Default for StandardDependencies { + fn default() -> Self { + Self::new() + } +} + impl<'a> Dependencies<'a> for StandardDependencies { fn get_output(&'a self) -> &'a RefCell { self.output.as_ref() @@ -91,12 +97,13 @@ fn parse_args(args: &[&str]) -> Result> { } let matcher = matchers::build_top_level_matcher(&args[i..], &mut config)?; Ok(ParsedInfo { - matcher: matcher, - paths: paths, - config: config, + matcher, + paths, + config, }) } +#[allow(clippy::borrowed_box)] // FIXME? fn process_dir<'a>( dir: &str, config: &Config, diff --git a/src/testing/commandline/main.rs b/src/testing/commandline/main.rs index 447f767..b28362e 100644 --- a/src/testing/commandline/main.rs +++ b/src/testing/commandline/main.rs @@ -44,8 +44,10 @@ fn main() { if args.len() < 2 || args[1] == "-h" || args[1] == "--help" { usage(); } - let mut config = Config::default(); - config.destination_dir = args[1].clone(); + let mut config = Config { + destination_dir: args[1].clone(), + ..Default::default() + }; for arg in &args[2..] { if arg.starts_with("--") { match arg.as_ref() {