Skip to content

Commit

Permalink
Merge pull request #4026 from stacks-network/ci/enable-clippy
Browse files Browse the repository at this point in the history
Enable clippy in CI
  • Loading branch information
obycode committed Nov 2, 2023
2 parents 9668fb1 + 6315b17 commit 6f04ad8
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 37 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Disabled - this workflow needs more work so it's not incredibly chatty
##
## Perform Clippy checks - currently set to defaults
## https://github.com/rust-lang/rust-clippy#usage
## https://rust-lang.github.io/rust-clippy/master/index.html
Expand All @@ -17,10 +15,10 @@ on:
types:
- opened
- reopened
- synchronize

jobs:
clippy_check:
if: ${{ false }}
name: Clippy Check
runs-on: ubuntu-latest
steps:
Expand All @@ -41,4 +39,4 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
args: -p clarity -p libstackerdb -p pox-locking -p stacks-common --no-deps --tests --all-features -- -D warnings
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl CheckError {

pub fn set_expressions(&mut self, exprs: &[SymbolicExpression]) {
self.diagnostic.spans = exprs.iter().map(|e| e.span().clone()).collect();
self.expressions.replace(exprs.clone().to_vec());
self.expressions.replace(exprs.to_vec());
}
}

Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ fn test_response_inference() {
fn test_function_arg_names() {
use crate::vm::analysis::type_check;

let functions = vec![
let functions = [
"(define-private (test (x int)) (ok 0))
(define-public (test-pub (x int)) (ok 0))
(define-read-only (test-ro (x int)) (ok 0))",
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ fn test_response_inference(#[case] version: ClarityVersion, #[case] epoch: Stack
fn test_function_arg_names() {
use crate::vm::analysis::type_check;

let functions = vec![
let functions = [
"(define-private (test (x int)) (ok 0))
(define-public (test-pub (x int)) (ok 0))
(define-read-only (test-ro (x int)) (ok 0))",
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::vm::types::QualifiedContractIdentifier;
use crate::vm::ClarityVersion;

/// Legacy function
#[cfg(any(test, features = "testing"))]
#[cfg(any(test, feature = "testing"))]
pub fn parse(
contract_identifier: &QualifiedContractIdentifier,
source_code: &str,
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/ast/parser/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ lazy_static! {

static ref lex_matchers: Vec<LexMatcher> = vec![
LexMatcher::new(
r##"u"(?P<value>((\\")|([[ -~]&&[^"]]))*)""##,
r#"u"(?P<value>((\\")|([[ -~]&&[^"]]))*)""#,
TokenType::StringUTF8Literal,
),
LexMatcher::new(
r##""(?P<value>((\\")|([[ -~]&&[^"]]))*)""##,
r#""(?P<value>((\\")|([[ -~]&&[^"]]))*)""#,
TokenType::StringASCIILiteral,
),
LexMatcher::new(";;[ -~]*", TokenType::Whitespace), // ;; comments.
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/ast/parser/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'a> Parser<'a> {
Token::Rparen => {
span.end_line = token.span.end_line;
span.end_column = token.span.end_column;
let out_nodes: Vec<_> = nodes.drain(..).collect();
let out_nodes: Vec<_> = std::mem::take(nodes);
let mut e = PreSymbolicExpression::list(out_nodes.into_boxed_slice());
e.copy_span(span);
Ok(Some(e))
Expand All @@ -253,7 +253,7 @@ impl<'a> Parser<'a> {
)?;
span.end_line = token.span.end_line;
span.end_column = token.span.end_column;
let out_nodes: Vec<_> = nodes.drain(..).collect();
let out_nodes: Vec<_> = std::mem::take(nodes);
let mut e = PreSymbolicExpression::list(out_nodes.into_boxed_slice());
e.copy_span(span);
Ok(Some(e))
Expand Down
10 changes: 4 additions & 6 deletions stacks-common/src/types/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ impl PeerAddress {
/// order. Return None if this is not an IPv4 address.
pub fn ipv4_bits(&self) -> Option<u32> {
let octets_opt = self.ipv4_octets();
if octets_opt.is_none() {
return None;
}
octets_opt?;

let octets = octets_opt.unwrap();
Some(
Expand Down Expand Up @@ -291,8 +289,8 @@ impl FromStr for PeerHost {
// try as DNS-name:port
let host;
let port;
let parts: Vec<&str> = header.split(":").collect();
if parts.len() == 0 {
let parts: Vec<&str> = header.split(':').collect();
if parts.is_empty() {
return Err(Error::DecodeError(
"Failed to parse PeerHost: no parts".to_string(),
));
Expand All @@ -305,7 +303,7 @@ impl FromStr for PeerHost {
if parts[np - 1].chars().all(char::is_numeric) {
// ends in :port
let host_str = parts[0..np - 1].join(":");
if host_str.len() == 0 {
if host_str.is_empty() {
return Err(Error::DecodeError("Empty host".to_string()));
}
host = Some(host_str);
Expand Down
21 changes: 8 additions & 13 deletions stacks-common/src/util/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,20 +605,15 @@ pub fn hex_bytes(s: &str) -> Result<Vec<u8>, HexError> {
let mut v = vec![];
let mut iter = s.chars().pair();
// Do the parsing
iter.by_ref().fold(Ok(()), |e, (f, s)| {
if e.is_err() {
e
} else {
match (f.to_digit(16), s.to_digit(16)) {
(None, _) => Err(HexError::BadCharacter(f)),
(_, None) => Err(HexError::BadCharacter(s)),
(Some(f), Some(s)) => {
v.push((f * 0x10 + s) as u8);
Ok(())
}
iter.by_ref()
.try_fold((), |_, (f, s)| match (f.to_digit(16), s.to_digit(16)) {
(None, _) => Err(HexError::BadCharacter(f)),
(_, None) => Err(HexError::BadCharacter(s)),
(Some(f), Some(s)) => {
v.push((f * 0x10 + s) as u8);
Ok(())
}
}
})?;
})?;
// Check that there was no remainder
match iter.remainder() {
Some(_) => Err(HexError::BadLength(s.len())),
Expand Down
3 changes: 1 addition & 2 deletions stacks-common/src/util/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ fn make_logger() -> Logger {
let plain = slog_term::PlainSyncDecorator::new(slog_term::TestStdoutWriter);
let isatty = isatty(Stream::Stdout);
let drain = TermFormat::new(plain, false, debug, isatty);
let logger = Logger::root(drain.ignore_res(), o!());
logger
Logger::root(drain.ignore_res(), o!())
}
}

Expand Down
3 changes: 1 addition & 2 deletions stacks-common/src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,10 @@ macro_rules! impl_array_newtype {
}
}

#[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl
impl Clone for $thing {
#[inline]
fn clone(&self) -> $thing {
$thing::from(&self[..])
*self
}
}

Expand Down
3 changes: 1 addition & 2 deletions stacks-common/src/util/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ mod test {

#[test]
fn test_connection_pipe_producer_consumer() {
let mut buf = Vec::new();
buf.resize(1048576, 0);
let mut buf = vec![0; 1048576];

let mut rng = rand::thread_rng();
rng.fill_bytes(&mut buf);
Expand Down

0 comments on commit 6f04ad8

Please sign in to comment.