Skip to content

Commit 13dea6b

Browse files
fix: resolve Clippy issues (#113)
1 parent ef66544 commit 13dea6b

3 files changed

Lines changed: 49 additions & 44 deletions

File tree

packages/mdbook-plugin-utils/src/markdown/block.rs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn parse_blocks<IsStartFn, IsEndFn>(
3333
is_start: IsStartFn,
3434
is_end: IsEndFn,
3535
skip_nested: bool,
36-
) -> Result<Vec<Block>>
36+
) -> Result<Vec<Block<'_>>>
3737
where
3838
IsStartFn: Fn(&Event) -> bool,
3939
IsEndFn: Fn(&Event) -> bool,
@@ -45,57 +45,58 @@ where
4545
debug!("{event:?} {span:?}");
4646

4747
if is_start(&event) {
48-
if let Some(block) = blocks.last_mut() {
49-
if !block.closed {
50-
if skip_nested {
51-
nested_level += 1;
52-
block.has_nested = true;
53-
block.events.push((event, span));
54-
continue;
55-
} else {
56-
bail!("Block is not closed. Nested blocks are not allowed.");
57-
}
48+
if let Some(block) = blocks.last_mut()
49+
&& !block.closed
50+
{
51+
if skip_nested {
52+
nested_level += 1;
53+
block.has_nested = true;
54+
block.events.push((event, span));
55+
continue;
56+
} else {
57+
bail!("Block is not closed. Nested blocks are not allowed.");
5858
}
5959
}
6060

6161
blocks.push(Block::new(event, span));
6262
} else if is_end(&event) {
63-
if let Some(block) = blocks.last_mut() {
64-
if !block.closed {
65-
if nested_level > 0 {
66-
nested_level -= 1;
67-
block.events.push((event, span));
68-
continue;
69-
}
70-
71-
block.closed = true;
72-
block.span = block.span.start..span.end;
63+
if let Some(block) = blocks.last_mut()
64+
&& !block.closed
65+
{
66+
if nested_level > 0 {
67+
nested_level -= 1;
7368
block.events.push((event, span));
69+
continue;
70+
}
7471

75-
let mut seen_first = false;
76-
block.events.retain(|(_, span)| {
77-
if !seen_first {
78-
seen_first = true;
79-
true
80-
} else if span.start == block.span.start && span.end != block.span.end {
81-
false
82-
} else {
83-
span.start >= block.span.start && span.end <= block.span.end
84-
}
85-
});
86-
87-
if let (Some((_, first)), Some((_, last))) = (
88-
block.events.get(1),
89-
block.events.get(block.events.len() - 2),
90-
) {
91-
block.inner_span = first.start..last.end;
72+
block.closed = true;
73+
block.span = block.span.start..span.end;
74+
block.events.push((event, span));
75+
76+
let mut seen_first = false;
77+
block.events.retain(|(_, span)| {
78+
if !seen_first {
79+
seen_first = true;
80+
true
81+
} else if span.start == block.span.start && span.end != block.span.end {
82+
false
83+
} else {
84+
span.start >= block.span.start && span.end <= block.span.end
9285
}
86+
});
87+
88+
if let (Some((_, first)), Some((_, last))) = (
89+
block.events.get(1),
90+
block.events.get(block.events.len() - 2),
91+
) {
92+
block.inner_span = first.start..last.end;
9393
}
9494
}
95-
} else if let Some(block) = blocks.last_mut() {
96-
if !block.closed && span.start >= block.span.start {
97-
block.events.push((event, span));
98-
}
95+
} else if let Some(block) = blocks.last_mut()
96+
&& !block.closed
97+
&& span.start >= block.span.start
98+
{
99+
block.events.push((event, span));
99100
}
100101
}
101102

packages/mdbook-plugin-utils/src/markdown/code_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn is_code_block_end(event: &Event) -> bool {
2424
matches!(event, Event::End(TagEnd::CodeBlock))
2525
}
2626

27-
pub fn parse_code_blocks<IsTagsFn>(content: &str, is_tags: IsTagsFn) -> Result<Vec<Block>>
27+
pub fn parse_code_blocks<IsTagsFn>(content: &str, is_tags: IsTagsFn) -> Result<Vec<Block<'_>>>
2828
where
2929
IsTagsFn: Fn(Vec<String>) -> bool + 'static,
3030
{

packages/mdbook-trunk/src/trunk.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ fn files(workspace: &Workspace, config: &Config) -> Result<String> {
8585

8686
header_elements.push(format!(
8787
"<button class=\"mdbook-trunk-file{}\" data-file=\"{}\">{}</button>",
88-
if config.show_files.unwrap_or(false) && index == 0 { " active" } else { Default::default() },
88+
if config.show_files.unwrap_or(false) && index == 0 {
89+
" active"
90+
} else {
91+
Default::default()
92+
},
8993
file,
9094
file_path
9195
.file_name()

0 commit comments

Comments
 (0)