Skip to content

Commit

Permalink
Fix clippy lint warnings (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
bemyak authored Jun 4, 2022
1 parent e9e6cad commit 6989eb7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 60 deletions.
6 changes: 3 additions & 3 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ bar = "baz"
"#;
let theme = Theme::parse(theme_str).unwrap();
// We expect an error here
assert!(!config.add_theme_extra(&theme).is_ok());
assert!(config.add_theme_extra(&theme).is_err());
}

#[test]
Expand Down Expand Up @@ -714,7 +714,7 @@ highlight_theme = "asdf"
"#;

let config = Config::parse(config);
assert_eq!(config.is_err(), true);
assert!(config.is_err());
}

#[test]
Expand All @@ -728,7 +728,7 @@ highlight_themes_css = [
"#;

let config = Config::parse(config);
assert_eq!(config.is_err(), true);
assert!(config.is_err());
}

// https://github.com/getzola/zola/issues/1687
Expand Down
27 changes: 5 additions & 22 deletions components/content/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();

let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
Expand All @@ -591,11 +587,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();

let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
Expand All @@ -619,11 +611,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();

let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
Expand All @@ -649,11 +637,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();

let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
Expand Down Expand Up @@ -682,8 +666,7 @@ And here's another. [^2]
let mut config = Config::default();
config.ignored_content_globset = Some(gsb.build().unwrap());

let res =
Page::from_file(nested_path.join("index.md").as_path(), &config, &path.to_path_buf());
let res = Page::from_file(nested_path.join("index.md").as_path(), &config, path);

assert!(res.is_ok());
let page = res.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions components/content/src/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", None);
let page3 = create_page_with_date("2019-01-01", None);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::Date);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::Date);
assert_eq!(pages[0], page3.file.path);
assert_eq!(pages[1], page1.file.path);
assert_eq!(pages[2], page2.file.path);
Expand All @@ -87,7 +87,7 @@ mod tests {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", Some("2022-02-01"));
let page3 = create_page_with_date("2019-01-01", None);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::UpdateDate);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::UpdateDate);
assert_eq!(pages[0], page2.file.path);
assert_eq!(pages[1], page3.file.path);
assert_eq!(pages[2], page1.file.path);
Expand All @@ -99,7 +99,7 @@ mod tests {
let page1 = create_page_with_weight(2);
let page2 = create_page_with_weight(3);
let page3 = create_page_with_weight(1);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::Weight);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::Weight);
// Should be sorted by weight
assert_eq!(pages[0], page3.file.path);
assert_eq!(pages[1], page1.file.path);
Expand All @@ -123,7 +123,7 @@ mod tests {
];
let pages: Vec<Page> = titles.iter().map(|title| create_page_with_title(title)).collect();
let (sorted_pages, ignored_pages) =
sort_pages(&pages.iter().map(|p| p).collect::<Vec<_>>(), SortBy::Title);
sort_pages(&pages.iter().collect::<Vec<_>>(), SortBy::Title);
// Should be sorted by title in lexical order
let sorted_titles: Vec<_> = sorted_pages
.iter()
Expand Down Expand Up @@ -153,7 +153,7 @@ mod tests {
fn can_find_ignored_pages() {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_weight(1);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2], SortBy::Date);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2], SortBy::Date);
assert_eq!(pages[0], page1.file.path);
assert_eq!(ignored_pages.len(), 1);
assert_eq!(ignored_pages[0], page2.file.path);
Expand Down
30 changes: 8 additions & 22 deletions components/content/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ mod tests {

let assets = find_related_assets(path, &Config::default(), true);
assert_eq!(assets.len(), 5);
assert_eq!(
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
5
);

for asset in
vec!["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"]
{
assert!(assets
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 5);

for asset in ["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"] {
assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
}
}

Expand All @@ -112,16 +104,10 @@ mod tests {
File::create(path.join("subdir").join("example.js")).unwrap();
let assets = find_related_assets(path, &Config::default(), false);
assert_eq!(assets.len(), 4);
assert_eq!(
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
4
);

for asset in vec!["example.js", "graph.jpg", "fail.png", "extensionless"] {
assert!(assets
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 4);

for asset in ["example.js", "graph.jpg", "fail.png", "extensionless"] {
assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
}
}
#[test]
Expand Down
10 changes: 5 additions & 5 deletions components/utils/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod tests {
let src_file_path = src_dir.path().join("test.txt");
let dest_file_path = dest_dir.path().join(src_file_path.strip_prefix(&base_path).unwrap());
File::create(&src_file_path).unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();

assert_eq!(
metadata(&src_file_path).and_then(|m| m.modified()).unwrap(),
Expand All @@ -207,7 +207,7 @@ mod tests {
let mut src_file = File::create(&src_file_path).unwrap();
src_file.write_all(b"file1").unwrap();
}
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
{
let mut dest_file = File::create(&dest_file_path).unwrap();
dest_file.write_all(b"file2").unwrap();
Expand All @@ -217,14 +217,14 @@ mod tests {
filetime::set_file_mtime(&src_file_path, filetime::FileTime::from_unix_time(0, 0)).unwrap();
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(0, 0))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file2");

// Copy occurs if the timestamps are different while the filesizes are same.
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(42, 42))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file1");

Expand All @@ -235,7 +235,7 @@ mod tests {
}
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(0, 0))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file1");
}
Expand Down
4 changes: 2 additions & 2 deletions components/utils/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ mod tests {
#[test]
fn template_fallback_is_successful() {
let mut tera = Tera::parse("test-templates/*.html").unwrap();
tera.add_raw_template(&"hyde/templates/index.html", "Hello").unwrap();
tera.add_raw_template(&"hyde/templates/theme-only.html", "Hello").unwrap();
tera.add_raw_template("hyde/templates/index.html", "Hello").unwrap();
tera.add_raw_template("hyde/templates/theme-only.html", "Hello").unwrap();

// Check finding existing template
assert_eq!(check_template_fallbacks("index.html", &tera, &None), Some("index.html"));
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod prompt;
fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
let root_dir = dir
.ancestors()
.find_map(|a| if a.join(&config_path).exists() { Some(a) } else { None })
.find(|a| a.join(&config_path).exists())
.unwrap_or_else(|| panic!("could not find directory containing config file"));

// if we got here we found root_dir so config file should exist so we can unwrap safely
Expand Down

0 comments on commit 6989eb7

Please sign in to comment.