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

fix(rome_js_analyze): Files with fn(() => (aborted = true)); cause -entered unreachable code - when --apply-unsafe #4464 #4473

Merged
merged 3 commits into from
May 15, 2023

Conversation

denbezrukov
Copy link
Contributor

Summary

Fix #4464

We have the noAssignInExpressions rule.

fn action(ctx: &RuleContext<Self>, _: &Self::State) -> Option<JsRuleAction> {
let assign = ctx.query();
let op = assign.operator().ok()?;
if let JsAssignmentOperator::Assign = op {
let operator_token = assign.operator_token().ok()?;
let new_operator_token = make::token(JsSyntaxKind::EQ3);
let mut mutation = ctx.root().begin();
mutation.replace_token(operator_token, new_operator_token);
Some(JsRuleAction {
mutation,
applicability: Applicability::MaybeIncorrect,
category: ActionCategory::QuickFix,
message: markup!("Did you mean '==='?").to_owned(),
})
} else {
None
}
}
}

We replace the token here with ===. However, the node remains a JsAssignmentExpression, and the subsequent noSelfAssign rule tries to retrieve the operator from the JsAssignmentExpression. This causes an issue because the node now contains ===.

I guess that the solution is to convert JsAssignmentExpression into JsBinaryExpression in the noAssignInExpressions rule.

Test Plan

cargo test

Changelog

  • The PR requires a changelog line

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

…entered unreachable code - when --apply-unsafe #4464
@netlify
Copy link

netlify bot commented May 14, 2023

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit 77d9e64
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/64611af4498ee80007cd9661

@github-actions github-actions bot added A-CLI Area: CLI A-Linter Area: linter labels May 14, 2023
@Conaclos
Copy link
Contributor

LGTM

@denbezrukov denbezrukov merged commit 0cb1680 into main May 15, 2023
16 checks passed
@denbezrukov denbezrukov deleted the fix/lint-crash branch May 15, 2023 14:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-CLI Area: CLI A-Linter Area: linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Files with fn(() => (aborted = true)); cause - entered unreachable code - when --apply-unsafe
2 participants