From f9021ba4043d8fc4a0819d8d71f6c5b6b6dc1735 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Thu, 5 Sep 2024 14:35:22 +0200 Subject: [PATCH] fix: lint --- eslint.config.js | 5 ++++- src/browser/localstorage.ts | 12 ++++-------- src/common/crypto.spec.ts | 2 +- src/common/platform.ts | 2 +- src/common/schema/rpc.spec.ts | 2 +- src/common/uuid.spec.ts | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index b7fcf7d..7fce60d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,6 +9,9 @@ export default antfu( }, {}, { - rules: eslintRulesDefaults(), + rules: { + ...eslintRulesDefaults(), + 'unicorn/consistent-function-scoping': 'off', + }, }, ) diff --git a/src/browser/localstorage.ts b/src/browser/localstorage.ts index 353c081..c3b6a40 100644 --- a/src/browser/localstorage.ts +++ b/src/browser/localstorage.ts @@ -49,17 +49,13 @@ export class LocalStorage implements ObjectStorage { } clear(): void { - Object.keys(localStorage) - .filter(key => key.startsWith(this.prefix)) - .forEach((key) => { - localStorage.removeItem(key) - }) + Object.keys(localStorage).filter(key => key.startsWith(this.prefix)).forEach((key) => { + localStorage.removeItem(key) + }) } allKeys(): string[] { const prefixLength = this.prefix.length - return Object.keys(localStorage) - .filter(key => key.startsWith(this.prefix)) - .map(key => key.substr(prefixLength)) + return Object.keys(localStorage).filter(key => key.startsWith(this.prefix)).map(key => key.substr(prefixLength)) } } diff --git a/src/common/crypto.spec.ts b/src/common/crypto.spec.ts index 96e8db7..cea6c73 100644 --- a/src/common/crypto.spec.ts +++ b/src/common/crypto.spec.ts @@ -10,7 +10,7 @@ const log = DefaultLogger('crypto.spec') describe('crypto', () => { it('should not have collisions', () => { expect(equalBinary(new Uint8Array(2), new Uint8Array([0, 0]))).toBe(true) - const list: Uint8Array[] = Array.apply(null, Array(100)).map(() => + const list: Uint8Array[] = Array.apply(null, Array.from({ length: 100 })).map(() => randomUint8Array(8), ) let id: Uint8Array | undefined diff --git a/src/common/platform.ts b/src/common/platform.ts index fd5cc13..dfc8dc2 100644 --- a/src/common/platform.ts +++ b/src/common/platform.ts @@ -31,7 +31,7 @@ export function getGlobal(): any { : typeof global !== 'undefined' ? global // eslint-disable-next-line no-new-func - : Function('return this;')() + : new Function('return this;')() } /** @deprecated */ diff --git a/src/common/schema/rpc.spec.ts b/src/common/schema/rpc.spec.ts index 5a7d136..7bc8c9d 100644 --- a/src/common/schema/rpc.spec.ts +++ b/src/common/schema/rpc.spec.ts @@ -1,5 +1,5 @@ import { func, object, string } from './schema' -import type { Infer, Type } from './schema' +import type { Infer } from './schema' // see https://github.com/colinhacks/zod?tab=readme-ov-file#functions diff --git a/src/common/uuid.spec.ts b/src/common/uuid.spec.ts index 8d21645..b717b7e 100644 --- a/src/common/uuid.spec.ts +++ b/src/common/uuid.spec.ts @@ -20,7 +20,7 @@ describe('uuid', () => { }) it('should not have collisions', () => { - const list = Array.apply(null, Array(100)).map(uuid) + const list = Array.apply(null, Array.from({ length: 100 })).map(uuid) while (list.length) { const id = list.pop() expect(id?.length).toBe(22) @@ -29,7 +29,7 @@ describe('uuid', () => { }) it('should not have collisions v4', () => { - const list = Array.apply(null, Array(100)).map(uuidv4) + const list = Array.apply(null, Array.from({ length: 100 })).map(uuidv4) while (list.length) { const id = list.pop() expect(id?.length).toBe(36)