Skip to content

Commit

Permalink
fix: update action for computer member expression case
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke committed Mar 11, 2024
1 parent 6abe775 commit 76394f7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
55 changes: 28 additions & 27 deletions crates/biome_js_analyze/src/analyzers/nursery/no_focused_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,38 @@ impl Rule for NoFocusedTests {
fn action(ctx: &RuleContext<Self>, _: &Self::State) -> Option<JsRuleAction> {
let node = ctx.query();
let callee = node.callee().ok()?;
let function_name = callee.get_callee_member_name()?;
let replaced_function;

let mut mutation = ctx.root().begin();

match function_name.text_trimmed() {
"only" => {
if let Some(expression) = callee.as_js_static_member_expression() {
let member_name = expression.member().ok()?;
let operator_token = expression.operator_token().ok()?;
mutation.remove_element(member_name.into());
mutation.remove_element(operator_token.into());
} else if let Some(expression) = callee.as_js_computed_member_expression() {
let l_brack = expression.l_brack_token().ok()?;
let r_brack = expression.r_brack_token().ok()?;
let member = expression.member().ok()?;
let expression = member.as_any_js_literal_expression()?;
mutation.remove_token(l_brack);
mutation.remove_element(NodeOrToken::Node(expression.syntax().clone()));
mutation.remove_token(r_brack);
if let Some(function_name) = callee.get_callee_member_name() {
let replaced_function;
match function_name.text_trimmed() {
"only" => {
if let Some(expression) = callee.as_js_static_member_expression() {
let member_name = expression.member().ok()?;
let operator_token = expression.operator_token().ok()?;
mutation.remove_element(member_name.into());
mutation.remove_element(operator_token.into());
}
}
}
"fdescribe" => {
replaced_function = make::js_reference_identifier(make::ident("describe"));
mutation.replace_element(function_name.into(), replaced_function.into());
}
"fit" => {
replaced_function = make::js_reference_identifier(make::ident("it"));
mutation.replace_element(function_name.into(), replaced_function.into());
}
_ => {}
"fdescribe" => {
replaced_function = make::js_reference_identifier(make::ident("describe"));
mutation.replace_element(function_name.into(), replaced_function.into());
}
"fit" => {
replaced_function = make::js_reference_identifier(make::ident("it"));
mutation.replace_element(function_name.into(), replaced_function.into());
}
_ => {}
};
} else if let Some(expression) = callee.as_js_computed_member_expression() {
let l_brack = expression.l_brack_token().ok()?;
let r_brack = expression.r_brack_token().ok()?;
let member = expression.member().ok()?;
let expression = member.as_any_js_literal_expression()?;
mutation.remove_element(NodeOrToken::Token(l_brack));
mutation.remove_element(NodeOrToken::Node(expression.syntax().clone()));
mutation.remove_element(NodeOrToken::Token(r_brack));
};

Some(JsRuleAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ invalid.js:7:6 lint/nursery/noFocusedTests FIXABLE ━━━━━━━━━
```

```
invalid.js:9:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:9:1 lint/nursery/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
Expand All @@ -199,11 +199,15 @@ invalid.js:9:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
9 │ describe["only"]("bar",·function·()·{});
│ --------
```

```
invalid.js:10:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:10:1 lint/nursery/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
Expand All @@ -217,11 +221,15 @@ invalid.js:10:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
10 │ it["only"]("bar",·function·()·{});
│ --------
```

```
invalid.js:11:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:11:1 lint/nursery/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
Expand All @@ -236,6 +244,10 @@ invalid.js:11:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
11 │ test["only"]("bar",·function·()·{});
│ --------
```

Expand Down

0 comments on commit 76394f7

Please sign in to comment.