Skip to content

Commit

Permalink
New exhaustive checks + Luau stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed Nov 11, 2023
1 parent 077d01f commit ddd6f16
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
14 changes: 12 additions & 2 deletions selene-lib/src/ast_util/extract_static_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ pub fn extract_static_token(expression: &ast::Expression) -> Option<&TokenRefere
deny(non_exhaustive_omitted_patterns)
)]
match expression {
ast::Expression::BinaryOperator { .. } | ast::Expression::UnaryOperator { .. } => None,

ast::Expression::Parentheses { expression, .. } => extract_static_token(expression),

ast::Expression::Number(token)
| ast::Expression::String(token)
| ast::Expression::Symbol(token) => Some(token),

ast::Expression::BinaryOperator { .. }
| ast::Expression::UnaryOperator { .. }
| ast::Expression::Function(_)
| ast::Expression::FunctionCall(_)
| ast::Expression::IfExpression(_)
| ast::Expression::InterpolatedString(_)
| ast::Expression::TableConstructor(_)
| ast::Expression::Var(_) => None,

#[cfg(feature = "roblox")]
ast::Expression::TypeAssertion { .. } => None,

_ => None,
}
}
5 changes: 5 additions & 0 deletions selene-lib/src/ast_util/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ impl ScopeVisitor {
}
}

#[cfg(feature = "roblox")]
ast::Expression::TypeAssertion { expression, .. } => {
self.read_expression(expression);
}

ast::Expression::Number(_) | ast::Expression::String(_) => {}

_ => {}
Expand Down
3 changes: 3 additions & 0 deletions selene-lib/src/ast_util/side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ impl HasSideEffects for ast::Expression {
false
}

#[cfg(feature = "roblox")]
ast::Expression::TypeAssertion { expression, .. } => expression.has_side_effects(),

_ => true,
}
}
Expand Down
5 changes: 5 additions & 0 deletions selene-lib/src/lints/high_cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ fn count_expression_complexity(expression: &ast::Expression, starting_complexity
complexity
}

#[cfg(feature = "roblox")]
ast::Expression::TypeAssertion { expression, .. } => {
count_expression_complexity(expression, complexity)
}

_ => complexity,
}
}
Expand Down
15 changes: 15 additions & 0 deletions selene-lib/src/lints/standard_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,25 @@ fn get_argument_type(expression: &ast::Expression) -> Option<PassedArgumentType>
None
}

#[cfg(feature = "roblox")]
ast::BinOp::DoubleSlash(_) => {
let lhs_type = get_argument_type(lhs);
let rhs_type = get_argument_type(rhs);

if lhs_type == rhs_type {
lhs_type
} else {
None
}
}

_ => None,
}
}

#[cfg(feature = "roblox")]
ast::Expression::TypeAssertion { expression, .. } => get_argument_type(expression),

_ => None,
}
}
Expand Down

0 comments on commit ddd6f16

Please sign in to comment.