Skip to content

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

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

Conversation

abrahamguo
Copy link
Contributor

@abrahamguo abrahamguo commented Oct 15, 2024

PR Checklist

Overview

Re-applies #5234, while accounting for updates made since to prefer-nullish-coalescing.

Commits:

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @abrahamguo!

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.

@abrahamguo abrahamguo marked this pull request as draft October 15, 2024 12:19
Copy link

netlify bot commented Oct 15, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 22841da
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/671698d6a3b5760008057386
😎 Deploy Preview https://deploy-preview-10152--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: 97 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (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 15, 2024

☁️ Nx Cloud Report

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

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@abrahamguo abrahamguo force-pushed the prefer-nullish-coalescing-assignments branch from 3dd873d to 1e3281a Compare October 15, 2024 12:21
@abrahamguo abrahamguo marked this pull request as ready for review October 15, 2024 12:54
@abrahamguo abrahamguo changed the title fix(eslint-plugin): [prefer-nullish-coalescing] fix(eslint-plugin): [prefer-nullish-coalescing]: add support for assignment expressions Oct 15, 2024
@abrahamguo abrahamguo changed the title fix(eslint-plugin): [prefer-nullish-coalescing]: add support for assignment expressions feat(eslint-plugin): [prefer-nullish-coalescing]: add support for assignment expressions Oct 15, 2024
@abrahamguo abrahamguo 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 Oct 15, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.16%. Comparing base (c8e7c27) to head (22841da).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10152      +/-   ##
==========================================
- Coverage   86.18%   86.16%   -0.02%     
==========================================
  Files         430      430              
  Lines       15029    15031       +2     
  Branches     4360     4361       +1     
==========================================
- Hits        12952    12951       -1     
- Misses       1725     1728       +3     
  Partials      352      352              
Flag Coverage Δ
unittest 86.16% <100.00%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...lint-plugin/src/rules/prefer-nullish-coalescing.ts 97.70% <100.00%> (-2.30%) ⬇️
packages/rule-tester/src/utils/config-validator.ts 27.41% <100.00%> (ø)
packages/type-utils/src/TypeOrValueSpecifier.ts 100.00% <ø> (ø)
packages/type-utils/src/builtinSymbolLikes.ts 4.91% <ø> (ø)
.../src/typeOrValueSpecifiers/specifierNameMatches.ts 100.00% <ø> (ø)

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.

Looks pretty reasonable! Requesting changes on keeping tests more precise. Thanks! ⚒️

@@ -171,7 +171,107 @@ export default createRule<Options, MessageIds>({
});
}

// todo: rename to something more specific?
Copy link
Member

Choose a reason for hiding this comment

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

todo

What's the resolution here? FWIW I don't mind the name as-is.

@@ -197,7 +197,7 @@ function validateConfigSchema(
config: TesterConfigWithDefaults,
source: string,
): void {
validateSchema ||= ajv.compile(flatConfigSchema);
validateSchema ??= ajv.compile(flatConfigSchema);
Copy link
Member

Choose a reason for hiding this comment

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

[Praise] Nice, a fix in the project itself!

@@ -30,31 +30,42 @@ const nullishTypes = ['null', 'undefined', 'null | undefined'];
const ignorablePrimitiveTypes = ['string', 'number', 'boolean', 'bigint'];

function typeValidTest(
cb: (type: string) => ValidTestCase<Options> | string,
cb: (type: string, equals: '' | '=') => ValidTestCase<Options> | string,
Copy link
Member

Choose a reason for hiding this comment

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

[Testing] We've been moving away from auto-generated tests. They tend to generate a huge spread of unit tests that each test ever so slightly different variations of the same thing. For example, this one now means each intricacy passed to typeValidTest is tested under both values of equals.

IMO it'd be better to instead have specific targeted tests for each behavior under test.

Change request: revert any additions to these test generation functions, and instead write new tests manually.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Oct 21, 2024
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.

Oh LOL I did a brain fart, this is a re-application of changes. Got mixed up. LGTM, thanks!

@JoshuaKGoldberg
Copy link
Member

I'd switched from const to let for consistency, I think. Not a major preference.

@JoshuaKGoldberg JoshuaKGoldberg removed the awaiting response Issues waiting for a reply from the OP or another party label Oct 21, 2024
@JoshuaKGoldberg JoshuaKGoldberg merged commit e765033 into typescript-eslint:main Oct 21, 2024
63 of 64 checks passed
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Oct 28, 2024
##### [v8.12.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8120-2024-10-28)

##### 🚀 Features

-   **eslint-plugin:** \[no-base-to-string] handle String() ([#10005](typescript-eslint/typescript-eslint#10005))
-   **eslint-plugin:** \[switch-exhaustiveness-check] add allowDefaultCaseMatchUnionMember option ([#9954](typescript-eslint/typescript-eslint#9954))
-   **eslint-plugin:** \[consistent-indexed-object-style] report mapped types ([#10160](typescript-eslint/typescript-eslint#10160))
-   **eslint-plugin:** \[prefer-nullish-coalescing] add support for assignment expressions ([#10152](typescript-eslint/typescript-eslint#10152))

##### ❤️  Thank You

-   Abraham Guo
-   Kim Sang Du [@developer-bandi](https://github.com/developer-bandi)
-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [prefer-nullish-coalescing] OR assignment operator(||=) does not report errors or suggest corrections.
2 participants