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

feat(eslint-plugin): [prefer-nullish-coalescing]: add support for assignment expressions #5234

Conversation

JoshuaKGoldberg
Copy link
Member

PR Checklist

Overview

Adds ||= to ??= support to the rule by reusing much of the existing rule's logic.

Note that this is a breaking change, as it targets a significant new area of syntax. We'll probably have to wait until 6.X to merge. 😕

@JoshuaKGoldberg JoshuaKGoldberg added the breaking change This change will require a new major version to be released label Jun 23, 2022
@nx-cloud
Copy link

nx-cloud bot commented Jun 23, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 9678f6c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 46 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @JoshuaKGoldberg!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@netlify
Copy link

netlify bot commented Jun 23, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 4b965a4
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6358780652472d0008e0c8e0
😎 Deploy Preview https://deploy-preview-5234--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@codecov
Copy link

codecov bot commented Jun 23, 2022

Codecov Report

Merging #5234 (9678f6c) into v6 (c4e0d86) will increase coverage by 0.11%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v6    #5234      +/-   ##
==========================================
+ Coverage   91.33%   91.44%   +0.11%     
==========================================
  Files         361      355       -6     
  Lines       12044    12060      +16     
  Branches     3506     3531      +25     
==========================================
+ Hits        11000    11028      +28     
+ Misses        748      733      -15     
- Partials      296      299       +3     
Flag Coverage Δ
unittest 91.44% <100.00%> (+0.11%) ⬆️

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

Impacted Files Coverage Δ
...lint-plugin/src/rules/prefer-nullish-coalescing.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/analyze.ts 57.89% <0.00%> (-7.49%) ⬇️
packages/scope-manager/src/ScopeManager.ts 77.21% <0.00%> (-2.54%) ⬇️
packages/typescript-estree/src/convert.ts 97.59% <0.00%> (-0.30%) ⬇️
...ackages/scope-manager/src/referencer/Referencer.ts 95.90% <0.00%> (-0.07%) ⬇️
packages/utils/src/ts-eslint/CLIEngine.ts 33.33% <0.00%> (ø)
packages/utils/src/eslint-utils/RuleCreator.ts 75.00% <0.00%> (ø)
...ges/typescript-estree/src/create-program/shared.ts 83.33% <0.00%> (ø)
...pt-estree/src/create-program/createWatchProgram.ts 78.06% <0.00%> (ø)
...-estree/src/create-program/createProjectProgram.ts 93.47% <0.00%> (ø)
... and 14 more

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review June 23, 2022 16:27
@jakebailey
Copy link
Collaborator

jakebailey commented Jun 23, 2022

Thanks for working on this! I'm currently running this on the TS codebase (as in some benchmarks, even our downleveled code for ?? with explicit undefined/null checks is faster than the boolean conversion; benchmark). I'll just pull this into my local fork for now, if it's not going in any time soon.

(I have to fork in order to skip the rule when the left side is potentially a string/number/boolean; applying the fixes from this rule without review breaks a few things as the behavior is not equivalent.)

@bradzacher
Copy link
Member

note that technically a ||= b is equivalent to a || (a = b), not a = a || b.
(similarly a ??= b is a ?? (a = b), not a = a ?? b)

This is a very slight difference that makes them marginally faster because you only assign if it's required.

@bradzacher bradzacher changed the base branch from main to v6 October 26, 2022 01:42
@bradzacher bradzacher added this to the 6.0.0 milestone Oct 26, 2022
@bradzacher bradzacher changed the title feat(eslint-plugin) [prefer-nullish-coalescing]: add support for assignment expressions feat(eslint-plugin): [prefer-nullish-coalescing]: add support for assignment expressions Nov 16, 2022
@bradzacher bradzacher merged commit b8c65fd into typescript-eslint:v6 Nov 16, 2022
@JoshuaKGoldberg JoshuaKGoldberg deleted the prefer-nullish-coalescing-assignments branch November 16, 2022 13:23
bradzacher pushed a commit that referenced this pull request Nov 23, 2022
…ignment expressions (#5234)

BREAKING CHANGE:
Adds an additional class of checks to the rule
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change This change will require a new major version to be released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [prefer-nullish-coalescing] recognize "||="
3 participants