Skip to content

Commit

Permalink
fix(utils): accept null as default option in applyDefault (#6724)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
Solo-steven and bradzacher committed Jul 17, 2023
1 parent 1404796 commit 841889f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/utils/src/eslint-utils/deepMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type ObjectLike<T = unknown> = Record<string, T>;
* @returns `true` if obj is an object
*/
function isObjectNotArray<T extends ObjectLike>(obj: unknown): obj is T {
return typeof obj === 'object' && !Array.isArray(obj);
return typeof obj === 'object' && obj != null && !Array.isArray(obj);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/utils/tests/eslint-utils/applyDefault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ describe('applyDefault', () => {
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});

it('should work when default option is null', () => {
const defaults: unknown[] = [null];
const user: unknown[] = [
{
prop: 'setting1',
other: 'other',
},
];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual(user);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
});

0 comments on commit 841889f

Please sign in to comment.