From c81303fe3ba7efd80075689c93c2ecca1051e9e4 Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Mon, 12 Jun 2023 20:15:17 +0100
Subject: [PATCH] Linting

---
 forge-script-lang/src/lexer/_span.rs              |  2 +-
 forge-script-lang/src/lexer/atoms.rs              |  6 +++---
 forge-script-lang/src/lexer/mod.rs                |  3 +--
 forge-script-lang/src/lexer/operators.rs          |  2 +-
 forge-script-lang/src/lexer/strings.rs            |  2 +-
 forge-script-lang/src/lexer/tokens.rs             |  2 +-
 forge-script-lang/src/parser/ast.rs               |  2 +-
 forge-script-lang/src/parser/forge_script.rs      | 12 ++----------
 forge-script-lang/src/pratt/parser.rs             | 10 +++++-----
 forge-script-lang/src/pratt/test_cases.rs         |  2 +-
 forge-script-lang/src/runtime/executor/printer.rs | 12 ++++++------
 forge-script-lang/src/runtime/executor/simple.rs  |  2 +-
 forge-script-lang/src/runtime/vm/chunks.rs        |  5 ++---
 forge-script-lang/src/runtime/vm/compile.rs       |  8 ++++----
 forge-script-lang/src/runtime/vm/machine.rs       |  4 ++--
 forge-script-lang/src/runtime/vm/opcode.rs        |  4 +---
 forge-script-lang/tests/program_tests.rs          |  2 +-
 forge-script/src/main.rs                          |  3 +--
 forge-script/src/repl.rs                          |  2 +-
 19 files changed, 36 insertions(+), 49 deletions(-)

diff --git a/forge-script-lang/src/lexer/_span.rs b/forge-script-lang/src/lexer/_span.rs
index c7c08b2..3026b06 100644
--- a/forge-script-lang/src/lexer/_span.rs
+++ b/forge-script-lang/src/lexer/_span.rs
@@ -326,7 +326,7 @@ impl<'a> nom::Slice<RangeFrom<usize>> for TextSpan<'a> {
 	}
 }
 impl<'a> nom::Slice<RangeFull> for TextSpan<'a> {
-	fn slice(&self, range: RangeFull) -> Self {
+	fn slice(&self, _range: RangeFull) -> Self {
 		*self
 	}
 }
diff --git a/forge-script-lang/src/lexer/atoms.rs b/forge-script-lang/src/lexer/atoms.rs
index 9c97405..9f2500b 100644
--- a/forge-script-lang/src/lexer/atoms.rs
+++ b/forge-script-lang/src/lexer/atoms.rs
@@ -1,7 +1,7 @@
 use nom::branch::alt;
-use nom::bytes::complete::{is_not, tag};
-use nom::character::complete::{alphanumeric1, char, multispace0, multispace1, none_of, one_of};
-use nom::combinator::{not, peek, value};
+use nom::bytes::complete::tag;
+use nom::character::complete::{alphanumeric1, char, multispace0, one_of};
+use nom::combinator::{not, value};
 use nom::multi::{many0, many1};
 use nom::sequence::{delimited, terminated};
 use nom::IResult;
diff --git a/forge-script-lang/src/lexer/mod.rs b/forge-script-lang/src/lexer/mod.rs
index 2cd83ce..c383370 100644
--- a/forge-script-lang/src/lexer/mod.rs
+++ b/forge-script-lang/src/lexer/mod.rs
@@ -23,7 +23,7 @@ use strings::token_string;
 pub use tokens::{ScriptToken, ScriptTokenType};
 
 use crate::error::TokenError;
-pub(crate) use atoms::{raw_decimal, raw_false, raw_true, OwnedSpan, Span};
+pub(crate) use atoms::{raw_decimal, raw_false, raw_true, Span};
 
 mod _lex {
 	use super::*;
@@ -172,5 +172,4 @@ mod _lex {
 	}
 }
 
-use crate::parser::TokenSlice;
 pub use _lex::script_to_tokens;
diff --git a/forge-script-lang/src/lexer/operators.rs b/forge-script-lang/src/lexer/operators.rs
index 911cd73..da54c1b 100644
--- a/forge-script-lang/src/lexer/operators.rs
+++ b/forge-script-lang/src/lexer/operators.rs
@@ -1,9 +1,9 @@
 use crate::lexer::Span;
 use crate::lexer::{ScriptToken, ScriptTokenType};
+use crate::parse_ops;
 use nom::bytes::complete::tag;
 use nom::IResult;
 use nom_locate::position;
-use crate::parse_ops;
 
 parse_ops!(
 	tag ;
diff --git a/forge-script-lang/src/lexer/strings.rs b/forge-script-lang/src/lexer/strings.rs
index 0b04579..c99334a 100644
--- a/forge-script-lang/src/lexer/strings.rs
+++ b/forge-script-lang/src/lexer/strings.rs
@@ -37,7 +37,7 @@ fn parse_unicode(input: Span) -> IResult<Span, char> {
 	// the function returns None, map_opt returns an error. In this case, because
 	// not all u32 values are valid unicode code points, we have to fallibly
 	// convert to p_char with from_u32.
-	let (span, char) = map_opt(parse_u32, move |val| char::from_u32(val))(input)?;
+	let (span, char) = map_opt(parse_u32, char::from_u32)(input)?;
 	Ok((span, char))
 }
 
diff --git a/forge-script-lang/src/lexer/tokens.rs b/forge-script-lang/src/lexer/tokens.rs
index 54ef760..5226c8a 100644
--- a/forge-script-lang/src/lexer/tokens.rs
+++ b/forge-script-lang/src/lexer/tokens.rs
@@ -1,6 +1,6 @@
 use crate::lexer::Span;
 use std::error::Error;
-use std::fmt::{format, Debug, Display, Formatter};
+use std::fmt::{Debug, Display, Formatter};
 
 #[derive(PartialEq, Clone, Debug)]
 pub enum ScriptTokenType {
diff --git a/forge-script-lang/src/parser/ast.rs b/forge-script-lang/src/parser/ast.rs
index 7bc290f..bcd350d 100644
--- a/forge-script-lang/src/parser/ast.rs
+++ b/forge-script-lang/src/parser/ast.rs
@@ -1,5 +1,5 @@
 use crate::runtime::numbers::Number;
-use crate::runtime::value::ForgeValue;
+
 use std::fmt::{Display, Formatter};
 use std::ops::Deref;
 
diff --git a/forge-script-lang/src/parser/forge_script.rs b/forge-script-lang/src/parser/forge_script.rs
index c138d5f..deca8f8 100644
--- a/forge-script-lang/src/parser/forge_script.rs
+++ b/forge-script-lang/src/parser/forge_script.rs
@@ -1,14 +1,6 @@
-use crate::error::ForgeResult;
-use crate::lexer::{script_to_tokens, ScriptTokenType};
+use crate::lexer::script_to_tokens;
 use crate::parser::ast::{Expression, Program};
-use crate::pratt::{Scanner, ScannerError};
-use crate::{ForgeError, ForgeErrorKind, TokenError};
-use peg::Parse;
-
-pub type InputSpan<'a, Loc, Tok> = Result<(Loc, Tok, Loc), String>;
-type ExprSpan<'a> = InputSpan<'a, usize, ScriptTokenType>;
-
-pub type SpanSpan<'a> = Result<(usize, ScriptTokenType, usize), ScannerError>;
+use crate::ForgeError;
 
 macro_rules! export_grammar_fn {
 	($name:ident = $output:ty => $part: tt) => {
diff --git a/forge-script-lang/src/pratt/parser.rs b/forge-script-lang/src/pratt/parser.rs
index 9dd3315..caa55f2 100644
--- a/forge-script-lang/src/pratt/parser.rs
+++ b/forge-script-lang/src/pratt/parser.rs
@@ -162,7 +162,7 @@ macro_rules! next_match {
 }
 
 impl<'a> Scanner<'a> {
-	pub fn new<'b>(source: &'b str) -> Scanner<'b> {
+	pub fn new(source: &str) -> Scanner<'_> {
 		Scanner {
 			source,
 			position: PositionState::default(),
@@ -357,20 +357,20 @@ impl<'a> Scanner<'a> {
 
 		let result = if can_have_dot {
 			// We haven't consumed a dot, it's an int
-			(&self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current])
+			self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current]
 				.replace('_', "")
 				.parse::<i64>()
-				.map_err(|e| ScannerError {
+				.map_err(|_e| ScannerError {
 					position: self.position,
 					kind: ScannerErrorKind::InvalidLiteral { ltype: "integer" },
 				})
 				.map(ScriptTokenType::Integer)
 		} else {
 			// We have consumed a dot, it's a float
-			(&self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current])
+			self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current]
 				.replace('_', "")
 				.parse::<f64>()
-				.map_err(|e| ScannerError {
+				.map_err(|_e| ScannerError {
 					position: self.position,
 					kind: ScannerErrorKind::InvalidLiteral { ltype: "float" },
 				})
diff --git a/forge-script-lang/src/pratt/test_cases.rs b/forge-script-lang/src/pratt/test_cases.rs
index 7959a01..91bcbfb 100644
--- a/forge-script-lang/src/pratt/test_cases.rs
+++ b/forge-script-lang/src/pratt/test_cases.rs
@@ -1,5 +1,5 @@
 use crate::lexer::ScriptTokenType;
-use crate::pratt::parser::{Scanner, ScannerError, ScannerResult};
+use crate::pratt::parser::{Scanner, ScannerError};
 use test_case::test_case;
 
 #[test_case("", Ok(ScriptTokenType::Eof) ; "expects eof")]
diff --git a/forge-script-lang/src/runtime/executor/printer.rs b/forge-script-lang/src/runtime/executor/printer.rs
index 5ebad13..3f6ebde 100644
--- a/forge-script-lang/src/runtime/executor/printer.rs
+++ b/forge-script-lang/src/runtime/executor/printer.rs
@@ -65,10 +65,10 @@ impl TreePrinter {
 		inner_printer.indent = self.indent;
 
 		let len = list.len();
-		let mut iter = list.expressions.iter();
+		let iter = list.expressions.iter();
 		let mut counter = 1;
 
-		while let Some(value) = iter.next() {
+		for value in iter {
 			inner_printer.evaluate_expression(value);
 			if counter < len {
 				inner_printer.writeln(";");
@@ -142,10 +142,10 @@ impl Visitor for TreePrinter {
 				self.evaluate_value_expression(assign.value.as_ref());
 			}
 			ValueExpression::ConditionalBlock(condition) => {
-				let mut iter = condition.blocks.iter();
-				let mut curr = 1;
+				let iter = condition.blocks.iter();
+				let curr = 1;
 				let count = iter.len();
-				while let Some(item) = iter.next() {
+				for item in iter {
 					self.write("if ");
 					self.evaluate_value_expression(item.guard.as_ref());
 					self.writeln(" {");
@@ -175,7 +175,7 @@ impl Visitor for TreePrinter {
 			ValueExpression::Identifier(ident) => {
 				self.write(ident);
 			}
-			ValueExpression::Accessor(accessor) => self.write("<ACCESSOR>"),
+			ValueExpression::Accessor(_accessor) => self.write("<ACCESSOR>"),
 			ValueExpression::FunctionCall(call) => {
 				self.write(&call.name);
 				self.write("(");
diff --git a/forge-script-lang/src/runtime/executor/simple.rs b/forge-script-lang/src/runtime/executor/simple.rs
index f12efa2..0b7b373 100644
--- a/forge-script-lang/src/runtime/executor/simple.rs
+++ b/forge-script-lang/src/runtime/executor/simple.rs
@@ -206,7 +206,7 @@ impl Visitor for SimpleExecutor {
 				.get_variable(ident)
 				.cloned()
 				.ok_or_else(|| RuntimeError::UndefinedVariable(ident.to_string())),
-			ValueExpression::Accessor(ident) => Err(RuntimeError::Unsupported("Accessor")),
+			ValueExpression::Accessor(_ident) => Err(RuntimeError::Unsupported("Accessor")),
 			ValueExpression::FunctionCall(_) => Err(RuntimeError::Unsupported("FunctionCall")),
 			ValueExpression::DeclareFunction(_) => {
 				Err(RuntimeError::Unsupported("DeclareFunction"))
diff --git a/forge-script-lang/src/runtime/vm/chunks.rs b/forge-script-lang/src/runtime/vm/chunks.rs
index e7d9d52..aca2687 100644
--- a/forge-script-lang/src/runtime/vm/chunks.rs
+++ b/forge-script-lang/src/runtime/vm/chunks.rs
@@ -1,9 +1,8 @@
 use crate::runtime::value::ForgeValue;
 use crate::runtime::vm::const_data::{ConstData, ConstDataRef};
-use crate::runtime::vm::opcode::{OpCode, OpCodeError};
+use crate::runtime::vm::opcode::OpCode;
 use crate::utilities::Clown;
 use std::fmt::{Display, Formatter};
-use std::ops::{Deref, DerefMut};
 
 #[derive(Default)]
 pub struct Chunk {
@@ -103,7 +102,7 @@ pub trait ChunkOps {
 				_ => {}
 			}
 
-			writeln!(f, "")?;
+			writeln!(f)?;
 
 			offset = opcode.next_offset(offset);
 		}
diff --git a/forge-script-lang/src/runtime/vm/compile.rs b/forge-script-lang/src/runtime/vm/compile.rs
index e1fb050..4af21e4 100644
--- a/forge-script-lang/src/runtime/vm/compile.rs
+++ b/forge-script-lang/src/runtime/vm/compile.rs
@@ -1,8 +1,8 @@
 use crate::lexer::ScriptTokenType;
 use crate::pratt::{Scanner, ScannerError, ScannerErrorKind, ScannerIter, ScannerToken};
-use crate::rule_table;
+
 use crate::runtime::vm::Chunk;
-use crate::runtime::vm::{ParsingPrecedence, ParsingRuleType, ParsingRules};
+use crate::runtime::vm::ParsingPrecedence;
 
 #[derive(Clone, Default)]
 pub struct ParsingState {
@@ -79,7 +79,7 @@ impl<'a> Compiler<'a> {
 		Ok(self.chunk())
 	}
 
-	fn process_precedence(&mut self, precedence: ParsingPrecedence) -> CompilerOp {
+	fn process_precedence(&mut self, _precedence: ParsingPrecedence) -> CompilerOp {
 		Ok(())
 	}
 
@@ -139,6 +139,6 @@ impl<'a> Compiler<'a> {
 	}
 }
 
-fn compile_expression(compiler: &mut Compiler) -> CompilerOp {
+fn compile_expression(_compiler: &mut Compiler) -> CompilerOp {
 	Ok(())
 }
diff --git a/forge-script-lang/src/runtime/vm/machine.rs b/forge-script-lang/src/runtime/vm/machine.rs
index 5e7c724..95feeab 100644
--- a/forge-script-lang/src/runtime/vm/machine.rs
+++ b/forge-script-lang/src/runtime/vm/machine.rs
@@ -1,10 +1,10 @@
 use crate::parser::ast::BinaryOp;
-use crate::parser::parse_program;
+
 use crate::runtime::value::{ForgeValue, UnsupportedOperation};
 use crate::runtime::vm::chunk_builder::ChunkBuilder;
 use crate::runtime::vm::chunks::Chunk;
 use crate::runtime::vm::{ChunkOps, OpCode};
-use crate::{format_forge_error, ForgeErrorKind};
+
 use std::collections::VecDeque;
 use std::error::Error;
 use std::fmt::{Display, Formatter};
diff --git a/forge-script-lang/src/runtime/vm/opcode.rs b/forge-script-lang/src/runtime/vm/opcode.rs
index 9b300dd..3781382 100644
--- a/forge-script-lang/src/runtime/vm/opcode.rs
+++ b/forge-script-lang/src/runtime/vm/opcode.rs
@@ -15,9 +15,7 @@ pub enum OpCode {
 
 impl OpCode {
 	pub fn next_offset(&self, current: usize) -> usize {
-		match self {
-			_ => current + 1,
-		}
+		current + 1
 	}
 
 	pub fn op_byte(&self) -> u8 {
diff --git a/forge-script-lang/tests/program_tests.rs b/forge-script-lang/tests/program_tests.rs
index 40e59fb..571721c 100644
--- a/forge-script-lang/tests/program_tests.rs
+++ b/forge-script-lang/tests/program_tests.rs
@@ -1,4 +1,4 @@
-use forge_script_lang::parse::{parse_expression, parse_program};
+use forge_script_lang::parse::parse_program;
 use std::path::PathBuf;
 
 fn get_base_path() -> Result<PathBuf, std::io::Error> {
diff --git a/forge-script/src/main.rs b/forge-script/src/main.rs
index ef49ca6..27448f1 100644
--- a/forge-script/src/main.rs
+++ b/forge-script/src/main.rs
@@ -1,9 +1,8 @@
 use forge_script_lang::parse::parse_program;
-use forge_script_lang::runtime::vm::{ChunkOps, Compiler};
 
 mod repl;
 
 fn main() {
 	let program = "2+2";
-	let ast = parse_program(program).expect("Failed");
+	let _ast = parse_program(program).expect("Failed");
 }
diff --git a/forge-script/src/repl.rs b/forge-script/src/repl.rs
index 1535fa8..a39877b 100644
--- a/forge-script/src/repl.rs
+++ b/forge-script/src/repl.rs
@@ -8,7 +8,7 @@ pub struct Repl {
 }
 
 fn parse_hex(string: &str) -> Result<Vec<u8>, ParseIntError> {
-	let parts = string.split(" ").collect::<Vec<&str>>();
+	let parts = string.split(' ').collect::<Vec<&str>>();
 	let mut out = Vec::with_capacity(parts.len());
 	for part in parts {
 		out.push(u8::from_str_radix(part, 16)?);
-- 
GitLab