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

Commit 8f46efb

Browse files
authored
feat(rome_js_analyze): new lint rule noExcessiveComplexity (#4657)
1 parent 10fb3d4 commit 8f46efb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1817
-98
lines changed

crates/rome_analyze/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl Visitor for MissingYieldVisitor {
463463
// entry of the stack and the `has_yield` flag is `false`, emit a query match
464464
if let Some(exit_node) = AnyFunctionLike::cast_ref(node) {
465465
if let Some((enter_node, has_yield)) = self.stack.pop() {
466-
assert_eq!(enter_node, exit_node);
466+
debug_assert_eq!(enter_node, exit_node);
467467
if !has_yield {
468468
ctx.match_query(MissingYield(enter_node));
469469
}

crates/rome_diagnostics_categories/src/categories.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ define_categories! {
104104
"lint/nursery/useArrowFunction": "https://docs.rome.tools/lint/rules/useArrowFunction",
105105
"lint/nursery/noVoid": "https://docs.rome.tools/lint/rules/noVoid",
106106
"lint/nursery/noNonoctalDecimalEscape": "https://docs.rome.tools/lint/rules/noNonoctalDecimalEscape",
107+
"lint/nursery/noExcessiveComplexity": "https://docs.rome.tools/lint/rules/noExcessiveComplexity",
107108
// Insert new nursery rule here
108109

109110

crates/rome_js_analyze/src/analyzers/correctness/use_yield.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ use rome_analyze::{
44
Visitor, VisitorContext,
55
};
66
use rome_console::markup;
7-
use rome_js_syntax::{
8-
AnyJsFunction, JsLanguage, JsMethodClassMember, JsMethodObjectMember, JsStatementList,
9-
JsYieldExpression, TextRange, WalkEvent,
10-
};
11-
use rome_rowan::{declare_node_union, AstNode, AstNodeList, Language, SyntaxNode};
7+
use rome_js_syntax::{AnyFunctionLike, JsLanguage, JsYieldExpression, TextRange, WalkEvent};
8+
use rome_rowan::{AstNode, AstNodeList, Language, SyntaxNode};
129

1310
declare_rule! {
1411
/// Require generator functions to contain `yield`.
@@ -48,40 +45,6 @@ declare_rule! {
4845
}
4946
}
5047

51-
declare_node_union! {
52-
pub(crate) AnyFunctionLike = AnyJsFunction | JsMethodObjectMember | JsMethodClassMember
53-
}
54-
55-
impl AnyFunctionLike {
56-
fn is_generator(&self) -> bool {
57-
match self {
58-
AnyFunctionLike::AnyJsFunction(any_js_function) => any_js_function.is_generator(),
59-
AnyFunctionLike::JsMethodClassMember(method_class_member) => {
60-
method_class_member.star_token().is_some()
61-
}
62-
AnyFunctionLike::JsMethodObjectMember(method_obj_member) => {
63-
method_obj_member.star_token().is_some()
64-
}
65-
}
66-
}
67-
68-
fn statements(&self) -> Option<JsStatementList> {
69-
Some(match self {
70-
AnyFunctionLike::AnyJsFunction(any_js_function) => any_js_function
71-
.body()
72-
.ok()?
73-
.as_js_function_body()?
74-
.statements(),
75-
AnyFunctionLike::JsMethodClassMember(method_class_member) => {
76-
method_class_member.body().ok()?.statements()
77-
}
78-
AnyFunctionLike::JsMethodObjectMember(method_obj_member) => {
79-
method_obj_member.body().ok()?.statements()
80-
}
81-
})
82-
}
83-
}
84-
8548
#[derive(Default)]
8649
struct MissingYieldVisitor {
8750
/// Vector to hold a function node and a boolean indicating whether the function

crates/rome_js_analyze/src/analyzers/nursery.rs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)