Skip to content

Commit

Permalink
fix: Resolve most eslint-disable and typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanoCookies authored and birme committed May 17, 2023
1 parent 086de19 commit 28ec5ae
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
10 changes: 3 additions & 7 deletions src/manifests/utils/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CorruptorConfig {
*
* ex: ...&keyWithEmptyFields=&...
*/
fields: { [key: string]: string | number | boolean } | null;
fields?: { [key: string]: string | number | boolean } | null;
}

export type IndexedCorruptorConfigMap = Map<TargetIndex, CorruptorConfigMap>;
Expand Down Expand Up @@ -106,8 +106,6 @@ export const corruptorConfigUtils = function (
return this;
},
getAllManifestConfigs(mseq = 0, isDash = false) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that: CorruptorConfigUtils = this;
const outputMap = new CorruptorIndexMap();
const configs = (
(this.registered || []) as SegmentCorruptorQueryConfig[]
Expand All @@ -116,7 +114,7 @@ export const corruptorConfigUtils = function (

for (const config of configs) {
// JSONify and remove whitespace
const parsableSearchParam = that.utils.getJSONParsableString(
const parsableSearchParam = this.utils.getJSONParsableString(
urlSearchParams.get(config.name)
);
let params = JSON.parse(parsableSearchParam);
Expand Down Expand Up @@ -151,11 +149,9 @@ export const corruptorConfigUtils = function (
const outputMap = new Map();
for (let i = 0; i < this.registered.length; i++) {
const SCC = this.registered[i];
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that: CorruptorConfigUtils = this;
if (urlSearchParams.get(SCC.name) !== null) {
// To make all object key names double quoted and remove whitespace
const parsedSearchParam = that.utils.getJSONParsableString(
const parsedSearchParam = this.utils.getJSONParsableString(
urlSearchParams.get(SCC.name)
);

Expand Down
19 changes: 9 additions & 10 deletions src/manifests/utils/corruptions/delay.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable */
import { unparsableError } from '../../../shared/utils';
import { ServiceError, TargetIndex } from '../../../shared/types';
import { CorruptorConfig, SegmentCorruptorQueryConfig } from '../configs';

interface DelayConfig extends CorruptorConfig {
ms: number;
ms?: number;
}

// TODO:Flytta till en i en constants fil, och gruppera med and
const delayExpectedQueryFormatMsg =
'Incorrect delay query format. Expected format: [{i?:number, sq?:number, br?:number, ms:number}, ...n] where i and sq are mutually exclusive.';

function getManifestConfigError(value: { [key: string]: any }): string {
function getManifestConfigError(value: { [key: string]: unknown }): string {
const o = value as DelayConfig;

if (o.ms && typeof o.ms !== 'number') {
return delayExpectedQueryFormatMsg;
}
Expand All @@ -32,19 +32,18 @@ function getManifestConfigError(value: { [key: string]: any }): string {
return "Incorrect delay query format. 'i' and 'sq' are mutually exclusive in a single query object.";
}

if (o.sq < 0) {
if (Number(o.sq) < 0) {
return 'Incorrect delay query format. Field sq must be 0 or positive.';
}

if (o.i < 0) {
if (Number(o.i) < 0) {
return 'Incorrect delay query format. Field i must be 0 or positive.';
}

return '';
}
function isValidSegmentConfig(value: { [key: string]: any }): boolean {
const o = value as DelayConfig;
if (o.ms && typeof o.ms !== 'number') {
function isValidSegmentConfig(value: { [key: string]: unknown }): boolean {
if (value.ms && typeof value.ms !== 'number') {
return false;
}
return true;
Expand Down Expand Up @@ -121,7 +120,7 @@ const delayConfig: SegmentCorruptorQueryConfig = {

const corruptorConfigs: CorruptorConfig[] = [];

for (var value of configIndexMap.values()) {
for (const value of configIndexMap.values()) {
corruptorConfigs.push(value);
}

Expand All @@ -133,7 +132,7 @@ const delayConfig: SegmentCorruptorQueryConfig = {
getSegmentConfigs(
delayConfigString: string
): [ServiceError | null, CorruptorConfig | null] {
const config: any = JSON.parse(delayConfigString);
const config = JSON.parse(delayConfigString);
if (!isValidSegmentConfig(config)) {
return [
unparsableError(
Expand Down
5 changes: 2 additions & 3 deletions src/manifests/utils/corruptions/statusCode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
import { unparsableError } from '../../../shared/utils';
import { ServiceError, TargetIndex } from '../../../shared/types';
import { CorruptorConfig, SegmentCorruptorQueryConfig } from '../configs';
Expand Down Expand Up @@ -35,11 +34,11 @@ function getManifestConfigError(value: { [key: string]: any }): string {
return "Incorrect statusCode query format. 'i' and 'sq' are mutually exclusive in a single query object.";
}

if (o.sq < 0) {
if (Number(o.sq) < 0) {
return 'Incorrect statusCode query format. Field sq must be 0 or positive.';
}

if (o.i < 0) {
if (Number(o.i) < 0) {
return 'Incorrect statusCode query format. Field i must be 0 or positive.';
}

Expand Down
7 changes: 3 additions & 4 deletions src/manifests/utils/corruptions/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ interface TimeoutConfig {
ch?: number;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getManifestConfigError(value: { [key: string]: any }): string {
function getManifestConfigError(value: { [key: string]: unknown }): string {
const o = value as TimeoutConfig;

if (o.i === undefined && o.sq === undefined) {
Expand All @@ -31,11 +30,11 @@ function getManifestConfigError(value: { [key: string]: any }): string {
return "Incorrect timeout query format. 'i' and 'sq' are mutually exclusive in a single query object.";
}

if (o.sq < 0) {
if (Number(o.sq) < 0) {
return 'Incorrect timeout query format. Field sq must be 0 or positive.';
}

if (o.i < 0) {
if (Number(o.i) < 0) {
return 'Incorrect timeout query format. Field i must be 0 or positive.';
}

Expand Down
8 changes: 2 additions & 6 deletions src/manifests/utils/hlsManifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export interface HLSManifestTools {
createProxyMediaManifest: (
originalM3U: M3U,
sourceBaseURL: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mutations: any
mutations: IndexedCorruptorConfigMap
) => Manifest; // look def again
createProxyMasterManifest: (
originalM3U: M3U,
Expand Down Expand Up @@ -122,13 +121,10 @@ export default function (): HLSManifestTools {
sourceBaseURL: string,
configsMap: IndexedCorruptorConfigMap
) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that: HLSManifestTools = this;

const m3u: M3U = clone(originalM3U);

// configs for each index
const corruptions = that.utils.mergeMap(
const corruptions = this.utils.mergeMap(
m3u.items.PlaylistItem.length,
configsMap
);
Expand Down
3 changes: 1 addition & 2 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { addSSMUrlParametersToUrl } from './aws.utils';
import dotenv from 'dotenv';
dotenv.config();

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../package.json');
const version = process.env.npm_package_version;

export const handleOptionsRequest = async (): Promise<ALBResult> => {
return {
Expand Down

0 comments on commit 28ec5ae

Please sign in to comment.