diff --git a/.oxlintrc.json b/.oxlintrc.json index 47687cf..63b5e87 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -11,7 +11,7 @@ "eslint/no-unused-private-class-members": "error", "react/react-in-jsx-scope": "off", "typescript/no-explicit-any": "error", - "unicorn/no-new-array": "off" + "unicorn/no-new-array": "error" }, "overrides": [ { diff --git a/packages/hdrify/src/exr/b44Codec.test.ts b/packages/hdrify/src/exr/b44Codec.test.ts index fb11d22..5f6074f 100644 --- a/packages/hdrify/src/exr/b44Codec.test.ts +++ b/packages/hdrify/src/exr/b44Codec.test.ts @@ -34,7 +34,7 @@ describe('b44Codec', () => { }); it('packs a constant block into 3 bytes when flatFields (B44A) is set', () => { - const values = new Array(16).fill(0.5); + const values = Array.from({ length: 16 }).fill(0.5); const { wcount, decoded } = packAndUnpack(values, true); expect(wcount).toBe(3); for (const v of decoded) { @@ -43,7 +43,7 @@ describe('b44Codec', () => { }); it('does not use the 3-byte flat encoding for a constant block when flatFields (B44) is false', () => { - const values = new Array(16).fill(0.5); + const values = Array.from({ length: 16 }).fill(0.5); const { wcount } = packAndUnpack(values, false); expect(wcount).toBe(14); }); diff --git a/packages/hdrify/src/exr/pizHuffman.ts b/packages/hdrify/src/exr/pizHuffman.ts index 88d9aee..5a3e493 100644 --- a/packages/hdrify/src/exr/pizHuffman.ts +++ b/packages/hdrify/src/exr/pizHuffman.ts @@ -57,7 +57,7 @@ function getBits(nBits: number, c: number, lc: number, uInt8Array: Uint8Array, i getBitsReturn.lc = currentLc; } -const hufTableBuffer = new Array(59); +const hufTableBuffer = Array.from({ length: 59 }); function hufCanonicalCodeTable(hcode: number[]): void { for (let i = 0; i <= 58; ++i) hufTableBuffer[i] = 0; @@ -185,7 +185,7 @@ function hufBuildDecTable(hcode: number[], im: number, iM: number, hdecod: HufDe pl.lit++; if (pl.p) { const p = pl.p; - pl.p = new Array(pl.lit); + pl.p = Array.from({ length: pl.lit }); for (let i = 0; i < pl.lit - 1; ++i) { const pValue = p[i]; if (pValue !== undefined) { @@ -193,7 +193,7 @@ function hufBuildDecTable(hcode: number[], im: number, iM: number, hdecod: HufDe } } } else { - pl.p = new Array(1); + pl.p = Array.from({ length: 1 }); } pl.p[pl.lit - 1] = currentIm; } else if (l) { @@ -379,9 +379,9 @@ function countFrequencies(freq: number[], data: Uint16Array, n: number): void { } function hufBuildEncTable(frq: number[], im: { value: number }, iM: { value: number }): void { - const hlink = new Array(HUF_ENCSIZE); + const hlink = Array.from({ length: HUF_ENCSIZE }); const fHeap: number[] = []; - const scode = new Array(HUF_ENCSIZE).fill(0); + const scode = Array.from({ length: HUF_ENCSIZE }).fill(0); im.value = 0; while (!(frq[im.value] ?? 0)) im.value++; @@ -568,7 +568,7 @@ export function hufCompress(raw: Uint16Array): Uint8Array { const n = raw.length; if (n === 0) return new Uint8Array(0); - const freq = new Array(HUF_ENCSIZE); + const freq = Array.from({ length: HUF_ENCSIZE }); countFrequencies(freq, raw, n); const im = { value: 0 }; @@ -624,8 +624,8 @@ export function hufUncompress( ); } - const freq = new Array(HUF_ENCSIZE); - const hdec: HufDec[] = new Array(HUF_DECSIZE); + const freq = Array.from({ length: HUF_ENCSIZE }); + const hdec: HufDec[] = Array.from({ length: HUF_DECSIZE }); hufClearDecTable(hdec); const ni = nCompressed - (inOffset.value - initialInOffset);