Skip to content

Commit ab94e64

Browse files
style(rust): clear cargo clippy -- -D warnings (the other half of Build Check) (#85)
## Why `Build Check` runs **`cargo fmt --check` then `cargo clippy -- -D warnings`** (`.github/workflows/security.yml:72-74`). On `main` the *fmt* step failed first and **masked 31 pre-existing clippy errors**. PR #84 fixes fmt; this PR clears the clippy half so the gate goes fully green. **Stacked on #84** (base = `claude/fix-rustfmt-nonconformity`) so this PR's diff is **clippy-only** and its own `Build Check` can pass (it needs the fmt fix present to get past the fmt step). When #84 merges, GitHub auto-retargets this to `main`. ## What - **Machine-applicable lints** via `cargo clippy --fix` across ~16 files (needless borrows/clones, redundant `to_owned`, single-char string patterns, `unused_enumerate_index`, …). - **Hand-fixed** the non-machine-applicable ones — all semantics-preserving: - `while_let_loop` → `src/interpreter/value.rs` - `manual_strip` ×2 → `src/stdlib/net.rs` (`strip_prefix`) - `needless_range_loop` → `src/stdlib/time.rs` (`.iter().take(..)`) - `collapsible_match` → `src/typechecker/mod.rs` - `unnecessary_to_owned` → `src/sexpr.rs` - `wildcard_in_or_patterns` → `src/main.rs` - **`dead_code` scaffolding silenced, NOT deleted** (your call) with `#[allow(dead_code)]` + a comment, since these look like reserved scaffolding: - `Precedence::Primary` (parser), `Parser::peek_next` (lookahead helper), `vm::compiler` `Local.depth` (scope tracking). - If you'd rather **delete** any of these, say so and I'll swap the allow for removal. ## Verified locally - `cargo fmt --check` — clean - `cargo clippy -- -D warnings` — **exit 0** - `cargo test --lib` — **173/173 pass** (confirms the collapse/while-let/strip_prefix edits didn't change behavior) ⚠️ One caveat: local clippy is **1.94.1** while CI floats to **1.96.0** (no toolchain pin; `.tool-versions` = `rust stable`). The fixes are forward-compatible, but if 1.96 introduces a lint 1.94 doesn't flag, CI may surface one more — I'll chase it if so. (A `rust-toolchain.toml` pin would prevent this class of drift — worth a follow-up.) https://claude.ai/code/session_013wg3Mtq2QFhYi4XVw1Z6z7 --- _Generated by [Claude Code](https://claude.ai/code/session_013wg3Mtq2QFhYi4XVw1Z6z7)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent dccad8f commit ab94e64

19 files changed

Lines changed: 51 additions & 56 deletions

File tree

src/bin/woke-lsp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn main() {
1717
let stdin = tokio::io::stdin();
1818
let stdout = tokio::io::stdout();
1919

20-
let (service, socket) = LspService::new(|client| Backend::new(client));
20+
let (service, socket) = LspService::new(Backend::new);
2121

2222
eprintln!("WokeLang LSP Server initialized");
2323

src/bin/wokelang-dap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use std::io::{BufRead, BufReader, Write};
66
use std::net::{TcpListener, TcpStream};
7-
use wokelang::dap::{DapRequest, DapResponse, DapServer};
7+
use wokelang::dap::{DapRequest, DapServer};
88

99
fn main() -> Result<(), Box<dyn std::error::Error>> {
1010
let listener = TcpListener::bind("127.0.0.1:4712")?;

src/dap/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
use serde::{Deserialize, Serialize};
88
use std::collections::HashMap;
9-
use std::path::PathBuf;
109

1110
#[derive(Debug, Serialize, Deserialize)]
1211
pub struct DapRequest {
@@ -121,6 +120,12 @@ pub struct DapServer {
121120
pub variables: HashMap<String, String>,
122121
}
123122

123+
impl Default for DapServer {
124+
fn default() -> Self {
125+
Self::new()
126+
}
127+
}
128+
124129
impl DapServer {
125130
pub fn new() -> Self {
126131
Self {

src/formatter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! Provides AST-based code formatting with consistent style.
77
88
use crate::ast::{Expr, Program, Statement, TopLevelItem};
9-
use crate::lexer::{Lexer, Spanned};
9+
use crate::lexer::Lexer;
1010
use crate::parser::Parser;
1111

1212
/// Formatter for WokeLang code
@@ -96,7 +96,7 @@ impl Formatter {
9696
output.push_str(&self.format_expr(&expr.node));
9797
output.push_str(";\n");
9898
}
99-
Statement::Return(ret_stmt) => {
99+
Statement::Return(_ret_stmt) => {
100100
output.push_str(&indent_str);
101101
output.push_str("give back ...;\n");
102102
}

src/interpreter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl Interpreter {
776776
})
777777
}
778778
_ => Err(RuntimeError {
779-
message: format!("Cannot access field of non-record value"),
779+
message: "Cannot access field of non-record value".to_string(),
780780
}),
781781
}
782782
}

src/interpreter/value.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,9 @@ impl ChannelHandle {
180180
let receiver = self.receiver.lock().unwrap();
181181
let mut count = 0usize;
182182
let mut drained = Vec::new();
183-
loop {
184-
match receiver.try_recv() {
185-
Ok(val) => {
186-
drained.push(val);
187-
count += 1;
188-
}
189-
Err(_) => break,
190-
}
183+
while let Ok(val) = receiver.try_recv() {
184+
drained.push(val);
185+
count += 1;
191186
}
192187
// Put them back via the sender
193188
for val in drained {

src/linter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Linter {
8383

8484
fn lint_function(&mut self, func: &FunctionDef) {
8585
// Check function name style
86-
if !func.name.chars().next().map_or(false, |c| c.is_lowercase()) {
86+
if !func.name.chars().next().is_some_and(|c| c.is_lowercase()) {
8787
self.diagnostics.push(Diagnostic {
8888
severity: Severity::Warning,
8989
message: format!("Function '{}' should start with lowercase", func.name),

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ fn parse_file(file: &PathBuf, format: &str) -> Result<()> {
402402
"sexpr" | "sexp" => {
403403
println!("{}", sexpr::program_to_sexpr(&program));
404404
}
405-
"pretty" | _ => {
405+
// "pretty" is the default for any unrecognised format
406+
_ => {
406407
println!("{:#?}", program);
407408
println!(
408409
"\nParsed {} top-level items successfully.",

src/parser/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ enum Precedence {
5555
Factor = 6, // * / %
5656
Unary = 7, // - not
5757
Call = 8, // f(x) arr[i]
58+
// Highest precedence; kept for ladder completeness (not constructed directly yet).
59+
#[allow(dead_code)]
5860
Primary = 9,
5961
}
6062

@@ -97,6 +99,7 @@ impl<'a> Parser<'a> {
9799
}
98100

99101
/// Peek at next token (lookahead)
102+
#[allow(dead_code)] // lookahead helper retained for upcoming grammar rules
100103
fn peek_next(&self) -> &Token {
101104
if self.current + 1 < self.tokens.len() {
102105
&self.tokens[self.current + 1].value
@@ -199,7 +202,7 @@ impl<'a> Parser<'a> {
199202
}
200203

201204
fn parse_precedence(&mut self, precedence: Precedence) -> Result<Spanned<Expr>, ParseError> {
202-
let start = self.current_span().start;
205+
let _start = self.current_span().start;
203206

204207
// Parse prefix expression
205208
let mut expr = self.parse_prefix()?;
@@ -711,7 +714,7 @@ impl<'a> Parser<'a> {
711714
while !matches!(self.peek(), Token::RBrace) && !self.is_at_end() {
712715
stmts.push(self.parse_statement()?);
713716
}
714-
let end_span = self.expect(Token::RBrace, "}")?;
717+
let _end_span = self.expect(Token::RBrace, "}")?;
715718
Some(stmts)
716719
} else {
717720
None
@@ -989,7 +992,7 @@ impl<'a> Parser<'a> {
989992
self.advance();
990993

991994
// Check if it's a constructor pattern (capitalized identifier followed by optional parens)
992-
if name.chars().next().map_or(false, |c| c.is_uppercase()) {
995+
if name.chars().next().is_some_and(|c| c.is_uppercase()) {
993996
if self.match_tokens(&[Token::LParen]) {
994997
let inner = self.parse_pattern()?;
995998
self.expect(Token::RParen, ")")?;

src/security/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl CapabilityRegistry {
218218

219219
self.capabilities
220220
.entry(scope.to_string())
221-
.or_insert_with(Vec::new)
221+
.or_default()
222222
.push(entry);
223223

224224
self.audit(capability, AuditAction::Granted, scope, true);
@@ -237,7 +237,7 @@ impl CapabilityRegistry {
237237

238238
self.capabilities
239239
.entry(scope.to_string())
240-
.or_insert_with(Vec::new)
240+
.or_default()
241241
.push(entry);
242242

243243
self.audit(capability, AuditAction::Granted, scope, true);

0 commit comments

Comments
 (0)