Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lint/noUnreachable): correctly analyze nested try-finally statements #1856

Merged
merged 6 commits into from
Feb 26, 2024

Conversation

ah-yu
Copy link
Contributor

@ah-yu ah-yu commented Feb 18, 2024

Summary

Closes #1827

The noUnreachable rule offers two approaches for analysis

if exceeds_complexity_threshold(cfg) {
analyze_simple(cfg, &mut signals)
} else {
analyze_fine(cfg, &mut signals)
}

The reported bug is caused by nested try statements, but it only occurs with analyze_simple.

Let's consider the following example (assuming the analysis is driven by analyze_simple)

try {
  try {
  } finally {
    if (mayThrow()) {
         // block 1
    }
    foo() // block 2
  }
} catch (e) {
  // block 3
}
  • If the mayThrow() function throws an exception, then block 1 jumps to block 3
  • If the mayThrow() function doesn't throw an exception, then block 1 jumps to block 2.

In the current implementation, we only handle the first scenario, but not the second. So we need to handle the second scenario.

Test Plan

Add a new test case

@github-actions github-actions bot added A-Linter Area: linter A-Website Area: website L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels Feb 18, 2024
Copy link

netlify bot commented Feb 18, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit e2811f7
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/65dc03b45193100008537881
😎 Deploy Preview https://deploy-preview-1856--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🔴 down 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codspeed-hq bot commented Feb 18, 2024

CodSpeed Performance Report

Merging #1856 will not alter performance

⚠️ No base runs were found

Falling back to comparing ah-yu:no_unreachable (e2811f7) with main (1957fb0)

Summary

✅ 93 untouched benchmarks

@ah-yu ah-yu marked this pull request as draft February 18, 2024 09:20
@Conaclos
Copy link
Member

Thanks for your contribution! We should also evaluate if other rules that use the control flow graph need to be updated.

@ah-yu
Copy link
Contributor Author

ah-yu commented Feb 19, 2024

Hi @Conaclos Thank you for the review! The fix is related to finally_fallthrough, and upon searching, I only found the noUnreachable rule using it.

I am not confident about the fix, could you please help check the PR description and see if the fix is heading in the right direction? Thanks!

@Conaclos
Copy link
Member

Hi @Conaclos Thank you for the review! The fix is related to finally_fallthrough, and upon searching, I only found the noUnreachable rule using it.

I am not confident about the fix, could you please help check the PR description and see if the fix is heading in the right direction? Thanks!

Sorry I missed your answer.

Looking at the fix and the repro, this looks good to me :)

@ah-yu ah-yu changed the title fix(lint/noUnreachable): correctly handle finally clause for nested try statements fix(lint/noUnreachable): correctly analyzing try-finally statements Feb 26, 2024
@ah-yu ah-yu marked this pull request as ready for review February 26, 2024 03:23
@ah-yu ah-yu changed the title fix(lint/noUnreachable): correctly analyzing try-finally statements fix(lint/noUnreachable): correctly analyze nested try-finally statements Feb 26, 2024
@Conaclos Conaclos merged commit e7b98ae into biomejs:main Feb 26, 2024
19 checks passed
@Conaclos
Copy link
Member

Thanks!

@ah-yu ah-yu deleted the no_unreachable branch February 27, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Linter Area: linter A-Website Area: website L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💅 lint/correctness/noUnreachable false positive
2 participants