Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_analyze): new lint rule noExcessiveComplexity #4657

Merged
merged 23 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rome_analyze/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl Visitor for MissingYieldVisitor {
// entry of the stack and the `has_yield` flag is `false`, emit a query match
if let Some(exit_node) = AnyFunctionLike::cast_ref(node) {
if let Some((enter_node, has_yield)) = self.stack.pop() {
assert_eq!(enter_node, exit_node);
debug_assert_eq!(enter_node, exit_node);
if !has_yield {
ctx.match_query(MissingYield(enter_node));
}
Expand Down
1 change: 1 addition & 0 deletions crates/rome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ define_categories! {
"lint/nursery/useArrowFunction": "https://docs.rome.tools/lint/rules/useArrowFunction",
"lint/nursery/noVoid": "https://docs.rome.tools/lint/rules/noVoid",
"lint/nursery/noNonoctalDecimalEscape": "https://docs.rome.tools/lint/rules/noNonoctalDecimalEscape",
"lint/nursery/noExcessiveComplexity": "https://docs.rome.tools/lint/rules/noExcessiveComplexity",
// Insert new nursery rule here


Expand Down
41 changes: 2 additions & 39 deletions crates/rome_js_analyze/src/analyzers/correctness/use_yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use rome_analyze::{
Visitor, VisitorContext,
};
use rome_console::markup;
use rome_js_syntax::{
AnyJsFunction, JsLanguage, JsMethodClassMember, JsMethodObjectMember, JsStatementList,
JsYieldExpression, TextRange, WalkEvent,
};
use rome_rowan::{declare_node_union, AstNode, AstNodeList, Language, SyntaxNode};
use rome_js_syntax::{AnyFunctionLike, JsLanguage, JsYieldExpression, TextRange, WalkEvent};
use rome_rowan::{AstNode, AstNodeList, Language, SyntaxNode};

declare_rule! {
/// Require generator functions to contain `yield`.
Expand Down Expand Up @@ -48,40 +45,6 @@ declare_rule! {
}
}

declare_node_union! {
pub(crate) AnyFunctionLike = AnyJsFunction | JsMethodObjectMember | JsMethodClassMember
}

impl AnyFunctionLike {
fn is_generator(&self) -> bool {
match self {
AnyFunctionLike::AnyJsFunction(any_js_function) => any_js_function.is_generator(),
AnyFunctionLike::JsMethodClassMember(method_class_member) => {
method_class_member.star_token().is_some()
}
AnyFunctionLike::JsMethodObjectMember(method_obj_member) => {
method_obj_member.star_token().is_some()
}
}
}

fn statements(&self) -> Option<JsStatementList> {
Some(match self {
AnyFunctionLike::AnyJsFunction(any_js_function) => any_js_function
.body()
.ok()?
.as_js_function_body()?
.statements(),
AnyFunctionLike::JsMethodClassMember(method_class_member) => {
method_class_member.body().ok()?.statements()
}
AnyFunctionLike::JsMethodObjectMember(method_obj_member) => {
method_obj_member.body().ok()?.statements()
}
})
}
}

#[derive(Default)]
struct MissingYieldVisitor {
/// Vector to hold a function node and a boolean indicating whether the function
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_js_analyze/src/analyzers/nursery.rs

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

Loading
Loading