Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [prefer-nullish-coalescing] fix parenthesization bug in suggestion#11098

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

mdm317
Copy link
Contributor

PR Checklist

Overview

When running theFix, add parentheses to conditional expressions that are missing them

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@mdm317!

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 onhttps://opencollective.com/typescript-eslint.

@netlifyNetlify
Copy link

netlifybot commentedApr 24, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commitdd690c4
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/68137f2db62b5000081b7b24
😎 Deploy Previewhttps://deploy-preview-11098--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: 98 (no change 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 yourNetlify site configuration.

@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedApr 24, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commitdd690c4.

CommandStatusDurationResult
nx typecheck ast-spec✅ Succeeded<1sView ↗
nx run-many --target=build --exclude website --...✅ Succeeded1sView ↗
nx run-many --target=clean✅ Succeeded11sView ↗

☁️Nx Cloud last updated this comment at2025-05-01 14:25:30 UTC

@codecovCodecov
Copy link

codecovbot commentedApr 24, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.84%. Comparing base(cc2d6ec) to head(dd690c4).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@##             main   #11098   +/-   ##=======================================  Coverage   90.83%   90.84%           =======================================  Files         497      497             Lines       50279    50295   +16       Branches     8297     8299    +2     =======================================+ Hits        45672    45690   +18+ Misses       4592     4590    -2  Partials       15       15
FlagCoverage Δ
unittest90.84% <100.00%> (+<0.01%)⬆️

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

Files with missing linesCoverage Δ
...lint-plugin/src/rules/prefer-nullish-coalescing.ts98.26% <100.00%> (+0.03%)⬆️

... and1 file with indirect coverage changes

🚀 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.

@mdm317mdm317 marked this pull request as ready for reviewApril 24, 2025 14:30
@OlivierZal
Copy link
Contributor

Looks good!

mdm317 reacted with heart emoji

Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Looks like it will solve the specific bug case but just have a question about being generic and/or reusing code. Thanks for sending!

@@ -932,3 +934,17 @@ function formatComments(
)
.join('');
}

function getTextWithEnsuredParentheses(
Copy link
Member

@kirkwaiblingerkirkwaiblingerApr 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

I wonder if we can leverage existing infrastructure around parenthesization/wrapping rather than hard-code a special case fora ? b : c... is there a specific reason to do that? I worry we might miss parens on other expressions that might need it?

FWIW I had success passing all the test cases with the following...

context.report({            node,messageId:'preferNullishOverTernary',// TODO: also account for = in the ternary clausedata:{equals:''},suggest:[{messageId:'suggestNullish',data:{equals:''},fix(fixer:TSESLint.RuleFixer):TSESLint.RuleFix{returnfixer.replaceText(node,`${getTextWithParentheses(context.sourceCode,nullishCoalescingParams.nullishCoalescingLeftNode,)} ??${(()=>{constbranch=getBranchNodes(node,operator,).nullishBranch;if(isParenthesized(branch,context.sourceCode)){returngetTextWithParentheses(context.sourceCode,branch,);}returngetWrappedCode(getTextWithParentheses(context.sourceCode,branch),getOperatorPrecedenceForNode(branch),OperatorPrecedence.Coalesce,);})()}`,);},},],});

Curious what you think!

JoshuaKGoldberg reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It definitely seems much better to use the existing infrastructure rather than hard-coding it!
I've updated the code to use your approach.
Thanks for pointing it out!

kirkwaiblinger reacted with thumbs up emoji
@kirkwaiblingerkirkwaiblinger added the awaiting responseIssues waiting for a reply from the OP or another party labelApr 28, 2025
@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelApr 30, 2025
Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Thanks for sending this in!

mdm317 reacted with heart emoji
@kirkwaiblingerkirkwaiblinger added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelMay 1, 2025
@kirkwaiblingerkirkwaiblinger changed the titlefix(eslint-plugin): [prefer-nullish-coalescing] mal-fixes nested conditional expressionfix(eslint-plugin): [prefer-nullish-coalescing] fix parenthesization bug in suggestionMay 1, 2025
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Super!

Great review suggestion too Kirk :)

kirkwaiblinger reacted with heart emoji
@JoshuaKGoldbergJoshuaKGoldberg merged commit9d6a6d0 intotypescript-eslint:mainMay 2, 2025
61 checks passed
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMay 10, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@kirkwaiblingerkirkwaiblingerkirkwaiblinger approved these changes

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: @typescript-eslint/prefer-nullish-coalescing mal-fixes nested condition
4 participants
@mdm317@OlivierZal@JoshuaKGoldberg@kirkwaiblinger

[8]ページ先頭

©2009-2025 Movatter.jp