chore: improve linting (#7244)

This commit is contained in:
Noel
2022-01-11 12:30:08 +01:00
committed by GitHub
parent ff3a8b8323
commit 16938da355
57 changed files with 527 additions and 440 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
import { addAudioPlayer, deleteAudioPlayer } from '../DataStore';
import { Awaited, noop } from '../util/util';
import { VoiceConnection, VoiceConnectionStatus } from '../VoiceConnection';
@@ -163,6 +164,19 @@ export type AudioPlayerEvents = {
) => Awaited<void>;
};
/**
* Stringifies an AudioPlayerState instance.
*
* @param state - The state to stringify
*/
function stringifyState(state: AudioPlayerState) {
return JSON.stringify({
...state,
resource: Reflect.has(state, 'resource'),
stepTimeout: Reflect.has(state, 'stepTimeout'),
});
}
/**
* Used to play audio resources (i.e. tracks, streams) to voice connections.
*
@@ -606,19 +620,6 @@ export class AudioPlayer extends TypedEmitter<AudioPlayerEvents> {
}
}
/**
* Stringifies an AudioPlayerState instance.
*
* @param state - The state to stringify
*/
function stringifyState(state: AudioPlayerState) {
return JSON.stringify({
...state,
resource: Reflect.has(state, 'resource'),
stepTimeout: Reflect.has(state, 'stepTimeout'),
});
}
/**
* Creates a new AudioPlayer to be used.
*/

View File

@@ -151,7 +151,7 @@ export class AudioResource<T = unknown> {
this.silenceRemaining--;
return SILENCE_FRAME;
}
const packet: Buffer | null = this.playStream.read();
const packet = this.playStream.read() as Buffer | null;
if (packet) {
this.playbackDuration += 20;
}

View File

@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/dot-notation */
import { AudioResource } from '../../audio/AudioResource';
import { createAudioPlayer, AudioPlayerStatus, AudioPlayer, SILENCE_FRAME } from '../AudioPlayer';
@@ -372,7 +374,7 @@ test('play() throws when playing a resource that has already ended', async () =>
expect(resource.playStream.readableEnded).toBe(true);
player.stop(true);
expect(player.state.status).toBe(AudioPlayerStatus.Idle);
expect(() => player.play(resource)).toThrow();
expect(() => player?.play(resource)).toThrow();
});
test('Propagates errors from streams', async () => {

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
import { opus, VolumeTransformer } from 'prism-media';
import { PassThrough, Readable } from 'node:stream';
import { SILENCE_FRAME } from '../AudioPlayer';