diff --git a/pkg/earwurm/src/Earwurm.ts b/pkg/earwurm/src/Earwurm.ts index 757990b..ef22d15 100644 --- a/pkg/earwurm/src/Earwurm.ts +++ b/pkg/earwurm/src/Earwurm.ts @@ -1,16 +1,16 @@ -import {arrayShallowEquals, clamp, getErrorMessage} from 'beeftools'; +import {arrayEquals, clamp, getErrorMessage} from 'beeftools'; import {EmittenCommon} from 'emitten'; import {linearRamp, unlockAudioContext} from '@earwurm/helpers'; import {Stack} from './Stack'; import {tokens} from './tokens'; import type { - ManagerState, - ManagerEventMap, - ManagerConfig, LibraryEntry, - StackId, + ManagerConfig, + ManagerEventMap, + ManagerState, StackEventMap, + StackId, } from './types'; export class Earwurm extends EmittenCommon { @@ -197,9 +197,9 @@ export class Earwurm extends EmittenCommon { suspend() { if ( - this._state === 'closed' || - this._state === 'suspended' || - this._state === 'suspending' + this._state === 'closed' + || this._state === 'suspended' + || this._state === 'suspending' ) { return this; } @@ -259,7 +259,7 @@ export class Earwurm extends EmittenCommon { #setLibrary(library: Stack[]) { const oldKeys = [...this._keys]; const newKeys = library.map(({id}) => id); - const identicalKeys = arrayShallowEquals(oldKeys, newKeys); + const identicalKeys = arrayEquals(oldKeys, newKeys); this.#library = library; this._keys = newKeys; @@ -275,7 +275,9 @@ export class Earwurm extends EmittenCommon { if (value === 'running') { this._unlocked = true; - } else if (value === 'closed') { + } + // TODO: This should not be broken onto a separate line. + else if (value === 'closed') { this._unlocked = false; } diff --git a/pkg/earwurm/src/Sound.ts b/pkg/earwurm/src/Sound.ts index 0c7823a..35efeaf 100644 --- a/pkg/earwurm/src/Sound.ts +++ b/pkg/earwurm/src/Sound.ts @@ -1,14 +1,14 @@ -import {clamp, calcProgress} from 'beeftools'; +import {calcProgress, clamp} from 'beeftools'; import {EmittenCommon} from 'emitten'; import {linearRamp} from '@earwurm/helpers'; import {tokens} from './tokens'; import type { - SoundId, - SoundState, + SoundConfig, SoundEventMap, + SoundId, SoundProgressEvent, - SoundConfig, + SoundState, } from './types'; export class Sound extends EmittenCommon { @@ -58,7 +58,7 @@ export class Sound extends EmittenCommon { } private get hasProgressSub() { - return this.activeEvents.some((event) => event === 'progress'); + return this.activeEvents.includes('progress'); } private get transDuration() { @@ -177,8 +177,8 @@ export class Sound extends EmittenCommon { // Not yet sure how to resolve this. this.#incrementLoop(); - const timeSince = - Math.max(this.context.currentTime - this.#timestamp, 0) * this.speed; + const timeSince + = Math.max(this.context.currentTime - this.#timestamp, 0) * this.speed; this.#progress.elapsed = clamp( 0, @@ -258,7 +258,9 @@ export class Sound extends EmittenCommon { this.#intervalId = this.hasProgressSub ? requestAnimationFrame(this.#handleInterval) : 0; - } else { + } + // TODO: This should not be broken onto a separate line. + else { cancelAnimationFrame(this.#intervalId); this.#intervalId = 0; @@ -273,9 +275,9 @@ export class Sound extends EmittenCommon { if (!this.loop) return; if ( - this.#progress.elapsed === this.duration || - this.#progress.remaining === 0 || - this.#progress.percentage === 100 + this.#progress.elapsed === this.duration + || this.#progress.remaining === 0 + || this.#progress.percentage === 100 ) { this.#progress.elapsed = 0; this.#progress.remaining = this.duration; diff --git a/pkg/earwurm/src/Stack.ts b/pkg/earwurm/src/Stack.ts index 8aa6c60..f05af7d 100644 --- a/pkg/earwurm/src/Stack.ts +++ b/pkg/earwurm/src/Stack.ts @@ -1,17 +1,17 @@ -import {arrayShallowEquals, clamp, getErrorMessage} from 'beeftools'; +import {arrayEquals, clamp, getErrorMessage} from 'beeftools'; import {EmittenCommon} from 'emitten'; import {fetchAudioBuffer, linearRamp, scratchBuffer} from '@earwurm/helpers'; import {Sound} from './Sound'; import {tokens} from './tokens'; import type { - StackId, - StackState, + SoundEventMap, + SoundId, + StackConfig, StackError, StackEventMap, - StackConfig, - SoundId, - SoundEventMap, + StackId, + StackState, } from './types'; export class Stack extends EmittenCommon { @@ -212,7 +212,7 @@ export class Stack extends EmittenCommon { #setQueue(value: Sound[]) { const oldKeys = [...this._keys]; const newKeys = value.map(({id}) => id); - const identicalKeys = arrayShallowEquals(oldKeys, newKeys); + const identicalKeys = arrayEquals(oldKeys, newKeys); this.#queue = value; this._keys = newKeys; diff --git a/pkg/earwurm/src/tests/Abstract.test.ts b/pkg/earwurm/src/tests/Abstract.test.ts index c316017..daaafb2 100644 --- a/pkg/earwurm/src/tests/Abstract.test.ts +++ b/pkg/earwurm/src/tests/Abstract.test.ts @@ -1,4 +1,4 @@ -import {afterEach, describe, it, expect, vi} from 'vitest'; +import {afterEach, describe, expect, it, vi} from 'vitest'; import {Sound} from '../Sound'; import {tokens} from '../tokens'; diff --git a/pkg/earwurm/src/tests/Earwurm.test.ts b/pkg/earwurm/src/tests/Earwurm.test.ts index a9ce80b..bb67ca2 100644 --- a/pkg/earwurm/src/tests/Earwurm.test.ts +++ b/pkg/earwurm/src/tests/Earwurm.test.ts @@ -1,4 +1,4 @@ -import {afterEach, describe, it, expect, vi} from 'vitest'; +import {afterEach, describe, expect, it, vi} from 'vitest'; import {mockData} from '@earwurm/mocks'; import {Earwurm} from '../Earwurm'; @@ -6,9 +6,9 @@ import {Stack} from '../Stack'; import type {Sound} from '../Sound'; import type { - ManagerEventMap, - ManagerConfig, LibraryEntry, + ManagerConfig, + ManagerEventMap, StackId, } from '../types'; diff --git a/pkg/earwurm/src/tests/Sound.test.ts b/pkg/earwurm/src/tests/Sound.test.ts index 98ec4f3..815d191 100644 --- a/pkg/earwurm/src/tests/Sound.test.ts +++ b/pkg/earwurm/src/tests/Sound.test.ts @@ -1,8 +1,8 @@ -import {afterEach, describe, it, expect, vi} from 'vitest'; +import {afterEach, describe, expect, it, vi} from 'vitest'; import {Sound} from '../Sound'; import {tokens} from '../tokens'; -import type {SoundState, SoundEventMap} from '../types'; +import type {SoundEventMap, SoundState} from '../types'; type SoundConstructor = ConstructorParameters; @@ -459,6 +459,7 @@ describe('Sound component', () => { expect(spyEnded).toBeCalledWith({ id: testSound.id, + // eslint-disable-next-line ts/no-unsafe-assignment source: expect.any(AudioBufferSourceNode), neverStarted: false, }); @@ -477,6 +478,7 @@ describe('Sound component', () => { expect(spyEnded).toBeCalledWith({ id: testSound.id, + // eslint-disable-next-line ts/no-unsafe-assignment source: expect.any(AudioBufferSourceNode), neverStarted: true, }); diff --git a/pkg/earwurm/src/tests/Stack.test.ts b/pkg/earwurm/src/tests/Stack.test.ts index 8ef1e34..767a072 100644 --- a/pkg/earwurm/src/tests/Stack.test.ts +++ b/pkg/earwurm/src/tests/Stack.test.ts @@ -1,11 +1,11 @@ -import {afterEach, describe, it, expect, vi} from 'vitest'; +import {afterEach, describe, expect, it, vi} from 'vitest'; import {arrayOfLength} from 'beeftools'; import {mockData} from '@earwurm/mocks'; import {Stack} from '../Stack'; import {Sound} from '../Sound'; import {tokens} from '../tokens'; -import type {StackEventMap, SoundEventMap} from '../types'; +import type {SoundEventMap, StackEventMap} from '../types'; type StackConstructor = ConstructorParameters; @@ -504,6 +504,7 @@ describe('Stack component', () => { // Fill the `queue` up with the exact max number of Sounds. const pendingSounds = arrayOfLength(tokens.maxStackSize).map( + // eslint-disable-next-line ts/return-await async (_index) => await testStack.prepare(), ); @@ -533,6 +534,7 @@ describe('Stack component', () => { // Add more sounds before any current Sound has finished playing. const additionalSounds = arrayOfLength(additionalSoundsCount).map( + // eslint-disable-next-line ts/return-await async (_index) => await testStack.prepare(), ); diff --git a/pkg/earwurm/src/types.ts b/pkg/earwurm/src/types.ts index 3ab471a..3b0b057 100644 --- a/pkg/earwurm/src/types.ts +++ b/pkg/earwurm/src/types.ts @@ -2,7 +2,7 @@ import type {CombinedErrorMessage} from '@earwurm/types'; export type ManagerState = AudioContextState | 'suspending' | 'interrupted'; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +// eslint-disable-next-line ts/consistent-type-definitions export type ManagerEventMap = { state: (current: ManagerState) => void; play: (active: boolean) => void; @@ -34,7 +34,7 @@ export interface StackError { message: CombinedErrorMessage; } -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +// eslint-disable-next-line ts/consistent-type-definitions export type StackEventMap = { state: (current: StackState) => void; queue: (newKeys: SoundId[], oldKeys: SoundId[]) => void; @@ -75,7 +75,7 @@ export interface SoundProgressEvent { iterations: number; } -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions +// eslint-disable-next-line ts/consistent-type-definitions export type SoundEventMap = { state: (current: SoundState) => void; ended: (event: SoundEndedEvent) => void;