From ddd6f16ed33bdbedf1b880991974ee79e64104ee Mon Sep 17 00:00:00 2001 From: Kampfkarren Date: Fri, 10 Nov 2023 23:19:59 -0800 Subject: [PATCH] New exhaustive checks + Luau stuff --- selene-lib/src/ast_util/extract_static_token.rs | 14 ++++++++++++-- selene-lib/src/ast_util/scopes.rs | 5 +++++ selene-lib/src/ast_util/side_effects.rs | 3 +++ .../src/lints/high_cyclomatic_complexity.rs | 5 +++++ selene-lib/src/lints/standard_library.rs | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/selene-lib/src/ast_util/extract_static_token.rs b/selene-lib/src/ast_util/extract_static_token.rs index 4783863d..df74ee42 100644 --- a/selene-lib/src/ast_util/extract_static_token.rs +++ b/selene-lib/src/ast_util/extract_static_token.rs @@ -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, } } diff --git a/selene-lib/src/ast_util/scopes.rs b/selene-lib/src/ast_util/scopes.rs index ed817d97..3e3b6ff2 100644 --- a/selene-lib/src/ast_util/scopes.rs +++ b/selene-lib/src/ast_util/scopes.rs @@ -388,6 +388,11 @@ impl ScopeVisitor { } } + #[cfg(feature = "roblox")] + ast::Expression::TypeAssertion { expression, .. } => { + self.read_expression(expression); + } + ast::Expression::Number(_) | ast::Expression::String(_) => {} _ => {} diff --git a/selene-lib/src/ast_util/side_effects.rs b/selene-lib/src/ast_util/side_effects.rs index e73dc263..f8af5aec 100644 --- a/selene-lib/src/ast_util/side_effects.rs +++ b/selene-lib/src/ast_util/side_effects.rs @@ -72,6 +72,9 @@ impl HasSideEffects for ast::Expression { false } + #[cfg(feature = "roblox")] + ast::Expression::TypeAssertion { expression, .. } => expression.has_side_effects(), + _ => true, } } diff --git a/selene-lib/src/lints/high_cyclomatic_complexity.rs b/selene-lib/src/lints/high_cyclomatic_complexity.rs index 69e9ecbd..adee8e28 100644 --- a/selene-lib/src/lints/high_cyclomatic_complexity.rs +++ b/selene-lib/src/lints/high_cyclomatic_complexity.rs @@ -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, } } diff --git a/selene-lib/src/lints/standard_library.rs b/selene-lib/src/lints/standard_library.rs index a87424e1..6c4942c6 100644 --- a/selene-lib/src/lints/standard_library.rs +++ b/selene-lib/src/lints/standard_library.rs @@ -177,10 +177,25 @@ fn get_argument_type(expression: &ast::Expression) -> Option 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, } }