Skip to content

Commit

Permalink
full-moon 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed Nov 6, 2020
1 parent 4776b96 commit 76c9860
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 108 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion selene-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion selene-lib/src/ast_util/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
150 changes: 74 additions & 76 deletions selene-lib/src/ast_util/side_effects.rs
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)
}
}
2 changes: 1 addition & 1 deletion selene-lib/src/rules/roblox_incorrect_roact_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
3 changes: 1 addition & 2 deletions selene-lib/src/rules/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 8 additions & 12 deletions selene-lib/tests/lints/standard_library/required.stderr
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()
│ ^^^^^^^^^^^^^^

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))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2 changes: 1 addition & 1 deletion selene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 76c9860

Please sign in to comment.