Skip to content

Commit ee264c7

Browse files
committed
Apply eslint
1 parent 99c6aa3 commit ee264c7

File tree

12 files changed

+51
-82
lines changed

12 files changed

+51
-82
lines changed

.eslintrc.js

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,14 @@ module.exports = {
55
},
66
parser: '@typescript-eslint/parser',
77
parserOptions: {
8-
sourceType: 'module',
9-
parser: '@typescript-eslint/parser',
10-
// project: ['./tsconfig.json'],
8+
tsconfigRootDir: __dirname,
9+
// project: ['./src/tsconfig.json'],
1110
},
1211
plugins: ['@typescript-eslint'],
1312
rules: {
1413
'@typescript-eslint/adjacent-overload-signatures': 'error',
1514
'@typescript-eslint/array-type': 'error',
1615
'@typescript-eslint/ban-types': 'error',
17-
'@typescript-eslint/naming-convention': [
18-
'error',
19-
{
20-
selector: 'default',
21-
format: ['camelCase'],
22-
},
23-
{
24-
selector: 'class',
25-
format: ['camelCase'],
26-
},
27-
{
28-
selector: 'typeAlias',
29-
format: ['PascalCase'],
30-
},
31-
{
32-
selector: 'interface',
33-
format: ['PascalCase'],
34-
},
35-
{
36-
selector: 'typeParameter',
37-
format: ['PascalCase'],
38-
},
39-
{
40-
selector: 'property',
41-
format: null,
42-
},
43-
{
44-
selector: 'variable',
45-
format: ['camelCase', 'UPPER_CASE'],
46-
leadingUnderscore: 'allow',
47-
trailingUnderscore: 'allow',
48-
},
49-
],
5016
'@typescript-eslint/consistent-type-assertions': 'error',
5117
'@typescript-eslint/consistent-type-definitions': 'off',
5218
'@typescript-eslint/explicit-member-accessibility': [
@@ -70,11 +36,12 @@ module.exports = {
7036
},
7137
},
7238
],
39+
// '@typescript-eslint/no-floating-promises': ['error'],
7340
'@typescript-eslint/no-empty-interface': 'error',
7441
'@typescript-eslint/no-explicit-any': 'off',
7542
'@typescript-eslint/no-misused-new': 'error',
7643
'@typescript-eslint/no-namespace': 'error',
77-
'@typescript-eslint/no-non-null-assertion': 'error',
44+
'@typescript-eslint/no-non-null-assertion': 'warn',
7845
'@typescript-eslint/no-parameter-properties': 'off',
7946
'@typescript-eslint/no-use-before-declare': 'off',
8047
// [TODO] this does not check unused expressions completely...
@@ -139,20 +106,16 @@ module.exports = {
139106
'no-cond-assign': 'error',
140107
'no-console': 'off',
141108
'no-debugger': 'error',
142-
'no-empty': 'error',
109+
'no-empty': 'off',
143110
'no-eval': 'error',
144111
'no-extra-semi': 'off',
145112
'no-fallthrough': 'off',
146113
'no-invalid-this': 'off',
147114
'no-irregular-whitespace': 'off',
148115
'no-multiple-empty-lines': 'off',
149116
'no-new-wrappers': 'error',
150-
'no-shadow': [
151-
'error',
152-
{
153-
hoist: 'all',
154-
},
155-
],
117+
'no-shadow': 'off',
118+
'@typescript-eslint/no-shadow': ['error'],
156119
'no-throw-literal': 'error',
157120
'no-trailing-spaces': 'off',
158121
'no-undef-init': 'error',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"build": "node build.js debug",
77
"watch": "node build.js debug watch",
8+
"lint": "eslint ./src/**/*.ts",
89
"publish": "node build.js production"
910
},
1011
"keywords": [],

src/core/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const GLOBAL_LOGLEVEL = {
3535
loglevel: LogLevel.WARN,
3636
};
3737

38-
function setLevel(level: LogLevel) {
38+
function setLevel(level: LogLevel): void {
3939
if (typeof self !== 'undefined') {
4040
// @ts-ignore
4141
self.__wv_global_loglevel = level;
@@ -52,7 +52,7 @@ function getLevel(): LogLevel {
5252
}
5353
}
5454

55-
function log(level: LogLevel, msg: string, header?: string) {
55+
function log(level: LogLevel, msg: string, header?: string): void {
5656
if (level < getLevel()) {
5757
return;
5858
}

src/core/ringbuffer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ export class WVAudioRingBuffer {
3838
this.options.channels = init.options.channels ?? this.options.channels;
3939
this.options.bufLength = init.options.bufLength ?? this.options.bufLength;
4040

41-
if (this.bufSet.lockSab.byteLength != 4) {
41+
if (this.bufSet.lockSab.byteLength !== 4) {
4242
throw Error('WVAudioRingBuffer Error: ByteLength of WVAudioRingBufferBufferSet.lockSab != 4');
4343
}
4444
this.lock = new Int32Array(this.bufSet.lockSab);
4545

46-
if (this.bufSet.idxSabs.length != 2) {
46+
if (this.bufSet.idxSabs.length !== 2) {
4747
throw Error('WVAudioRingBuffer Error: Length of WVAudioRingBufferBufferSet.idxSabs != 2');
4848
}
4949
for (let i = 0; i < 2; i++) {
50-
if (this.bufSet.idxSabs[i].byteLength != 4) {
50+
if (this.bufSet.idxSabs[i].byteLength !== 4) {
5151
throw Error('WVAudioRingBuffer: ByteLength of WVAudioRingBufferBufferSet.idxSabs[] != 4');
5252
}
5353
}
5454
this.readIdx = new Uint32Array(this.bufSet.idxSabs[0]);
5555
this.writeIdx = new Uint32Array(this.bufSet.idxSabs[1]);
5656

57-
if (this.bufSet.bufSabs.length != this.options.channels) {
57+
if (this.bufSet.bufSabs.length !== this.options.channels) {
5858
throw Error(
5959
'WVAudioRingBuffer Error: Length of WVAudioRingBufferBufferSet.bufSabs != WVAudioRingBufferOptions.channels'
6060
);
6161
}
6262
for (let ch = 0; ch < this.options.channels; ch++) {
63-
if (this.bufSet.bufSabs[ch].byteLength != 4 * this.options.bufLength) {
63+
if (this.bufSet.bufSabs[ch].byteLength !== 4 * this.options.bufLength) {
6464
throw Error(
6565
'WVAudioRingBuffer: ByteLength of WVAudioRingBufferBufferSet.bufSabs[] != WVAudioRingBufferOptions.bufLength'
6666
);

src/core/state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export class WVPlayState {
8585
export class WVSharedFlag {
8686
#buf: Int32Array;
8787

88-
static readonly #TRUE = 1;
89-
static readonly #FALSE = 0;
88+
static readonly #TRUE: number = 1;
89+
static readonly #FALSE: number = 0;
9090

9191
static fromBuffer(buf: Int32Array): WVSharedFlag {
9292
const dummy = false;

src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ enum PlayBtnIcon {
88
FONTAWESOME_PAUSE = '&#xf04c;',
99
}
1010

11-
function showLoader(loaderElem: HTMLElement) {
11+
function showLoader(loaderElem: HTMLElement): void {
1212
loaderElem.style.display = '';
1313
}
1414

15-
function hideLoader(loaderElem: HTMLElement) {
15+
function hideLoader(loaderElem: HTMLElement): void {
1616
loaderElem.style.display = 'none';
1717
}
1818

19-
function showPlayBtn(playBtnWrapperElem: HTMLElement) {
19+
function showPlayBtn(playBtnWrapperElem: HTMLElement): void {
2020
playBtnWrapperElem.style.display = '';
2121
}
2222

23-
function hidePlayBtn(playBtnWrapperElem: HTMLElement) {
23+
function hidePlayBtn(playBtnWrapperElem: HTMLElement): void {
2424
playBtnWrapperElem.style.display = 'none';
2525
}
2626

27-
function autohidePlayBtn(enable: boolean, playBtnWrapperElem: HTMLElement) {
27+
function autohidePlayBtn(enable: boolean, playBtnWrapperElem: HTMLElement): void {
2828
playBtnWrapperElem.style.opacity = enable ? '0' : '1';
2929
}
3030

31-
function setPlayBtnIcon(icon: PlayBtnIcon, playBtnElem: HTMLElement) {
31+
function setPlayBtnIcon(icon: PlayBtnIcon, playBtnElem: HTMLElement): void {
3232
playBtnElem.innerHTML = icon;
3333
}
3434

3535
window.addEventListener('beforeunload', (e) => {
36-
function blockingSleep(waitMs: number) {
36+
function blockingSleep(waitMs: number): void {
3737
const start = new Date().getTime();
3838
while (new Date().getTime() - start < waitMs) {}
3939
}
@@ -92,14 +92,14 @@ window.addEventListener('load', async () => {
9292
switch (player.playState()) {
9393
case WVPlayStateKind.PAUSED: {
9494
if (player.canPlay()) {
95-
player.play();
95+
void player.play();
9696
autohidePlayBtn(true, playBtnWrapperElem);
9797
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PAUSE, playBtnElem);
9898
}
9999
break;
100100
}
101101
case WVPlayStateKind.PLAYING: {
102-
player.pause();
102+
void player.pause();
103103
autohidePlayBtn(false, playBtnWrapperElem);
104104
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PLAY, playBtnElem);
105105
break;

src/media/codec/decoderWebCodecs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async function createDecoder(
180180
stream: WVMediaStreamInfo,
181181
output: (frame: DecodedFrame) => void
182182
): Promise<VideoDecoder | AudioDecoder | null> {
183-
if (stream.type == 'video') {
183+
if (stream.type === 'video') {
184184
return await createVideoDecoder(stream, output);
185185
} else {
186186
return await createAudioDecoder(stream, output);
@@ -194,7 +194,7 @@ export class WebCodecsMediaDecoder implements WVMediaDecoder {
194194
#decoder: AudioDecoder | VideoDecoder | null = null;
195195
#decodedFrames: DecodedFrame[] = [];
196196

197-
#onFrame = (data: DecodedFrame): void => {
197+
#onFrame: (d: DecodedFrame) => void = (data: DecodedFrame): void => {
198198
data.close();
199199
};
200200

src/media/format/demuxerMP4Box.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,30 @@ function createAVCDescription(trackIdx: number, file: MP4Box.MP4File): Uint8Arra
4343
return undefined;
4444
}
4545

46-
let i,
47-
size = 7;
48-
for (i = 0; i < avccBox.SPS.length; i++) size += 2 + avccBox.SPS[i].length;
49-
for (i = 0; i < avccBox.PPS.length; i++) size += 2 + avccBox.PPS[i].length;
46+
let i;
47+
let size = 7;
48+
for (i = 0; i < avccBox.SPS.length; i++) {
49+
size += 2 + avccBox.SPS[i].length;
50+
}
51+
for (i = 0; i < avccBox.PPS.length; i++) {
52+
size += 2 + avccBox.PPS[i].length;
53+
}
5054

5155
let id = 0;
52-
let data = new Uint8Array(size);
56+
const data = new Uint8Array(size);
5357

54-
let writeUint8 = (value: any) => {
58+
const writeUint8 = (value: any): any => {
5559
data.set([value], id);
5660
id++;
5761
};
58-
let writeUint16 = (value: any) => {
59-
let arr = new Uint8Array(1);
62+
const writeUint16 = (value: any): any => {
63+
const arr = new Uint8Array(1);
6064
arr[0] = value;
61-
let buffer = new Uint8Array(arr.buffer);
65+
const buffer = new Uint8Array(arr.buffer);
6266
data.set([buffer[1], buffer[0]], id);
6367
id += 2;
6468
};
65-
let writeUint8Array = (value: any) => {
69+
const writeUint8Array = (value: any): any => {
6670
data.set(value, id);
6771
id += value.length;
6872
};
@@ -85,7 +89,7 @@ function createAVCDescription(trackIdx: number, file: MP4Box.MP4File): Uint8Arra
8589
writeUint8Array(avccBox.PPS[i].nalu);
8690
}
8791

88-
if (id != size) {
92+
if (id !== size) {
8993
logger.debug('Size mismatched', 'MP4BoxMediaDemuxer');
9094
return undefined;
9195
}
@@ -100,8 +104,8 @@ function createWVMediaStreamInfo(
100104
): WVMediaStreamInfo {
101105
const streamType = track.type;
102106
let streamTypeStr: WVMediaStreamType = 'other';
103-
let video: WVVideoStreamInfo | undefined = undefined;
104-
let audio: WVAudioStreamInfo | undefined = undefined;
107+
let video: WVVideoStreamInfo | undefined;
108+
let audio: WVAudioStreamInfo | undefined;
105109
if (streamType === 'video') {
106110
streamTypeStr = 'video';
107111
video = {
@@ -205,7 +209,7 @@ export class MP4BoxMediaDemuxer implements WVMediaDemuxer {
205209
});
206210
}
207211

208-
destroy() {
212+
destroy(): void {
209213
if (this.#info) {
210214
for (const track of this.#info.tracks) {
211215
// @ts-ignore

src/player/audio/decoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { WVMediaStreamInfo } from '../../media/media';
55
export class WVAudioDecoderWorkerFront {
66
#worker: Worker;
77

8-
constructor(options: {}) {
8+
constructor() {
99
this.#worker = new Worker(AUDIO_DECODER_WORKER_PATH, {
1010
type: 'module',
1111
name: AUDIO_DECODER_WORKER_NAME,

src/player/audio/decoderWorker/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ self.addEventListener('message', async (e) => {
9898
break;
9999
}
100100
if (data.frame) {
101-
if (data.frame.type() == 'audio') {
101+
if (data.frame.type() === 'audio') {
102102
await pushSamples(workerState, data.frame);
103103
data.frame.close();
104104
continue;

0 commit comments

Comments
 (0)