From 8459f251b0463bcd78626a5807d7546fbffd8b8e Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Fri, 7 Jun 2024 10:39:39 +0300 Subject: [PATCH 1/2] Resolve Clippy warnings --- src/ast.rs | 2 +- src/ast/tokens.rs | 2 +- src/lib.rs | 2 +- src/tokenizer.rs | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 6698ef4..4cd749b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -49,7 +49,7 @@ mod support { } pub(super) fn token(parent: &N) -> Option { - children_tokens(parent).nth(0) + children_tokens(parent).next() } /// Token untyped diff --git a/src/ast/tokens.rs b/src/ast/tokens.rs index 362812f..5aae5cc 100644 --- a/src/ast/tokens.rs +++ b/src/ast/tokens.rs @@ -50,7 +50,7 @@ impl Comment { pub fn text(&self) -> &str { let text = self.syntax().text(); // Handle both "#..." and "/*...*/" comments. - match text.strip_prefix("#") { + match text.strip_prefix('#') { Some(s) => s, None => text.strip_prefix(r#"/*"#).unwrap().strip_suffix(r#"*/"#).unwrap(), } diff --git a/src/lib.rs b/src/lib.rs index 342ca21..5fe8ecd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ impl Parse { /// Return all errors in the tree, if any pub fn errors(&self) -> &[ParseError] { - &*self.errors + &self.errors } /// Either return the first error in the tree, or if there are none return self diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 4cc734c..e04db0f 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -136,7 +136,7 @@ impl Tokenizer<'_> { } Some('\\') => { self.next().unwrap(); - if let None = self.next() { + if self.next().is_none() { return TOKEN_ERROR; } } @@ -336,8 +336,8 @@ impl Tokenizer<'_> { ':' => TOKEN_COLON, ',' => TOKEN_COMMA, '.' => { - if self.peek().map_or(false, |x| ('0'..='9').contains(&x)) { - self.consume(|c| ('0'..='9').contains(&c)); + if self.peek().map_or(false, |x| x.is_ascii_digit()) { + self.consume(|c| c.is_ascii_digit()); self.consume_scientific() } else { TOKEN_DOT @@ -436,10 +436,10 @@ impl Tokenizer<'_> { TOKEN_STRING_START } '0'..='9' => { - self.consume(|c| ('0'..='9').contains(&c)); + self.consume(|c| c.is_ascii_digit()); if self.peek() == Some('.') { self.next().unwrap(); - self.consume(|c| ('0'..='9').contains(&c)); + self.consume(|c| c.is_ascii_digit()); self.consume_scientific() } else { TOKEN_INTEGER @@ -455,7 +455,7 @@ impl Tokenizer<'_> { if self.peek() == Some('-') || self.peek() == Some('+') { self.next().unwrap(); } - if self.consume(|c| ('0'..='9').contains(&c)) == 0 { + if self.consume(|c| c.is_ascii_digit()) == 0 { return TOKEN_ERROR; } } From dd9c66bc3912c0a6835c172cd0c8c64c952de2ca Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Fri, 7 Jun 2024 10:40:01 +0300 Subject: [PATCH 2/2] Add a CI step for running Clippy --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6aff05a..571e57f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,3 +63,23 @@ jobs: with: command: fmt args: --all -- --check + + clippy: + name: clippy + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + profile: minimal + components: clippy + + - name: Run Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy