diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0adc339c89354..85eab8600adc9 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -108,6 +108,7 @@ module.exports = { 'unicorn/prefer-blob-reading-methods': 'error', 'unicorn/no-typeof-undefined': 'error', 'unicorn/no-useless-promise-resolve-reject': 'error', + 'unicorn/no-new-array': 'error', }, }, ...allPackages.map(pkg => ({ diff --git a/packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts b/packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts index 45e854b12f35d..9b267e2b7b34c 100644 --- a/packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts +++ b/packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts @@ -9,9 +9,9 @@ export const templates = [ ]; function lcs(text1: string, text2: string) { - const dp: number[][] = new Array(text1.length + 1) + const dp: number[][] = Array.from({ length: text1.length + 1 }) .fill(null) - .map(() => new Array(text2.length + 1).fill(0)); + .map(() => Array.from({ length: text2.length + 1 }).fill(0)); for (let i = 1; i <= text1.length; i++) { for (let j = 1; j <= text2.length; j++) { diff --git a/packages/presets/src/__tests__/utils/common.ts b/packages/presets/src/__tests__/utils/common.ts index a73b071536f5d..2cea331018b66 100644 --- a/packages/presets/src/__tests__/utils/common.ts +++ b/packages/presets/src/__tests__/utils/common.ts @@ -118,12 +118,14 @@ export function drag( const xStep = (end.x - start.x) / step; const yStep = (end.y - start.y) / step; - new Array(step).fill(0).forEach((_, i) => { - pointermove(target, { - x: start.x + xStep * (i + 1), - y: start.y + yStep * (i + 1), + Array.from({ length: step }) + .fill(0) + .forEach((_, i) => { + pointermove(target, { + x: start.x + xStep * (i + 1), + y: start.y + yStep * (i + 1), + }); }); - }); } pointermove(target, end); diff --git a/tests/selection/block.spec.ts b/tests/selection/block.spec.ts index 9af8addc772f9..cdeb2090938d8 100644 --- a/tests/selection/block.spec.ts +++ b/tests/selection/block.spec.ts @@ -417,7 +417,7 @@ test('should keep selection state when scrolling backward', async ({ await pressEnter(page); await type(page, '321'); - const data = new Array(5).fill(''); + const data = Array.from({ length: 5 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); @@ -493,7 +493,7 @@ test('should keep selection state when scrolling forward', async ({ page }) => { await pressEnter(page); await type(page, '321'); - const data = new Array(5).fill(''); + const data = Array.from({ length: 5 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); @@ -571,7 +571,7 @@ test('should keep selection state when scrolling backward with the scroll wheel' await pressEnter(page); await type(page, '321'); - const data = new Array(5).fill(''); + const data = Array.from({ length: 5 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); @@ -687,7 +687,7 @@ test('should keep selection state when scrolling forward with the scroll wheel', await pressEnter(page); await type(page, '321'); - const data = new Array(5).fill(''); + const data = Array.from({ length: 5 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); diff --git a/tests/selection/native.spec.ts b/tests/selection/native.spec.ts index ff89bb2e56b8a..765a9da299211 100644 --- a/tests/selection/native.spec.ts +++ b/tests/selection/native.spec.ts @@ -1494,7 +1494,7 @@ test('should keep native range selection when scrolling backward with the scroll await pressEnter(page); await type(page, '321'); - const data = new Array(9).fill(''); + const data = Array.from({ length: 9 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); @@ -1566,7 +1566,7 @@ test('should keep native range selection when scrolling forward with the scroll await pressEnter(page); await type(page, '321'); - const data = new Array(9).fill(''); + const data = Array.from({ length: 9 }).fill(''); data.unshift('123', '456', '789'); data.push('987', '654', '321'); await assertRichTexts(page, data); diff --git a/tests/utils/actions/misc.ts b/tests/utils/actions/misc.ts index 273d2c7851e89..503124b2f4942 100644 --- a/tests/utils/actions/misc.ts +++ b/tests/utils/actions/misc.ts @@ -880,8 +880,8 @@ export async function pasteBlocks(page: Page, json: unknown) { export async function getClipboardHTML(page: Page) { const dataInClipboard = await page.evaluate(async () => { function format(node: HTMLElement, level: number) { - const indentBefore = new Array(level++ + 1).join(' '); - const indentAfter = new Array(level - 1).join(' '); + const indentBefore = ' '.repeat(level++ + 1); + const indentAfter = Array.from({ length: level - 1 }).join(' '); let textNode; for (let i = 0; i < node.children.length; i++) {