diff --git a/.eslintrc.js b/.eslintrc.js index a94e1e5012..9f1fd2bba0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -214,6 +214,7 @@ const config = { 'unicorn/prefer-date-now': 'error', 'unicorn/no-typeof-undefined': 'error', 'unicorn/no-useless-promise-resolve-reject': 'error', + 'unicorn/no-new-array': 'error', 'unicorn/new-for-builtins': 'error', 'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-element-overwrite': 'error', diff --git a/packages/backend/server/tests/history.spec.ts b/packages/backend/server/tests/history.spec.ts index 103a7d231a..c2ed148574 100644 --- a/packages/backend/server/tests/history.spec.ts +++ b/packages/backend/server/tests/history.spec.ts @@ -183,26 +183,30 @@ test('should correctly list all history records', async t => { // insert expired data await db.snapshotHistory.createMany({ - data: new Array(10).fill(0).map((_, i) => ({ - workspaceId: snapshot.workspaceId, - id: snapshot.id, - blob: snapshot.blob, - state: snapshot.state, - timestamp: new Date(timestamp - 10 - i), - expiredAt: new Date(timestamp - 1), - })), + data: Array.from({ length: 10 }) + .fill(0) + .map((_, i) => ({ + workspaceId: snapshot.workspaceId, + id: snapshot.id, + blob: snapshot.blob, + state: snapshot.state, + timestamp: new Date(timestamp - 10 - i), + expiredAt: new Date(timestamp - 1), + })), }); // insert available data await db.snapshotHistory.createMany({ - data: new Array(10).fill(0).map((_, i) => ({ - workspaceId: snapshot.workspaceId, - id: snapshot.id, - blob: snapshot.blob, - state: snapshot.state, - timestamp: new Date(timestamp + i), - expiredAt: new Date(timestamp + 1000), - })), + data: Array.from({ length: 10 }) + .fill(0) + .map((_, i) => ({ + workspaceId: snapshot.workspaceId, + id: snapshot.id, + blob: snapshot.blob, + state: snapshot.state, + timestamp: new Date(timestamp + i), + expiredAt: new Date(timestamp + 1000), + })), }); const list = await manager.list( @@ -243,14 +247,16 @@ test('should be able to get last history record', async t => { // insert available data await db.snapshotHistory.createMany({ - data: new Array(10).fill(0).map((_, i) => ({ - workspaceId: snapshot.workspaceId, - id: snapshot.id, - blob: snapshot.blob, - state: snapshot.state, - timestamp: new Date(timestamp + i), - expiredAt: new Date(timestamp + 1000), - })), + data: Array.from({ length: 10 }) + .fill(0) + .map((_, i) => ({ + workspaceId: snapshot.workspaceId, + id: snapshot.id, + blob: snapshot.blob, + state: snapshot.state, + timestamp: new Date(timestamp + i), + expiredAt: new Date(timestamp + 1000), + })), }); const history = await manager.last(snapshot.workspaceId, snapshot.id); @@ -299,26 +305,30 @@ test('should be able to cleanup expired history', async t => { // insert expired data await db.snapshotHistory.createMany({ - data: new Array(10).fill(0).map((_, i) => ({ - workspaceId: snapshot.workspaceId, - id: snapshot.id, - blob: snapshot.blob, - state: snapshot.state, - timestamp: new Date(timestamp - 10 - i), - expiredAt: new Date(timestamp - 1), - })), + data: Array.from({ length: 10 }) + .fill(0) + .map((_, i) => ({ + workspaceId: snapshot.workspaceId, + id: snapshot.id, + blob: snapshot.blob, + state: snapshot.state, + timestamp: new Date(timestamp - 10 - i), + expiredAt: new Date(timestamp - 1), + })), }); // insert available data await db.snapshotHistory.createMany({ - data: new Array(10).fill(0).map((_, i) => ({ - workspaceId: snapshot.workspaceId, - id: snapshot.id, - blob: snapshot.blob, - state: snapshot.state, - timestamp: new Date(timestamp + i), - expiredAt: new Date(timestamp + 1000), - })), + data: Array.from({ length: 10 }) + .fill(0) + .map((_, i) => ({ + workspaceId: snapshot.workspaceId, + id: snapshot.id, + blob: snapshot.blob, + state: snapshot.state, + timestamp: new Date(timestamp + i), + expiredAt: new Date(timestamp + 1000), + })), }); let count = await db.snapshotHistory.count(); diff --git a/packages/frontend/component/src/components/setting-components/workspace-detail-skeleton.tsx b/packages/frontend/component/src/components/setting-components/workspace-detail-skeleton.tsx index 6755c200d6..dde4dfd578 100644 --- a/packages/frontend/component/src/components/setting-components/workspace-detail-skeleton.tsx +++ b/packages/frontend/component/src/components/setting-components/workspace-detail-skeleton.tsx @@ -8,17 +8,19 @@ export const WorkspaceDetailSkeleton = () => { <> } subtitle={} /> - {new Array(3).fill(0).map((_, index) => { - return ( - } key={index}> - } - desc={} - spreadCol={false} - > - - ); - })} + {Array.from({ length: 3 }) + .fill(0) + .map((_, index) => { + return ( + } key={index}> + } + desc={} + spreadCol={false} + > + + ); + })} ); }; diff --git a/packages/frontend/component/src/components/setting-components/workspace-list-skeleton.tsx b/packages/frontend/component/src/components/setting-components/workspace-list-skeleton.tsx index 170798d4a4..8783ab82b0 100644 --- a/packages/frontend/component/src/components/setting-components/workspace-list-skeleton.tsx +++ b/packages/frontend/component/src/components/setting-components/workspace-list-skeleton.tsx @@ -26,9 +26,11 @@ export const WorkspaceListItemSkeleton = () => { export const WorkspaceListSkeleton = () => { return ( <> - {new Array(5).fill(0).map((_, index) => { - return ; - })} + {Array.from({ length: 5 }) + .fill(0) + .map((_, index) => { + return ; + })} ); }; diff --git a/packages/frontend/graphql/src/utils.ts b/packages/frontend/graphql/src/utils.ts index 138a427bdd..4e2a1f8e83 100644 --- a/packages/frontend/graphql/src/utils.ts +++ b/packages/frontend/graphql/src/utils.ts @@ -3,7 +3,7 @@ export const TRACE_ID_BYTES = 16; export const TRACE_VERSION = '00'; export const TRACE_FLAG = '01'; -const BytesBuffer = new Array(32); +const BytesBuffer = Array.from({ length: 32 }); type TraceSpan = { name: string; diff --git a/tests/affine-cloud/e2e/collaboration.spec.ts b/tests/affine-cloud/e2e/collaboration.spec.ts index 2be5db6571..2af8c02d54 100644 --- a/tests/affine-cloud/e2e/collaboration.spec.ts +++ b/tests/affine-cloud/e2e/collaboration.spec.ts @@ -265,7 +265,9 @@ test.describe('collaboration members', () => { await addUserToWorkspace(workspaceId, userB.id, 1 /* READ */); }; await Promise.all( - new Array(10).fill(1).map(() => createUserAndAddToWorkspace()) + Array.from({ length: 10 }) + .fill(1) + .map(() => createUserAndAddToWorkspace()) ); await openSettingModal(page);