fix: add no-new-array rule (#5117)

This commit is contained in:
LongYinan
2023-11-29 04:44:06 +00:00
parent 68caf5027d
commit cb2c659f52
6 changed files with 73 additions and 56 deletions

View File

@@ -214,6 +214,7 @@ const config = {
'unicorn/prefer-date-now': 'error', 'unicorn/prefer-date-now': 'error',
'unicorn/no-typeof-undefined': 'error', 'unicorn/no-typeof-undefined': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error', 'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-new-array': 'error',
'unicorn/new-for-builtins': 'error', 'unicorn/new-for-builtins': 'error',
'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-all-duplicated-branches': 'error',
'sonarjs/no-element-overwrite': 'error', 'sonarjs/no-element-overwrite': 'error',

View File

@@ -183,7 +183,9 @@ test('should correctly list all history records', async t => {
// insert expired data // insert expired data
await db.snapshotHistory.createMany({ await db.snapshotHistory.createMany({
data: new Array(10).fill(0).map((_, i) => ({ data: Array.from({ length: 10 })
.fill(0)
.map((_, i) => ({
workspaceId: snapshot.workspaceId, workspaceId: snapshot.workspaceId,
id: snapshot.id, id: snapshot.id,
blob: snapshot.blob, blob: snapshot.blob,
@@ -195,7 +197,9 @@ test('should correctly list all history records', async t => {
// insert available data // insert available data
await db.snapshotHistory.createMany({ await db.snapshotHistory.createMany({
data: new Array(10).fill(0).map((_, i) => ({ data: Array.from({ length: 10 })
.fill(0)
.map((_, i) => ({
workspaceId: snapshot.workspaceId, workspaceId: snapshot.workspaceId,
id: snapshot.id, id: snapshot.id,
blob: snapshot.blob, blob: snapshot.blob,
@@ -243,7 +247,9 @@ test('should be able to get last history record', async t => {
// insert available data // insert available data
await db.snapshotHistory.createMany({ await db.snapshotHistory.createMany({
data: new Array(10).fill(0).map((_, i) => ({ data: Array.from({ length: 10 })
.fill(0)
.map((_, i) => ({
workspaceId: snapshot.workspaceId, workspaceId: snapshot.workspaceId,
id: snapshot.id, id: snapshot.id,
blob: snapshot.blob, blob: snapshot.blob,
@@ -299,7 +305,9 @@ test('should be able to cleanup expired history', async t => {
// insert expired data // insert expired data
await db.snapshotHistory.createMany({ await db.snapshotHistory.createMany({
data: new Array(10).fill(0).map((_, i) => ({ data: Array.from({ length: 10 })
.fill(0)
.map((_, i) => ({
workspaceId: snapshot.workspaceId, workspaceId: snapshot.workspaceId,
id: snapshot.id, id: snapshot.id,
blob: snapshot.blob, blob: snapshot.blob,
@@ -311,7 +319,9 @@ test('should be able to cleanup expired history', async t => {
// insert available data // insert available data
await db.snapshotHistory.createMany({ await db.snapshotHistory.createMany({
data: new Array(10).fill(0).map((_, i) => ({ data: Array.from({ length: 10 })
.fill(0)
.map((_, i) => ({
workspaceId: snapshot.workspaceId, workspaceId: snapshot.workspaceId,
id: snapshot.id, id: snapshot.id,
blob: snapshot.blob, blob: snapshot.blob,

View File

@@ -8,7 +8,9 @@ export const WorkspaceDetailSkeleton = () => {
<> <>
<SettingHeader title={<Skeleton />} subtitle={<Skeleton />} /> <SettingHeader title={<Skeleton />} subtitle={<Skeleton />} />
{new Array(3).fill(0).map((_, index) => { {Array.from({ length: 3 })
.fill(0)
.map((_, index) => {
return ( return (
<SettingWrapper title={<Skeleton />} key={index}> <SettingWrapper title={<Skeleton />} key={index}>
<SettingRow <SettingRow

View File

@@ -26,7 +26,9 @@ export const WorkspaceListItemSkeleton = () => {
export const WorkspaceListSkeleton = () => { export const WorkspaceListSkeleton = () => {
return ( return (
<> <>
{new Array(5).fill(0).map((_, index) => { {Array.from({ length: 5 })
.fill(0)
.map((_, index) => {
return <WorkspaceListItemSkeleton key={index} />; return <WorkspaceListItemSkeleton key={index} />;
})} })}
</> </>

View File

@@ -3,7 +3,7 @@ export const TRACE_ID_BYTES = 16;
export const TRACE_VERSION = '00'; export const TRACE_VERSION = '00';
export const TRACE_FLAG = '01'; export const TRACE_FLAG = '01';
const BytesBuffer = new Array(32); const BytesBuffer = Array.from<number>({ length: 32 });
type TraceSpan = { type TraceSpan = {
name: string; name: string;

View File

@@ -265,7 +265,9 @@ test.describe('collaboration members', () => {
await addUserToWorkspace(workspaceId, userB.id, 1 /* READ */); await addUserToWorkspace(workspaceId, userB.id, 1 /* READ */);
}; };
await Promise.all( await Promise.all(
new Array(10).fill(1).map(() => createUserAndAddToWorkspace()) Array.from({ length: 10 })
.fill(1)
.map(() => createUserAndAddToWorkspace())
); );
await openSettingModal(page); await openSettingModal(page);