Skip to content

Commit e6ac172

Browse files
committed
Fix: Resolve all remaining clippy warnings in nagari-compiler
- Fixed CI.yml malformed YAML and Windows compile command - Updated all format! macros to use modern inline variable syntax - Fixed error.rs, lexer.rs, parser.rs, types.rs, js_runtime.rs, lib.rs - Resolved uninlined_format_args, unnecessary_map_or, while_let_on_iterator, and format_in_format_args lints - All tests passing, CLI functionality preserved - Ready for successful CI/CD builds
1 parent f5703e2 commit e6ac172

File tree

7 files changed

+62
-66
lines changed

7 files changed

+62
-66
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ jobs:
6464
run: |
6565
./target/release/nag --version
6666
echo 'print("Hello from CI test!")' > test_ci.nag
67-
- name: Test CLI binary
68-
run: |
69-
./target/release/nag build test_ci.nag
67+
./target/release/nag build test_ci.nag
7068
7169
- name: Test CLI functionality (Windows)
7270
if: matrix.os == 'windows-latest'
7371
run: |
7472
.\target\release\nag.exe --version
7573
echo 'print("Hello from CI test!")' > test_ci.nag
76-
.\target\release\nag.exe compile test_ci.nag
74+
.\target\release\nag.exe build test_ci.nag
7775
7876
security:
7977
name: Security Audit

src/nagari-compiler/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ pub enum NagariError {
1212
impl fmt::Display for NagariError {
1313
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1414
match self {
15-
NagariError::LexError(msg) => write!(f, "Lexer error: {}", msg),
16-
NagariError::ParseError(msg) => write!(f, "Parser error: {}", msg),
17-
NagariError::TypeError(msg) => write!(f, "Type error: {}", msg),
18-
NagariError::BytecodeError(msg) => write!(f, "Bytecode generation error: {}", msg),
19-
NagariError::IoError(msg) => write!(f, "IO error: {}", msg),
15+
NagariError::LexError(msg) => write!(f, "Lexer error: {msg}"),
16+
NagariError::ParseError(msg) => write!(f, "Parser error: {msg}"),
17+
NagariError::TypeError(msg) => write!(f, "Type error: {msg}"),
18+
NagariError::BytecodeError(msg) => write!(f, "Bytecode generation error: {msg}"),
19+
NagariError::IoError(msg) => write!(f, "IO error: {msg}"),
2020
}
2121
}
2222
}

src/nagari-compiler/src/lexer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,25 +587,25 @@ impl Lexer {
587587
let mut value = String::new();
588588
value.push(first_char); // Include the first character that was already consumed
589589

590-
while self.peek().map_or(false, |c| c.is_ascii_digit()) {
590+
while self.peek().is_some_and(|c| c.is_ascii_digit()) {
591591
value.push(self.advance());
592592
}
593593

594-
if self.peek() == Some('.') && self.peek_next().map_or(false, |c| c.is_ascii_digit()) {
594+
if self.peek() == Some('.') && self.peek_next().is_some_and(|c| c.is_ascii_digit()) {
595595
value.push(self.advance()); // consume '.'
596596

597-
while self.peek().map_or(false, |c| c.is_ascii_digit()) {
597+
while self.peek().is_some_and(|c| c.is_ascii_digit()) {
598598
value.push(self.advance());
599599
}
600600

601601
let float_val = value
602602
.parse::<f64>()
603-
.map_err(|_| NagariError::LexError(format!("Invalid float literal: {}", value)))?;
603+
.map_err(|_| NagariError::LexError(format!("Invalid float literal: {value}")))?;
604604

605605
Ok(Token::FloatLiteral(float_val))
606606
} else {
607607
let int_val = value.parse::<i64>().map_err(|_| {
608-
NagariError::LexError(format!("Invalid integer literal: {}", value))
608+
NagariError::LexError(format!("Invalid integer literal: {value}"))
609609
})?;
610610

611611
Ok(Token::IntLiteral(int_val))
@@ -621,7 +621,7 @@ impl Lexer {
621621

622622
while self
623623
.peek()
624-
.map_or(false, |c| c.is_ascii_alphanumeric() || c == '_')
624+
.is_some_and(|c| c.is_ascii_alphanumeric() || c == '_')
625625
{
626626
value.push(self.advance());
627627
}

src/nagari-compiler/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Compiler {
9999
let mut lexer = Lexer::new(source);
100100
let tokens = lexer
101101
.tokenize()
102-
.map_err(|e| NagariError::LexError(format!("Lexing failed: {}", e)))?;
102+
.map_err(|e| NagariError::LexError(format!("Lexing failed: {e}")))?;
103103

104104
if self.config.verbose {
105105
println!("✅ Lexical analysis completed ({} tokens)", tokens.len());
@@ -109,7 +109,7 @@ impl Compiler {
109109
let mut parser = NagParser::new(tokens);
110110
let ast = parser
111111
.parse()
112-
.map_err(|e| NagariError::ParseError(format!("Parsing failed: {}", e)))?;
112+
.map_err(|e| NagariError::ParseError(format!("Parsing failed: {e}")))?;
113113

114114
if self.config.verbose {
115115
println!("✅ Parsing completed");
@@ -157,7 +157,7 @@ impl Compiler {
157157
}
158158

159159
let source = fs::read_to_string(input_path)
160-
.map_err(|e| NagariError::IoError(format!("Failed to read input file: {}", e)))?;
160+
.map_err(|e| NagariError::IoError(format!("Failed to read input file: {e}")))?;
161161

162162
let filename = input_path
163163
.file_name()
@@ -182,19 +182,19 @@ impl Compiler {
182182
}
183183

184184
let source = fs::read_to_string(input_path)
185-
.map_err(|e| NagariError::IoError(format!("Failed to read input file: {}", e)))?;
185+
.map_err(|e| NagariError::IoError(format!("Failed to read input file: {e}")))?;
186186

187187
// Lexical analysis
188188
let mut lexer = Lexer::new(&source);
189189
let tokens = lexer
190190
.tokenize()
191-
.map_err(|e| NagariError::LexError(format!("Lexing failed: {}", e)))?;
191+
.map_err(|e| NagariError::LexError(format!("Lexing failed: {e}")))?;
192192

193193
// Parsing
194194
let mut parser = NagParser::new(tokens);
195195
let ast = parser
196196
.parse()
197-
.map_err(|e| NagariError::ParseError(format!("Parsing failed: {}", e)))?;
197+
.map_err(|e| NagariError::ParseError(format!("Parsing failed: {e}")))?;
198198

199199
if self.config.verbose {
200200
println!("✅ Syntax check passed");
@@ -215,7 +215,7 @@ impl Compiler {
215215
// Create output directory if needed
216216
if let Some(parent) = output_path.parent() {
217217
fs::create_dir_all(parent).map_err(|e| {
218-
NagariError::IoError(format!("Failed to create output directory: {}", e))
218+
NagariError::IoError(format!("Failed to create output directory: {e}"))
219219
})?;
220220
}
221221

@@ -232,20 +232,20 @@ impl Compiler {
232232

233233
// Write JavaScript output
234234
fs::write(output_path, final_code)
235-
.map_err(|e| NagariError::IoError(format!("Failed to write output file: {}", e)))?;
235+
.map_err(|e| NagariError::IoError(format!("Failed to write output file: {e}")))?;
236236

237237
// Write source map if enabled
238238
if let Some(source_map) = result.source_map {
239239
let map_path = output_path.with_extension("js.map");
240240
fs::write(&map_path, source_map)
241-
.map_err(|e| NagariError::IoError(format!("Failed to write source map: {}", e)))?;
241+
.map_err(|e| NagariError::IoError(format!("Failed to write source map: {e}")))?;
242242
}
243243

244244
// Write TypeScript declarations if enabled
245245
if let Some(declarations) = result.declarations {
246246
let dts_path = output_path.with_extension("d.ts");
247247
fs::write(&dts_path, declarations).map_err(|e| {
248-
NagariError::IoError(format!("Failed to write declarations: {}", e))
248+
NagariError::IoError(format!("Failed to write declarations: {e}"))
249249
})?;
250250
}
251251

src/nagari-compiler/src/parser.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl Parser {
777777
match self.advance() {
778778
Token::Identifier(type_name) => {
779779
let mut base_type = Type::from_string(&type_name).ok_or_else(|| {
780-
NagariError::ParseError(format!("Unknown type: {}", type_name))
780+
NagariError::ParseError(format!("Unknown type: {type_name}"))
781781
})?;
782782

783783
// Handle generic types like list[int], dict[str, int]
@@ -1578,8 +1578,7 @@ impl Parser {
15781578

15791579
if closing_tag != tag_name {
15801580
return Err(NagariError::ParseError(format!(
1581-
"Mismatched JSX tags: {} and {}",
1582-
tag_name, closing_tag
1581+
"Mismatched JSX tags: {tag_name} and {closing_tag}"
15831582
)));
15841583
}
15851584

@@ -1839,7 +1838,7 @@ impl Parser {
18391838
let mut expr_content = String::new();
18401839
let mut brace_count = 1;
18411840

1842-
while let Some(ch) = chars.next() {
1841+
for ch in chars.by_ref() {
18431842
if ch == '{' {
18441843
brace_count += 1;
18451844
} else if ch == '}' {
@@ -2154,7 +2153,7 @@ impl Parser {
21542153
&Token::RightParen,
21552154
"Expected ')' after function call",
21562155
)?;
2157-
format!("{}(\"{}\")", func_name, arg)
2156+
format!("{func_name}(\"{arg}\")")
21582157
} else {
21592158
func_name
21602159
}

src/nagari-compiler/src/transpiler/js_runtime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ function setComp(iterable, transform, condition = () => true) {
175175
if is_async {
176176
match self.target.as_str() {
177177
"node" => {
178-
format!("async function {}(...args) {{ return nagariToJS(await jsToNagari({}(...args.map(jsToNagari)))); }}", function_name, function_name)
178+
format!("async function {function_name}(...args) {{ return nagariToJS(await jsToNagari({function_name}(...args.map(jsToNagari)))); }}")
179179
}
180180
_ => {
181-
format!("async function {}(...args) {{ return nagariToJS(await jsToNagari({}(...args.map(jsToNagari)))); }}", function_name, function_name)
181+
format!("async function {function_name}(...args) {{ return nagariToJS(await jsToNagari({function_name}(...args.map(jsToNagari)))); }}")
182182
}
183183
}
184184
} else {
185-
format!("function {}(...args) {{ return nagariToJS({}(...args.map(jsToNagari))); }}", function_name, function_name)
185+
format!("function {function_name}(...args) {{ return nagariToJS({function_name}(...args.map(jsToNagari))); }}")
186186
}
187187
}
188188

0 commit comments

Comments
 (0)