Add GitHub CI workflow and clippy fixes

This commit is contained in:
Chad Williamson
2021-01-01 10:42:44 -08:00
parent c58f70e0da
commit 3c35491e30
9 changed files with 108 additions and 38 deletions
+70
View File
@@ -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
+7 -7
View File
@@ -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
}
}
+4 -12
View File
@@ -26,9 +26,7 @@ pub struct AndMatcher {
impl AndMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> AndMatcher {
AndMatcher {
submatchers: submatchers,
}
AndMatcher { submatchers }
}
}
@@ -97,9 +95,7 @@ pub struct OrMatcher {
impl OrMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> OrMatcher {
OrMatcher {
submatchers: submatchers,
}
OrMatcher { submatchers }
}
}
@@ -189,9 +185,7 @@ pub struct ListMatcher {
impl ListMatcher {
pub fn new(submatchers: Vec<Box<dyn Matcher>>) -> ListMatcher {
ListMatcher {
submatchers: submatchers,
}
ListMatcher { submatchers }
}
}
@@ -331,9 +325,7 @@ pub struct NotMatcher {
impl NotMatcher {
pub fn new(submatcher: Box<dyn Matcher>) -> NotMatcher {
NotMatcher {
submatcher: submatcher,
}
NotMatcher { submatcher }
}
pub fn new_box(submatcher: Box<dyn Matcher>) -> Box<NotMatcher> {
+3 -3
View File
@@ -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 {
+7 -7
View File
@@ -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<dyn Error>> {
fn handle_char(&mut self, char: char) -> Result<(), Box<dyn Error>> {
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,
})
}
+1 -1
View File
@@ -78,7 +78,7 @@ impl SizeMatcher {
) -> Result<SizeMatcher, Box<dyn Error>> {
Ok(SizeMatcher {
unit: suffix_string.parse()?,
value_to_match: value_to_match,
value_to_match,
})
}
+2 -3
View File
@@ -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,
}
}
+10 -3
View File
@@ -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<dyn Write> {
self.output.as_ref()
@@ -91,12 +97,13 @@ fn parse_args(args: &[&str]) -> Result<ParsedInfo, Box<dyn Error>> {
}
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,
+4 -2
View File
@@ -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() {