Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Dec 2, 2022
1 parent 1d75511 commit 9d48e75
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion clippy.toml

This file was deleted.

6 changes: 1 addition & 5 deletions src/content/mod.rs
Expand Up @@ -224,11 +224,7 @@ impl Content {

/// Returns true if the value is nil.
pub fn is_nil(&self) -> bool {
if let Content::None | Content::Unit = self.resolve_inner() {
true
} else {
false
}
matches!(self.resolve_inner(), Content::None | Content::Unit)
}

/// Returns the value as bool
Expand Down
2 changes: 1 addition & 1 deletion src/glob.rs
Expand Up @@ -71,7 +71,7 @@ pub fn glob_exec<F: FnMut(&Path)>(base: &Path, pattern: &str, mut f: F) {
continue;
}

settings.set_input_file(&path);
settings.set_input_file(path);
settings.set_snapshot_suffix(path.file_name().unwrap().to_str().unwrap());

settings.bind(|| {
Expand Down
15 changes: 9 additions & 6 deletions src/redaction.rs
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
use crate::content::Content;

#[derive(Debug)]
pub struct SelectorParseError(pest::error::Error<Rule>);
pub struct SelectorParseError(Box<pest::error::Error<Rule>>);

impl SelectorParseError {
/// Return the column of where the error occurred.
Expand Down Expand Up @@ -244,6 +244,7 @@ pub struct Selector<'a> {
impl<'a> Selector<'a> {
pub fn parse(selector: &'a str) -> Result<Selector<'a>, SelectorParseError> {
let pair = SelectParser::parse(Rule::selectors, selector)
.map_err(Box::new)
.map_err(SelectorParseError)?
.next()
.unwrap();
Expand All @@ -262,11 +263,13 @@ impl<'a> Selector<'a> {
Rule::wildcard => Segment::Wildcard,
Rule::deep_wildcard => {
if have_deep_wildcard {
return Err(SelectorParseError(pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError {
message: "deep wildcard used twice".into(),
},
segment_pair.as_span(),
return Err(SelectorParseError(Box::new(
pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError {
message: "deep wildcard used twice".into(),
},
segment_pair.as_span(),
),
)));
}
have_deep_wildcard = true;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.rs
Expand Up @@ -183,7 +183,7 @@ fn get_snapshot_filename(
write!(
&mut f,
"{}.snap",
snapshot_name.replace('/', "__").replace('\\', "__")
snapshot_name.replace(&['/', '\\'][..], "__")
)
.unwrap();
f
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Expand Up @@ -579,7 +579,7 @@ impl Settings {

/// Runs a function with the current settings.
pub(crate) fn with<R, F: FnOnce(&Settings) -> R>(f: F) -> R {
CURRENT_SETTINGS.with(|x| f(&*x.borrow()))
CURRENT_SETTINGS.with(|x| f(&x.borrow()))
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/snapshot.rs
Expand Up @@ -57,7 +57,7 @@ impl PendingInlineSnapshot {
}

pub fn save_batch(p: &Path, batch: &[PendingInlineSnapshot]) -> Result<(), Box<dyn Error>> {
fs::remove_file(&p).ok();
fs::remove_file(p).ok();
for snap in batch {
snap.save(p)?;
}
Expand Down Expand Up @@ -426,9 +426,9 @@ impl Snapshot {

fn save_with_metadata(&self, path: &Path, md: &MetaData) -> Result<(), Box<dyn Error>> {
if let Some(folder) = path.parent() {
fs::create_dir_all(&folder)?;
fs::create_dir_all(folder)?;
}
let mut f = fs::File::create(&path)?;
let mut f = fs::File::create(path)?;
let blob = yaml::to_string(&md.as_content());
f.write_all(blob.as_bytes())?;
f.write_all(b"---\n")?;
Expand Down Expand Up @@ -604,9 +604,8 @@ fn get_inline_snapshot_value(frozen_value: &str) -> String {
}
}
if let Some(remainder) = line.get(indentation..) {
if remainder.starts_with('⋮') {
// 3 because '⋮' is three utf-8 bytes long
buf.push_str(&remainder[3..]);
if let Some(rest) = remainder.strip_prefix('⋮') {
buf.push_str(rest);
buf.push('\n');
} else if remainder.trim().is_empty() {
continue;
Expand Down

0 comments on commit 9d48e75

Please sign in to comment.