Skip to content

Commit

Permalink
chore: enable unicorn/prefer-structured-clone (typescript-eslint#9911)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamguo authored Sep 3, 2024
1 parent 1d40aa4 commit 6f24fe6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export default tseslint.config(
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-structured-clone': 'error',
},
},
{
Expand Down
4 changes: 1 addition & 3 deletions packages/utils/src/eslint-utils/applyDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ function applyDefault<User extends readonly unknown[], Default extends User>(
userOptions: Readonly<User> | null,
): Default {
// clone defaults
const options = JSON.parse(
JSON.stringify(defaultOptions),
) as AsMutable<Default>;
const options = structuredClone(defaultOptions) as AsMutable<Default>;

if (userOptions == null) {
return options;
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/tests/eslint-utils/applyDefault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('applyDefault', () => {
const user = null;
const result = ESLintUtils.applyDefault(defaults, user);

expect(result).toStrictEqual(defaults);
expect(result).toEqual(defaults);
expect(result).not.toBe(defaults);
});

Expand All @@ -28,7 +28,7 @@ describe('applyDefault', () => {
];
const result = ESLintUtils.applyDefault(defaults, user);

expect(result).toStrictEqual([
expect(result).toEqual([
{
prop: 'new',
other: 'something',
Expand All @@ -55,7 +55,7 @@ describe('applyDefault', () => {
const user: unknown[] = ['2tbs'];
const result = ESLintUtils.applyDefault(defaults, user);

expect(result).toStrictEqual(['2tbs']);
expect(result).toEqual(['2tbs']);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
Expand All @@ -69,7 +69,7 @@ describe('applyDefault', () => {
},
];
const result = ESLintUtils.applyDefault(defaults, user);
expect(result).toStrictEqual(user);
expect(result).toEqual(user);
expect(result).not.toBe(defaults);
expect(result).not.toBe(user);
});
Expand Down

0 comments on commit 6f24fe6

Please sign in to comment.