-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4776b96
commit 76c9860
Showing
9 changed files
with
97 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
│ ^^^^^^^^^^^^^^ | ||
|
20 changes: 8 additions & 12 deletions
20
selene-lib/tests/lints/standard_library/unpack_function_arguments.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters