Skip to content

Commit

Permalink
Merge pull request stoically#12 from rs-tml/clippy_enhance
Browse files Browse the repository at this point in the history
clippy ci
  • Loading branch information
dj8yfo committed May 19, 2023
2 parents 4e02a53 + b1f000d commit d0d2b65
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
7 changes: 6 additions & 1 deletion .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ test() {
echo "git-hooks: Fmt check failed, stop pushing"
return $RESULT
fi
cargo +stable test
cargo +stable test --workspace
RESULT=$?
if [[ "$RESULT" -ne 0 ]]; then
echo "git-hooks: Test failed, stop pushing"
fi
cargo +stable clippy --workspace
RESULT=$?
if [[ "$RESULT" -ne 0 ]]; then
echo "git-hooks: clippy failed, stop pushing"
fi
return $RESULT
}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
run: cargo build

- name: test
run: |
cargo test
cd examples/html-to-string-macro
cargo test
run: cargo test --workspace

- name: clippy
run: cargo clippy --workspace

- name: coverage
run: |
Expand Down
5 changes: 2 additions & 3 deletions examples/html-to-string-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'a> WalkNodesOutput<'a> {
}
}

fn walk_nodes<'a>(nodes: &'a Vec<Node>) -> WalkNodesOutput<'a> {
fn walk_nodes(nodes: &Vec<Node>) -> WalkNodesOutput<'_> {
let mut out = WalkNodesOutput::default();

for node in nodes {
Expand All @@ -56,8 +56,7 @@ fn walk_nodes<'a>(nodes: &'a Vec<Node>) -> WalkNodesOutput<'a> {
out.values.push(block.to_token_stream());
}
NodeAttribute::Attribute(attribute) => {
out.static_format
.push_str(&format!(" {}", attribute.key.to_string()));
out.static_format.push_str(&format!(" {}", attribute.key));
if let Some(value) = attribute.value() {
out.static_format.push_str(r#"="{}""#);
out.values.push(value.to_token_stream());
Expand Down
2 changes: 1 addition & 1 deletion src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Node {
.collect::<Vec<_>>();

std::iter::once(self)
.chain(children.into_iter().map(Self::flatten).flatten())
.chain(children.into_iter().flat_map(Self::flatten))
.collect()
}
/// Get the type of the node.
Expand Down
2 changes: 1 addition & 1 deletion src/node/node_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Parse for NodeName {
let fork = &input.fork();
let value = block_expr(fork)?;
input.advance_to(fork);
Ok(NodeName::Block(value.into()))
Ok(NodeName::Block(value))
} else if input.peek(Ident::peek_any) {
let mut segments = Punctuated::new();
let ident = Ident::parse_any(input)?;
Expand Down
4 changes: 2 additions & 2 deletions src/node/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ParseRecoverable for NodeBlock {
let block = match parse_valid_block_expr(parser, &fork) {
Ok(value) => {
input.advance_to(&fork);
NodeBlock::ValidBlock(value.into())
NodeBlock::ValidBlock(value)
}
Err(e) if parser.config().recover_block => {
parser.push_diagnostic(e);
Expand Down Expand Up @@ -202,7 +202,7 @@ impl ParseRecoverable for NodeElement {
parser.push_diagnostic(diagnostic);
return Some(NodeElement {
open_tag,
children: children,
children,
close_tag: None,
});
};
Expand Down
7 changes: 3 additions & 4 deletions src/node/raw_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl RawText {
};
span = Some(joined);
}
return span;
span
}

pub fn is_empty(&self) -> bool {
Expand All @@ -96,9 +96,8 @@ impl RawText {
.collect();

for (spans, children) in spans.windows(3).zip(&mut children) {
match children {
Node::RawText(t) => t.set_tag_spans(spans[0], spans[2]),
_ => {}
if let Node::RawText(t) = children {
t.set_tag_spans(spans[0], spans[2])
}
}
children
Expand Down
6 changes: 2 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl Parser {
let mut parser = RecoverableContext::new(self.config.clone().into());
while !input.cursor().eof() {
let Some(parsed_node) = Node::parse_recoverable(&mut parser, input) else {
parser.push_diagnostic(input.error(format!(
"Node parse failed"
)));
parser.push_diagnostic(input.error("Node parse failed".to_string()));
break;
};

Expand Down Expand Up @@ -102,7 +100,7 @@ impl Parser {
}

let nodes = if self.config.flat_tree {
nodes.into_iter().map(Node::flatten).flatten().collect()
nodes.into_iter().flat_map(Node::flatten).collect()
} else {
nodes
};
Expand Down
10 changes: 5 additions & 5 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ test_unquoted!(
assert!(v.close_tag.is_none());
assert_eq!(v.open_tag.name.to_string(), "div");

assert!(v.attributes().len() == 0 );
assert!(v.children.len() == 0 );
assert!(v.attributes().is_empty() );
assert!(v.children.is_empty() );
};
block => "{ x + 1 }" => Node::Block(v) => {
// check that block valid
Expand All @@ -147,13 +147,13 @@ test_unquoted!(
assert!(v.close_tag.is_some());
assert_eq!(v.open_tag.name.to_string(), "div");

assert!(v.attributes().len() == 0 );
assert!(v.attributes().is_empty() );
assert!(v.children.len() == 1 );
let Node::Element(child) = v.children[0].clone() else {
panic!("Not a element")
};
assert!(child.attributes().len() == 0 );
assert!(child.children.len() == 0 );
assert!(child.attributes().is_empty() );
assert!(child.children.is_empty() );
assert_eq!(child.open_tag.name.to_string(), "basd");
assert!(child.close_tag.is_none());
};
Expand Down

0 comments on commit d0d2b65

Please sign in to comment.