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

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

Closed
1 task done
mrazorvin opened this issue May 11, 2023 · 10 comments · Fixed by #4473
Closed
1 task done
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug

Comments

@mrazorvin
Copy link

Environment information

Rome: v12.0.0

What happened?

command ./node_modules/.bin/rome check ./packages --apply-unsafe

  res.onAborted(() => (aborted = true));

cause entered unreachable code

Source Location: crates/rome_js_syntax/src/expr_ext.rs:489:18
Thread Name: rome::worker_5
Message: internal error: entered unreachable code

Expected result

Fixed XXXX file(s) in YYYYms

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@mrazorvin mrazorvin added the S-To triage Status: user report of a possible bug that needs to be triaged label May 11, 2023
@ematipico ematipico added S-Bug: confirmed Status: report has been confirmed as a valid bug A-Linter Area: linter and removed S-To triage Status: user report of a possible bug that needs to be triaged labels May 11, 2023
@ematipico
Copy link
Contributor

I believe this issue was fixed. Could you try one of our latest nightlies? We're going to do a new release soon.

@denbezrukov
Copy link
Contributor

denbezrukov commented May 13, 2023

I've checked the reason why Rome crashes here.
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.

denbezrukov added a commit that referenced this issue May 14, 2023
…entered unreachable code - when --apply-unsafe #4464
denbezrukov added a commit that referenced this issue May 14, 2023
…entered unreachable code - when --apply-unsafe #4464
denbezrukov added a commit that referenced this issue May 14, 2023
…entered unreachable code - when --apply-unsafe #4464
@Conaclos
Copy link
Contributor

Conaclos commented May 15, 2023

You should certainly rewrite your code in the following way:

  res.onAborted(() => { aborted = true; return aborted });

Or if you don't need to return:

  res.onAborted(() => { aborted = true });

@mrazorvin
Copy link
Author

You should certainly rewrite your code in the following way:

  res.onAborted(() => { aborted = true; return aborted });

Or if you don't need to return:

  res.onAborted(() => { aborted = true });

This is the point of my issue, I expected this suggestion from linter in console not as comment on github

@Conaclos
Copy link
Contributor

The linter is not able to know if you mean () => { aborted = true } or () => aborted === true. However, the parenthesis around the assignment could suggest that the former suggestion is better than the latter. We decided to opt for the latter one when the rule was designed.

@mrazorvin
Copy link
Author

We have big codebase where code written by different people.
I'm okay with any linter notification that I can propagate to other team members, but when liter panic, I get no info what is wrong.

It's obviously that code should be rewritten, but I expected this information from linter

@Conaclos
Copy link
Contributor

Conaclos commented May 15, 2023

@mrazorvin We totally agree. This should be fixed by #4473 in the following release :)

@Conaclos
Copy link
Contributor

Conaclos commented May 15, 2023

For now you can disable the rule that creates the issue:

{
  "linter": {
    "enabled": true,
    "rules": {
      "suspicious": {
        "noAssignInExpressions": "off"
      }
    }
  }
}

@mrazorvin
Copy link
Author

mrazorvin commented May 15, 2023

@mrazorvin We totally agree. This should be fixed by #4473 in the following release :)

thanks, It just not always easy to change code immediately, especially when there more of those places and you need to find them manually (there not info which file contains wrong code)

@Conaclos
Copy link
Contributor

This is a bug. Rome is not intended to behave in this way. Thanks for the reporting!

denbezrukov added a commit that referenced this issue May 15, 2023
…ntered unreachable code - when --apply-unsafe #4464 (#4473)

* fix(rome_js_analyze): Files with fn(() => (aborted = true)); cause - entered unreachable code - when --apply-unsafe #4464
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug
Projects
None yet
4 participants