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(utils): accept null as default option in applyDefault #6724

Merged
merged 6 commits into from Jul 17, 2023

Conversation

Solo-steven
Copy link
Contributor

PR Checklist

Overview

fix issue #6439

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Solo-steven!

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.

@netlify
Copy link

netlify bot commented Mar 21, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 081e79f
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64b4932e77d0360008a1be78
😎 Deploy Preview https://deploy-preview-6724--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 configuration.

@Solo-steven Solo-steven changed the title Fix/issue 6439 fix(utils): fix issue 6439, accept null as default option Mar 21, 2023
@nx-cloud
Copy link

nx-cloud bot commented Mar 21, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 081e79f. 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 35 targets

Sent with 💌 from NxCloud.

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #6724 (081e79f) into main (d67fd6d) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6724   +/-   ##
=======================================
  Coverage   87.47%   87.47%           
=======================================
  Files         379      379           
  Lines       13228    13228           
  Branches     3905     3905           
=======================================
  Hits        11571    11571           
  Misses       1279     1279           
  Partials      378      378           
Flag Coverage Δ
unittest 87.47% <100.00%> (ø)

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

Impacted Files Coverage Δ
packages/utils/src/eslint-utils/deepMerge.ts 89.47% <100.00%> (ø)

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

I guess the question here is whether or not an explicit null should be ignored like this and overridden by the default, or if it should be seen as a value that shouldn't be overridden.

I think an explicit null should not be overridden, personally.

@Solo-steven
Copy link
Contributor Author

@bradzacher Thanks for your reply, I think another solution is adding one more conditional to isObjectNotArray like

function isObjectNotArray<T extends ObjectLike>(
  obj: unknown | unknown[],
): obj is T {
  return typeof obj === 'object' && obj != null && !Array.isArray(obj);
}

this solution wouldn't overwrite the null value .

But I want to know why we shouldn't overwrite the value, is it cause more errors?

@bradzacher
Copy link
Member

But I want to know why we shouldn't overwrite the value, is it cause more errors?

If a user does a config like { foo: null }, and the default is { foo: { bar: '' } }, then we should not override the explicit null with { bar: '' }.
The same can be said for a top-level null. If the user configures a rule like ['error', null], then we should not override that explicit null with whatever the default is.

Instead I think that we should only override undefined, as we currently do for non-top-level values.

@JoshuaKGoldberg JoshuaKGoldberg changed the title fix(utils): fix issue 6439, accept null as default option fix(utils): accept null as default option Mar 21, 2023
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.

Nice, thanks for this!

packages/utils/src/eslint-utils/applyDefault.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Mar 21, 2023

Oh 🤦 my GitHub did a weird and I didn't see @bradzacher's comments. Ignore me, and sorry for the force pushing!

@Solo-steven Solo-steven requested review from JoshuaKGoldberg and removed request for bradzacher March 23, 2023 12:49
@bradzacher bradzacher added the bug Something isn't working label Apr 10, 2023
@JoshuaKGoldberg
Copy link
Member

👋 @bradzacher I think this got dropped from the queue because I did a silly. Do you want to review this one?

It looks good to me, but just making sure.

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.

💯 Thanks! And, sorry for the long wait!

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Jul 16, 2023
@bradzacher bradzacher changed the title fix(utils): accept null as default option fix(utils): accept null as default option in applyDefault Jul 17, 2023
@bradzacher bradzacher merged commit 841889f into typescript-eslint:main Jul 17, 2023
46 of 50 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: null as default option is failing in applyDefault
3 participants