Merge pull request #1214 from ehuss/fix-clippy
Fix some clippy warnings.
This commit is contained in:
commit
8ee950e3de
|
@ -5,6 +5,7 @@
|
||||||
//!
|
//!
|
||||||
//! [1]: ../index.html
|
//! [1]: ../index.html
|
||||||
|
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod book;
|
mod book;
|
||||||
mod init;
|
mod init;
|
||||||
mod summary;
|
mod summary;
|
||||||
|
@ -126,8 +127,6 @@ impl MDBook {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use mdbook::MDBook;
|
/// # use mdbook::MDBook;
|
||||||
/// # use mdbook::book::BookItem;
|
/// # use mdbook::book::BookItem;
|
||||||
/// # #[allow(unused_variables)]
|
|
||||||
/// # fn main() {
|
|
||||||
/// # let book = MDBook::load("mybook").unwrap();
|
/// # let book = MDBook::load("mybook").unwrap();
|
||||||
/// for item in book.iter() {
|
/// for item in book.iter() {
|
||||||
/// match *item {
|
/// match *item {
|
||||||
|
@ -143,7 +142,6 @@ impl MDBook {
|
||||||
/// // 2. Chapter 2
|
/// // 2. Chapter 2
|
||||||
/// //
|
/// //
|
||||||
/// // etc.
|
/// // etc.
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn iter(&self) -> BookItems<'_> {
|
pub fn iter(&self) -> BookItems<'_> {
|
||||||
self.book.iter()
|
self.book.iter()
|
||||||
|
@ -405,7 +403,7 @@ fn interpret_custom_preprocessor(key: &str, table: &Value) -> Box<CmdPreprocesso
|
||||||
.map(ToString::to_string)
|
.map(ToString::to_string)
|
||||||
.unwrap_or_else(|| format!("mdbook-{}", key));
|
.unwrap_or_else(|| format!("mdbook-{}", key));
|
||||||
|
|
||||||
Box::new(CmdPreprocessor::new(key.to_string(), command.to_string()))
|
Box::new(CmdPreprocessor::new(key.to_string(), command))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
|
fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
|
||||||
|
@ -418,7 +416,7 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
|
||||||
|
|
||||||
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
|
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
|
||||||
|
|
||||||
Box::new(CmdRenderer::new(key.to_string(), command.to_string()))
|
Box::new(CmdRenderer::new(key.to_string(), command))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether we should run a particular `Preprocessor` in combination
|
/// Check whether we should run a particular `Preprocessor` in combination
|
||||||
|
|
|
@ -281,7 +281,7 @@ impl<'a> SummaryParser<'a> {
|
||||||
} else {
|
} else {
|
||||||
Ok(Link {
|
Ok(Link {
|
||||||
name,
|
name,
|
||||||
location: PathBuf::from(href.to_string()),
|
location: PathBuf::from(href),
|
||||||
number: None,
|
number: None,
|
||||||
nested_items: Vec::new(),
|
nested_items: Vec::new(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
//! assert_eq!(got, Some(PathBuf::from("./themes")));
|
//! assert_eq!(got, Some(PathBuf::from("./themes")));
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! # fn main() { run().unwrap() }
|
//! # run().unwrap()
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
|
#![allow(clippy::comparison_chain)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|
|
@ -75,8 +75,7 @@ fn find_chapter(
|
||||||
// Skip things like "spacer"
|
// Skip things like "spacer"
|
||||||
chapter.contains_key("path")
|
chapter.contains_key("path")
|
||||||
})
|
})
|
||||||
.skip(1)
|
.nth(1)
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
Some(chapter) => return Ok(Some(chapter.clone())),
|
Some(chapter) => return Ok(Some(chapter.clone())),
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl HelperDef for RenderToc {
|
||||||
.evaluate(ctx, "@root/path")?
|
.evaluate(ctx, "@root/path")?
|
||||||
.as_json()
|
.as_json()
|
||||||
.as_str()
|
.as_str()
|
||||||
.ok_or(RenderError::new("Type error for `path`, string expected"))?
|
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
|
||||||
.replace("\"", "");
|
.replace("\"", "");
|
||||||
|
|
||||||
let current_section = rc
|
let current_section = rc
|
||||||
|
@ -46,17 +46,13 @@ impl HelperDef for RenderToc {
|
||||||
.evaluate(ctx, "@root/fold_enable")?
|
.evaluate(ctx, "@root/fold_enable")?
|
||||||
.as_json()
|
.as_json()
|
||||||
.as_bool()
|
.as_bool()
|
||||||
.ok_or(RenderError::new(
|
.ok_or_else(|| RenderError::new("Type error for `fold_enable`, bool expected"))?;
|
||||||
"Type error for `fold_enable`, bool expected",
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let fold_level = rc
|
let fold_level = rc
|
||||||
.evaluate(ctx, "@root/fold_level")?
|
.evaluate(ctx, "@root/fold_level")?
|
||||||
.as_json()
|
.as_json()
|
||||||
.as_u64()
|
.as_u64()
|
||||||
.ok_or(RenderError::new(
|
.ok_or_else(|| RenderError::new("Type error for `fold_level`, u64 expected"))?;
|
||||||
"Type error for `fold_level`, u64 expected",
|
|
||||||
))?;
|
|
||||||
|
|
||||||
out.write("<ol class=\"chapter\">")?;
|
out.write("<ol class=\"chapter\">")?;
|
||||||
|
|
||||||
|
@ -75,18 +71,15 @@ impl HelperDef for RenderToc {
|
||||||
("", 1)
|
("", 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_expanded = {
|
let is_expanded =
|
||||||
if !fold_enable {
|
if !fold_enable || (!section.is_empty() && current_section.starts_with(section)) {
|
||||||
// Disable fold. Expand all chapters.
|
// Expand if folding is disabled, or if the section is an
|
||||||
true
|
// ancestor or the current section itself.
|
||||||
} else if !section.is_empty() && current_section.starts_with(section) {
|
|
||||||
// The section is ancestor or the current section itself.
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
// Levels that are larger than this would be folded.
|
// Levels that are larger than this would be folded.
|
||||||
level - 1 < fold_level as usize
|
level - 1 < fold_level as usize
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if level > current_level {
|
if level > current_level {
|
||||||
while level > current_level {
|
while level > current_level {
|
||||||
|
|
|
@ -152,34 +152,31 @@ impl CmdRenderer {
|
||||||
|
|
||||||
impl CmdRenderer {
|
impl CmdRenderer {
|
||||||
fn handle_render_command_error(&self, ctx: &RenderContext, error: io::Error) -> Result<()> {
|
fn handle_render_command_error(&self, ctx: &RenderContext, error: io::Error) -> Result<()> {
|
||||||
match error.kind() {
|
if let ErrorKind::NotFound = error.kind() {
|
||||||
ErrorKind::NotFound => {
|
// Look for "output.{self.name}.optional".
|
||||||
// Look for "output.{self.name}.optional".
|
// If it exists and is true, treat this as a warning.
|
||||||
// If it exists and is true, treat this as a warning.
|
// Otherwise, fail the build.
|
||||||
// Otherwise, fail the build.
|
|
||||||
|
|
||||||
let optional_key = format!("output.{}.optional", self.name);
|
let optional_key = format!("output.{}.optional", self.name);
|
||||||
|
|
||||||
let is_optional = match ctx.config.get(&optional_key) {
|
let is_optional = match ctx.config.get(&optional_key) {
|
||||||
Some(Value::Boolean(value)) => *value,
|
Some(Value::Boolean(value)) => *value,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_optional {
|
if is_optional {
|
||||||
warn!(
|
warn!(
|
||||||
"The command `{}` for backend `{}` was not found, \
|
"The command `{}` for backend `{}` was not found, \
|
||||||
but was marked as optional.",
|
but was marked as optional.",
|
||||||
self.cmd, self.name
|
self.cmd, self.name
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
"The command `{}` wasn't found, is the `{}` backend installed?",
|
"The command `{}` wasn't found, is the `{}` backend installed?",
|
||||||
self.cmd, self.name
|
self.cmd, self.name
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
Err(error).chain_err(|| "Unable to start the backend")?
|
Err(error).chain_err(|| "Unable to start the backend")?
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,8 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8])
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use std::path::Path;
|
/// # use std::path::Path;
|
||||||
/// # use mdbook::utils::fs::path_to_root;
|
/// # use mdbook::utils::fs::path_to_root;
|
||||||
/// #
|
|
||||||
/// # fn main() {
|
|
||||||
/// let path = Path::new("some/relative/path");
|
/// let path = Path::new("some/relative/path");
|
||||||
/// assert_eq!(path_to_root(path), "../../");
|
/// assert_eq!(path_to_root(path), "../../");
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// **note:** it's not very fool-proof, if you find a situation where
|
/// **note:** it's not very fool-proof, if you find a situation where
|
||||||
|
|
|
@ -43,11 +43,9 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(cap) = ANCHOR_START.captures(l) {
|
||||||
if let Some(cap) = ANCHOR_START.captures(l) {
|
if &cap["anchor_name"] == anchor {
|
||||||
if &cap["anchor_name"] == anchor {
|
anchor_found = true;
|
||||||
anchor_found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,16 +94,14 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(cap) = ANCHOR_START.captures(l) {
|
||||||
if let Some(cap) = ANCHOR_START.captures(l) {
|
if &cap["anchor_name"] == anchor {
|
||||||
if &cap["anchor_name"] == anchor {
|
within_anchored_section = true;
|
||||||
within_anchored_section = true;
|
|
||||||
}
|
|
||||||
} else if !ANCHOR_END.is_match(l) {
|
|
||||||
output.push_str("# ");
|
|
||||||
output.push_str(l);
|
|
||||||
output.push_str("\n");
|
|
||||||
}
|
}
|
||||||
|
} else if !ANCHOR_END.is_match(l) {
|
||||||
|
output.push_str("# ");
|
||||||
|
output.push_str(l);
|
||||||
|
output.push_str("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue