Repository: ViacomInc/data-point
Pull request #403 (2019-08-28 17:13:50)

fix(data-point): fix check against null
<!--
Thanks for your interest in the project. We appreciate bugs filed and PRs submitted!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!

BREAKING CHANGES:

If your PR includes a breaking change, please submit it with a codemod under
data-point-codemods that will help users upgrade their codebase.

Breaking changes without a codemod will not be accepted unless a codemod is not
viable or does not apply to the specific situation.
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->
**What**:

fix checking against null

<!-- Why are these changes necessary? -->
**Why**:

was not and had a false positive

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Has Breaking changes
- [ ] Documentation
- [x] Tests
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [ ] Added username to **all-contributors** list

<!-- feel free to add additional comments -->


codecov[bot]: # [Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=h1) Report
> Merging [#403](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=desc) into [canary](https://codecov.io/gh/ViacomInc/data-point/commit/1a8098a340d972eb86966346a79bfd54324af0d8?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/ViacomInc/data-point/pull/403/graphs/tree.svg?width=650&token=LYxItnrx4i&height=150&src=pr)](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           canary   #403   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          24     24           
  Lines         388    388           
  Branches       57     57           
=====================================
  Hits          388    388
```


| [Impacted Files](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/data-point/src/is-plain-object.js](https://codecov.io/gh/ViacomInc/data-point/pull/403/diff?src=pr&el=tree#diff-cGFja2FnZXMvZGF0YS1wb2ludC9zcmMvaXMtcGxhaW4tb2JqZWN0Lmpz) | `100% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=footer). Last update [1a8098a...6982df7](https://codecov.io/gh/ViacomInc/data-point/pull/403?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/data-point/src/is-plain-object.js b/packages/data-point/src/is-plain-object.js
index dbc99bc..29b8a29 100644
--- a/packages/data-point/src/is-plain-object.js
+++ b/packages/data-point/src/is-plain-object.js
@@ -1,6 +1,19 @@
+/**
+ * This method is used to check if the argument passed is a simple object.
+ *
+ * Please take a look at the unit tests of this module to understand which
+ * values are considered an object.
+ *
+ * If there are more cases that need to be considered please create an issue.
+ *
+ * @param {any} obj
+ * @returns {Boolean} true if object created via `{}`
+ */
 function isPlainObject(obj) {
   return (
-    typeof obj === "object" && Object.getPrototypeOf(obj) === Object.prototype
+    obj !== null &&
+    typeof obj === "object" &&
+    Object.getPrototypeOf(obj) === Object.prototype
   );
 }
 module.exports = isPlainObject;


Test patch:
diff --git a/packages/data-point/src/is-plain-object.test.js b/packages/data-point/src/is-plain-object.test.js
index 6c113ed..3bf69e5 100644
--- a/packages/data-point/src/is-plain-object.test.js
+++ b/packages/data-point/src/is-plain-object.test.js
@@ -5,6 +5,8 @@ describe("isPlainObject", () => {
     expect(isPlainObject({})).toEqual(true);
     expect(isPlainObject("string")).toEqual(false);
     expect(isPlainObject(123)).toEqual(false);
+    expect(isPlainObject(null)).toEqual(false);
+    expect(isPlainObject([])).toEqual(false);
     expect(isPlainObject(() => true)).toEqual(false);
 
     expect(isPlainObject(Object.create({}))).toEqual(false);