2019-05-27 12:05:07 +00:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use errors::Result;
|
|
|
|
use site::Site;
|
|
|
|
|
|
|
|
use console;
|
|
|
|
|
2019-06-02 18:21:06 +00:00
|
|
|
pub fn check(config_file: &str, base_path: Option<&str>, base_url: Option<&str>) -> Result<()> {
|
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.
2019-07-12 08:29:44 +00:00
|
|
|
let bp = base_path.map(PathBuf::from).unwrap_or_else(|| env::current_dir().unwrap());
|
2019-05-27 12:05:07 +00:00
|
|
|
let mut site = Site::new(bp, config_file)?;
|
|
|
|
// Force the checking of external links
|
2019-07-12 21:09:05 +00:00
|
|
|
site.config.enable_check_mode();
|
2019-05-27 12:05:07 +00:00
|
|
|
if let Some(b) = base_url {
|
|
|
|
site.set_base_url(b.to_string());
|
|
|
|
}
|
|
|
|
site.load()?;
|
2019-07-12 21:43:07 +00:00
|
|
|
console::check_site_summary(&site);
|
2019-05-27 12:05:07 +00:00
|
|
|
console::warn_about_ignored_pages(&site);
|
|
|
|
Ok(())
|
|
|
|
}
|