Skip to content

feat(eslint-plugin): [prefer-optional-chain] support if statement as part of chain #10137

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

Open
wants to merge 51 commits into
base: main
Choose a base branch
from

Conversation

omril1
Copy link
Contributor

@omril1 omril1 commented Oct 12, 2024

PR Checklist

Overview

Add an allowIfStatements option that would look at if statements with a single call expression in their body and try to report a suggestion for a bigger chain that includes the if's test node and body node

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @omril1!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Oct 12, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit cbfb329
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/67d68d4f9892e40008f3ff05
😎 Deploy Preview https://deploy-preview-10137--typescript-eslint.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: 94 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

Copy link

nx-cloud bot commented Oct 12, 2024

View your CI Pipeline Execution ↗ for commit cbfb329.

Command Status Duration Result
nx test eslint-plugin ✅ Succeeded 7m 44s View ↗
nx run eslint-plugin:test -- --coverage ✅ Succeeded 6m 14s View ↗
nx test eslint-plugin --coverage=false ✅ Succeeded 6m 28s View ↗
nx test typescript-estree ✅ Succeeded 1m 17s View ↗
nx test scope-manager ✅ Succeeded <1s View ↗
nx run types:build ✅ Succeeded <1s View ↗
nx test typescript-eslint ✅ Succeeded 10s View ↗
nx run-many --target=build --exclude website --... ✅ Succeeded 21s View ↗
Additional runs (25) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-03-16 08:49:30 UTC

@omril1 omril1 force-pushed the feat-eslint-plugin-issue-6309-prefer-optional-chain-support-if-statement branch from 41e9ec4 to 075c034 Compare October 12, 2024 11:11
@omril1 omril1 force-pushed the feat-eslint-plugin-issue-6309-prefer-optional-chain-support-if-statement branch from 075c034 to fd1c08d Compare October 12, 2024 11:12
Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.63%. Comparing base (543d36c) to head (cbfb329).
Report is 53 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10137      +/-   ##
==========================================
+ Coverage   87.58%   87.63%   +0.05%     
==========================================
  Files         470      470              
  Lines       16095    16162      +67     
  Branches     4668     4688      +20     
==========================================
+ Hits        14097    14164      +67     
  Misses       1642     1642              
  Partials      356      356              
Flag Coverage Δ
unittest 87.63% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../rules/prefer-optional-chain-utils/analyzeChain.ts 100.00% <100.00%> (ø)
...s/eslint-plugin/src/rules/prefer-optional-chain.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@omril1 omril1 marked this pull request as ready for review October 13, 2024 10:14
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! This is a tricky rule to work with and I like how you stayed with the existing flow with it. Nicely done! 👏

I found a few cases that'll need to have support, such as comments in the rule.

Family Guy's Stewie Griffin telling Brian "good stuff. good stuff."

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Nov 4, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Jan 18, 2025
@omril1
Copy link
Contributor Author

omril1 commented Mar 5, 2025

@JoshuaKGoldberg ping, I saw a lot of your other work in the typescript/eslint/typescript-eslint repos, and I get that you are busy, but can we please advance this?

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay! I've personally mostly stepped back from reviewing specific rule PRs, especially tricky ones like this. But the change is exciting and I want to be helpful - please do ping if I take weeks to get back to you again.

I think the autofixing/suggesting is still a little too brittle and can be reworked to better handle some comments. Left a few comments suggesting strategies.

? sourceCode.getCommentsBefore(tokenAfterAfterNodeTest)
: []; // if (foo) /* this */

const commentsToReloacte = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Typo]

Suggested change
const commentsToReloacte = [
const commentsToRelocate = [

@JoshuaKGoldberg
Copy link
Member

👋 Just checking in @omril1, is this still something you have time for?

@JoshuaKGoldberg JoshuaKGoldberg added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Apr 14, 2025
@omril1
Copy link
Contributor Author

omril1 commented Apr 14, 2025

👋 Just checking in @omril1, is this still something you have time for?

@JoshuaKGoldberg I think I'm giving up on this. The rule as it is currently doesn't handle all of the comments between the optional chaining nodes, and this PR is reusing all of the existing logic from analyzeChain.

I have no interest in expanding the scope of the PR, as it was already hard enough for me to integrate IfStatement into the current logic.

@JoshuaKGoldberg
Copy link
Member

Ah, I'm sorry to hear that - especially since I think this is largely my fault for trying to sling a lot of annoying comments work on you. I think what was missing on my end was I'd thought there was existing comment handling that was being regressed here. But I think it'd be better to get this in and file a followup issue for the comments. Do you think you'd have time to just wontfix my comments there?

@omril1
Copy link
Contributor Author

omril1 commented Apr 14, 2025

Ah, I'm sorry to hear that - especially since I think this is largely my fault for trying to sling a lot of annoying comments work on you. I think what was missing on my end was I'd thought there was existing comment handling that was being regressed here. But I think it'd be better to get this in and file a followup issue for the comments. Do you think you'd have time to just wontfix my comments there?

I'm not sure what 'wontfix' mean, do you want me to just acknowledge it as out of scope in each discussion?

I'll probably try to pick easier PRs to work on next time, I just liked how this rule helped simplify the awful legacy codebases I worked on 😄

@JoshuaKGoldberg
Copy link
Member

Exactly: whatever you don't have scope to do, mention that in the conversation.

And yeah, this is one of my favorite rules too. Really a pity what a nightmare working with its implementation is. 🥲

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for team members to take a look and removed awaiting response Issues waiting for a reply from the OP or another party stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period labels Apr 15, 2025
@JoshuaKGoldberg JoshuaKGoldberg self-requested a review April 15, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Waiting for team members to take a look
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants