You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check.rs 760B

Fix clippy warnings (#744) Clippy is returning some warnings. Let's fix or explicitly ignore them. In particular: - In `components/imageproc/src/lib.rs`, we implement `Hash` explicitly but derive `PartialEq`. We need to maintain the property that two keys being equal implies the hashes of those two keys are equal. Our `Hash` implementations preserve this, so we'll explicitly ignore the warnings. - In `components/site/src/lib.rs`, we were calling `.into()` on some values that are already of the correct type. - In `components/site/src/lib.rs`, we were using `.map(|x| *x)` in iterator chains to remove a level of indirection; we can instead say `.copied()` (introduced in Rust v1.36) or `.cloned()`. Using `.copied` here is better from a type-checking point of view, but we'll use `.cloned` for now as Rust v1.36 was only recently released. - In `components/templates/src/filters.rs` and `components/utils/src/site.rs`, we were taking `HashMap`s as function arguments but not generically accepting alternate `Hasher` implementations. - In `src/cmd/check.rs`, we use `env::current_dir()` as a default value, but our use of `unwrap_or` meant that we would always retrieve the current directory even when not needed. - In `components/errors/src/lib.rs`, we can use `if let` rather than `match`. - In `components/library/src/content/page.rs`, we can collapse a nested conditional into `else if let ...`. - In `components/library/src/sorting.rs`, a function takes `&&Page` arguments. Clippy warns about this for efficiency reasons, but we're doing it here to match a particular sorting API, so we'll explicitly ignore the warning.
4 years ago
123456789101112131415161718192021222324
  1. use std::env;
  2. use std::path::PathBuf;
  3. use errors::Result;
  4. use site::Site;
  5. use console;
  6. pub fn check(config_file: &str, base_path: Option<&str>, base_url: Option<&str>) -> Result<()> {
  7. let bp = base_path.map(PathBuf::from).unwrap_or_else(|| env::current_dir().unwrap());
  8. let mut site = Site::new(bp, config_file)?;
  9. // Force the checking of external links
  10. site.config.check_external_links = true;
  11. // Disable syntax highlighting since the results won't be used
  12. // and this operation can be expensive.
  13. site.config.highlight_code = false;
  14. if let Some(b) = base_url {
  15. site.set_base_url(b.to_string());
  16. }
  17. site.load()?;
  18. console::notify_site_size(&site);
  19. console::warn_about_ignored_pages(&site);
  20. Ok(())
  21. }