diff --git a/Cargo.lock b/Cargo.lock index 36ee615a..2986118b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -433,9 +433,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "full_moon" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10ff67debb902ca15a8296249ca41f452dc3f89a8ea65bf0d83eb3acfea30614" +checksum = "72c8093c43fd81ff7f0207dd2dd4750ecff4547d8b8b4ea80c5a325215c5fda9" dependencies = [ "bytecount", "cfg-if 0.1.10", diff --git a/selene-lib/Cargo.toml b/selene-lib/Cargo.toml index b593c9e4..aed6f446 100644 --- a/selene-lib/Cargo.toml +++ b/selene-lib/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] codespan = "0.9" codespan-reporting = "0.9" -full_moon = "0.6.0" +full_moon = "0.7" id-arena = "2.2" if_chain = "1.0" lazy_static = "1.4" diff --git a/selene-lib/src/ast_util/scopes.rs b/selene-lib/src/ast_util/scopes.rs index 390c2f6e..5144fcc3 100644 --- a/selene-lib/src/ast_util/scopes.rs +++ b/selene-lib/src/ast_util/scopes.rs @@ -231,7 +231,7 @@ impl ScopeVisitor { } fn read_table_constructor(&mut self, table: &ast::TableConstructor) { - for (field, _) in table.iter_fields() { + for field in table.iter_fields() { match field { ast::Field::ExpressionKey { key, value, .. } => { self.read_expression(key); diff --git a/selene-lib/src/ast_util/side_effects.rs b/selene-lib/src/ast_util/side_effects.rs index dec30c98..cd9e2fe8 100644 --- a/selene-lib/src/ast_util/side_effects.rs +++ b/selene-lib/src/ast_util/side_effects.rs @@ -1,76 +1,74 @@ -use full_moon::ast; - -pub trait HasSideEffects { - fn has_side_effects(&self) -> bool; -} - -impl HasSideEffects for ast::Expression<'_> { - fn has_side_effects(&self) -> bool { - match self { - ast::Expression::Parentheses { expression, .. } - | ast::Expression::UnaryOperator { expression, .. } => expression.has_side_effects(), - ast::Expression::Value { value, .. } => value.has_side_effects(), - } - } -} - -impl HasSideEffects for ast::Prefix<'_> { - fn has_side_effects(&self) -> bool { - match self { - ast::Prefix::Expression(expression) => expression.has_side_effects(), - ast::Prefix::Name(_) => false, - } - } -} - -impl HasSideEffects for ast::Suffix<'_> { - fn has_side_effects(&self) -> bool { - match self { - ast::Suffix::Call(_) => true, - ast::Suffix::Index(_) => false, - } - } -} - -impl HasSideEffects for ast::Value<'_> { - fn has_side_effects(&self) -> bool { - match self { - ast::Value::Function(_) - | ast::Value::Number(_) - | ast::Value::String(_) - | ast::Value::Symbol(_) => false, - ast::Value::FunctionCall(_) => true, - ast::Value::ParseExpression(expression) => expression.has_side_effects(), - ast::Value::TableConstructor(table_constructor) => { - table_constructor - .iter_fields() - .any(|(field, _)| match field { - ast::Field::ExpressionKey { key, value, .. } => { - key.has_side_effects() || value.has_side_effects() - } - - ast::Field::NameKey { value, .. } => value.has_side_effects(), - - ast::Field::NoKey(expression) => expression.has_side_effects(), - }) - } - ast::Value::Var(var) => var.has_side_effects(), - } - } -} - -impl HasSideEffects for ast::Var<'_> { - fn has_side_effects(&self) -> bool { - match self { - ast::Var::Expression(var_expr) => var_expr.has_side_effects(), - ast::Var::Name(_) => false, - } - } -} - -impl HasSideEffects for ast::VarExpression<'_> { - fn has_side_effects(&self) -> bool { - self.prefix().has_side_effects() - || self.iter_suffixes().any(HasSideEffects::has_side_effects) - } -} +use full_moon::ast; + +pub trait HasSideEffects { + fn has_side_effects(&self) -> bool; +} + +impl HasSideEffects for ast::Expression<'_> { + fn has_side_effects(&self) -> bool { + match self { + ast::Expression::Parentheses { expression, .. } + | ast::Expression::UnaryOperator { expression, .. } => expression.has_side_effects(), + ast::Expression::Value { value, .. } => value.has_side_effects(), + } + } +} + +impl HasSideEffects for ast::Prefix<'_> { + fn has_side_effects(&self) -> bool { + match self { + ast::Prefix::Expression(expression) => expression.has_side_effects(), + ast::Prefix::Name(_) => false, + } + } +} + +impl HasSideEffects for ast::Suffix<'_> { + fn has_side_effects(&self) -> bool { + match self { + ast::Suffix::Call(_) => true, + ast::Suffix::Index(_) => false, + } + } +} + +impl HasSideEffects for ast::Value<'_> { + fn has_side_effects(&self) -> bool { + match self { + ast::Value::Function(_) + | ast::Value::Number(_) + | ast::Value::String(_) + | ast::Value::Symbol(_) => false, + ast::Value::FunctionCall(_) => true, + ast::Value::ParseExpression(expression) => expression.has_side_effects(), + ast::Value::TableConstructor(table_constructor) => { + table_constructor.iter_fields().any(|field| match field { + ast::Field::ExpressionKey { key, value, .. } => { + key.has_side_effects() || value.has_side_effects() + } + + ast::Field::NameKey { value, .. } => value.has_side_effects(), + + ast::Field::NoKey(expression) => expression.has_side_effects(), + }) + } + ast::Value::Var(var) => var.has_side_effects(), + } + } +} + +impl HasSideEffects for ast::Var<'_> { + fn has_side_effects(&self) -> bool { + match self { + ast::Var::Expression(var_expr) => var_expr.has_side_effects(), + ast::Var::Name(_) => false, + } + } +} + +impl HasSideEffects for ast::VarExpression<'_> { + fn has_side_effects(&self) -> bool { + self.prefix().has_side_effects() + || self.iter_suffixes().any(HasSideEffects::has_side_effects) + } +} diff --git a/selene-lib/src/rules/roblox_incorrect_roact_usage.rs b/selene-lib/src/rules/roblox_incorrect_roact_usage.rs index 77c84205..195632fe 100644 --- a/selene-lib/src/rules/roblox_incorrect_roact_usage.rs +++ b/selene-lib/src/rules/roblox_incorrect_roact_usage.rs @@ -193,7 +193,7 @@ impl Visitor<'_> for IncorrectRoactUsageVisitor { } } - for (field, _) in arguments.iter_fields() { + for field in arguments.iter_fields() { if let ast::Field::NameKey { key, .. } = field { let property_name = key.token().to_string(); if !valid_properties.contains(property_name.as_str()) { diff --git a/selene-lib/src/rules/test_util.rs b/selene-lib/src/rules/test_util.rs index 6e6818bf..27b25ce2 100644 --- a/selene-lib/src/rules/test_util.rs +++ b/selene-lib/src/rules/test_util.rs @@ -13,8 +13,7 @@ use full_moon::ast::owned::Owned; use serde::de::DeserializeOwned; lazy_static::lazy_static! { - static ref TEST_PROJECTS_ROOT: PathBuf = - { Path::new(env!("CARGO_MANIFEST_DIR")).join("tests").join("lints") }; + static ref TEST_PROJECTS_ROOT: PathBuf = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests").join("lints"); } pub struct TestUtilConfig { diff --git a/selene-lib/tests/lints/standard_library/required.stderr b/selene-lib/tests/lints/standard_library/required.stderr index 2d145546..ba0b79ee 100644 --- a/selene-lib/tests/lints/standard_library/required.stderr +++ b/selene-lib/tests/lints/standard_library/required.stderr @@ -1,16 +1,12 @@ error[incorrect_standard_library_use]: standard library function `ipairs` requires 1 parameters, 0 passed - - ┌── required.lua:2:1 ─── - │ - 2 │ ipairs() - │ ^^^^^^^^ - │ + ┌─ required.lua:2:1 + │ +2 │ ipairs() + │ ^^^^^^^^ error[incorrect_standard_library_use]: standard library function `setmetatable` requires 1 parameters, 0 passed - - ┌── required.lua:5:1 ─── - │ - 5 │ setmetatable() - │ ^^^^^^^^^^^^^^ - │ + ┌─ required.lua:5:1 + │ +5 │ setmetatable() + │ ^^^^^^^^^^^^^^ diff --git a/selene-lib/tests/lints/standard_library/unpack_function_arguments.stderr b/selene-lib/tests/lints/standard_library/unpack_function_arguments.stderr index 86f3ed34..1c2bdc9f 100644 --- a/selene-lib/tests/lints/standard_library/unpack_function_arguments.stderr +++ b/selene-lib/tests/lints/standard_library/unpack_function_arguments.stderr @@ -1,16 +1,12 @@ error[incorrect_standard_library_use]: standard library function `debug.setlocal` requires 3 parameters, 2 passed - - ┌── unpack_function_arguments.lua:9:1 ─── - │ - 9 │ debug.setlocal(unpack(stuff), 2) - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - │ + ┌─ unpack_function_arguments.lua:9:1 + │ +9 │ debug.setlocal(unpack(stuff), 2) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[incorrect_standard_library_use]: standard library function `string.upper` requires 1 parameters, 2 passed - - ┌── unpack_function_arguments.lua:12:1 ─── - │ - 12 │ string.upper("text", unpack(stuff)) - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - │ + ┌─ unpack_function_arguments.lua:12:1 + │ +12 │ string.upper("text", unpack(stuff)) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/selene/Cargo.toml b/selene/Cargo.toml index 9a730c46..bb5ccbdf 100644 --- a/selene/Cargo.toml +++ b/selene/Cargo.toml @@ -16,7 +16,7 @@ cfg-if = "0.1" chrono = "0.4" codespan = { version = "0.9", features = ["serialization"] } codespan-reporting = { version = "0.9", features = ["serialization"] } -full_moon = "0.6.0" +full_moon = "0.7" lazy_static = "1.4" glob = "0.3" num_cpus = "1.10"