Skip to content

Commit

Permalink
style: add no-new-array rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Mar 6, 2024
1 parent faf108f commit 2b7d543
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Check failure on line 12 in packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts

View workflow job for this annotation

GitHub Actions / Unit test

Type 'unknown[][]' is not assignable to type 'number[][]'.

Check failure on line 12 in packages/blocks/src/root-block/edgeless/components/toolbar/template/builtin-templates.ts

View workflow job for this annotation

GitHub Actions / Unit test

Type 'unknown[][]' is not assignable to type 'number[][]'.
.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++) {
Expand Down
12 changes: 7 additions & 5 deletions packages/presets/src/__tests__/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/selection/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 423 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 423 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down Expand Up @@ -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);

Check failure on line 499 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 499 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down Expand Up @@ -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);

Check failure on line 577 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 577 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down Expand Up @@ -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);

Check failure on line 693 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 693 in tests/selection/block.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down
4 changes: 2 additions & 2 deletions tests/selection/native.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 1500 in tests/selection/native.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 1500 in tests/selection/native.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down Expand Up @@ -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);

Check failure on line 1572 in tests/selection/native.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.

Check failure on line 1572 in tests/selection/native.spec.ts

View workflow job for this annotation

GitHub Actions / Unit test

Argument of type 'unknown[]' is not assignable to parameter of type 'string[]'.
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/actions/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 2b7d543

Please sign in to comment.