From dececa46c378e7cefd34170ddfd76260ab90922a Mon Sep 17 00:00:00 2001 From: hensm Date: Wed, 27 Apr 2022 22:28:38 +0100 Subject: [PATCH] Narrow linting rules and fix for eslintrc for js files --- .eslintrc.json | 60 +++-- app/bin/build.js | 5 +- app/package-lock.json | 1 - app/src/bridge/components/cast/Session.ts | 2 - app/src/bridge/components/cast/index.ts | 2 +- app/src/bridge/components/cast/types.ts | 12 +- app/src/bridge/index.ts | 2 +- app/src/bridge/lib/subtitles.ts | 1 - app/src/bridge/messaging.ts | 10 +- app/src/transforms.ts | 15 +- ext/bin/build.js | 2 +- ext/src/background/receiverDevices.ts | 2 +- ext/src/cast/eventMessaging.ts | 1 - ext/src/cast/export.ts | 2 +- ext/src/cast/index.ts | 16 +- ext/src/cast/sdk/classes.ts | 2 +- ext/src/cast/sdk/media/Media.ts | 2 +- ext/src/cast/sdk/media/classes.ts | 38 +-- ext/src/cast/senders/media/index.ts | 16 +- ext/src/cast/senders/mirroring.ts | 8 +- ext/src/global.d.ts | 4 +- ext/src/lib/logger.ts | 8 +- ext/src/lib/nativeMessaging.ts | 5 +- ext/src/lib/utils.ts | 4 +- ext/src/messaging.ts | 30 ++- ext/src/ui/options/Bridge.tsx | 292 ++++++++++++---------- ext/src/ui/popup/index.tsx | 2 - 27 files changed, 298 insertions(+), 246 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c022ca3..53d96b6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,30 +1,48 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": [ "@typescript-eslint" ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier" - ], + "plugins": ["@typescript-eslint"], + "extends": ["eslint:recommended", "prettier"], "rules": { "no-useless-escape": "off", "no-prototype-builtins": "off", "no-async-promise-executor": "off", - "semi": [ "error", "always"], - "no-multiple-empty-lines": [ "error", { "max": 2 }], - "no-console": [ "error", { - "allow": [ "info", "warn", "error" ] - }], + "semi": ["error", "always"], + "no-multiple-empty-lines": ["error", { "max": 2 }], + "no-console": [ + "error", + { + "allow": ["info", "warn", "error"] + } + ] + }, - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/ban-types": "off", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-this-alias": [ "error", { - "allowedNames": [ "this_" ] - }] - } + "overrides": [ + { + "files": ["*/bin/**/*.js"], + "env": { + "node": true + } + }, + { + "files": ["**/*.ts", "**/*.tsx"], + "extends": "plugin:@typescript-eslint/recommended", + "rules": { + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { "argsIgnorePattern": "^_" } + ], + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-this-alias": [ + "error", + { + "allowedNames": ["this_"] + } + ] + } + } + ] } diff --git a/app/bin/build.js b/app/bin/build.js index 0a2a76c..2ece2c1 100644 --- a/app/bin/build.js +++ b/app/bin/build.js @@ -489,8 +489,7 @@ function packageLinuxRpm( function packageWin32( arch, platformExecutableName, - platformExecutablePath, - platformManifestPath + platformExecutablePath ) { const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.exe`; @@ -525,6 +524,6 @@ function packageWin32( } build().catch(e => { - console.log("Build failed", e); + console.error("Build failed", e); process.exit(1); }); diff --git a/app/package-lock.json b/app/package-lock.json index d61f419..0c0eb83 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -13,7 +13,6 @@ "mime-types": "^2.1.35", "minimist": "^1.2.6", "node-fetch": "^3.2.3", - "rage-edit": "*", "tweetnacl": "^1.0.3", "ws": "^8.5.0" }, diff --git a/app/src/bridge/components/cast/Session.ts b/app/src/bridge/components/cast/Session.ts index b18defa..3ca62f3 100644 --- a/app/src/bridge/components/cast/Session.ts +++ b/app/src/bridge/components/cast/Session.ts @@ -72,8 +72,6 @@ export default class Session extends CastClient { this.establishAppConnection(this.transportId); this.onSessionCreated?.(this.sessionId); - const { friendlyName } = this.receiverDevice; - messaging.sendMessage({ subject: "cast:sessionCreated", data: { diff --git a/app/src/bridge/components/cast/index.ts b/app/src/bridge/components/cast/index.ts index bbad39c..64adaaf 100644 --- a/app/src/bridge/components/cast/index.ts +++ b/app/src/bridge/components/cast/index.ts @@ -3,7 +3,7 @@ import messaging, { Message } from "../../messaging"; import Session from "./Session"; -import CastClient, { NS_CONNECTION, NS_RECEIVER } from "./client"; +import CastClient from "./client"; const sessions = new Map(); diff --git a/app/src/bridge/components/cast/types.ts b/app/src/bridge/components/cast/types.ts index 1efb363..d43718b 100644 --- a/app/src/bridge/components/cast/types.ts +++ b/app/src/bridge/components/cast/types.ts @@ -125,7 +125,7 @@ interface BreakClip { contentId?: string; contentType?: string; contentUrl?: string; - customData?: {}; + customData?: unknown; duration?: number; id: string; hlsSegmentFormat?: HlsSegmentFormat; @@ -137,7 +137,7 @@ interface BreakClip { interface TextTrackStyle { backgroundColor: Nullable; - customData: any; + customData: unknown; edgeColor: Nullable; edgeType: Nullable; fontFamily: Nullable; @@ -151,7 +151,7 @@ interface TextTrackStyle { } interface Track { - customData: any; + customData: unknown; language: Nullable; name: Nullable; subtype: Nullable; @@ -162,7 +162,7 @@ interface Track { } interface UserActionState { - customData: any; + customData: unknown; userAction: UserAction; } @@ -185,7 +185,7 @@ interface MediaInformation { contentId: string; contentType: string; contentUrl?: string; - customData: any; + customData: unknown; duration: Nullable; entity?: string; hlsSegmentFormat?: HlsSegmentFormat; @@ -269,7 +269,7 @@ interface PhotoMediaMetadata { interface QueueItem { activeTrackIds: Nullable; autoplay: boolean; - customData: any; + customData: unknown; itemId: Nullable; media: MediaInformation; playbackDuration: Nullable; diff --git a/app/src/bridge/index.ts b/app/src/bridge/index.ts index 15bf13a..8c6b693 100755 --- a/app/src/bridge/index.ts +++ b/app/src/bridge/index.ts @@ -6,7 +6,7 @@ import { handleCastMessage } from "./components/cast"; import { startDiscovery, stopDiscovery } from "./components/discovery"; import { startMediaServer, stopMediaServer } from "./components/mediaServer"; -import { __applicationName, __applicationVersion } from "../../package.json"; +import { __applicationVersion } from "../../package.json"; process.on("SIGTERM", () => { stopDiscovery(); diff --git a/app/src/bridge/lib/subtitles.ts b/app/src/bridge/lib/subtitles.ts index 3f5aac4..b10db56 100644 --- a/app/src/bridge/lib/subtitles.ts +++ b/app/src/bridge/lib/subtitles.ts @@ -37,7 +37,6 @@ export async function convertSrtToVtt(srtFilePath: string) { * millisecond separator. */ for (const groups of fileContents.matchAll(REGEX_CAPTION)) { - const captionSource = groups[0]; const captionIndex = groups[1]; const captionTime = groups[2]; const captionText = groups[3]; diff --git a/app/src/bridge/messaging.ts b/app/src/bridge/messaging.ts index 610a706..d43444e 100644 --- a/app/src/bridge/messaging.ts +++ b/app/src/bridge/messaging.ts @@ -163,12 +163,12 @@ type MessageDefinitions = { /** * Sent to bridge to stop HTTP media server. */ - "bridge:stopMediaServer": {}; + "bridge:stopMediaServer": undefined; /** * Sent to media sender from bridge when the media server has * stopped. */ - "mediaCast:mediaServerStopped": {}; + "mediaCast:mediaServerStopped": undefined; /** * Sent to media sender from bridge when the media server has * encountered an error. @@ -190,8 +190,8 @@ type Messages = { * all-optional keys. */ type NarrowedMessage> = - L extends any - ? {} extends L["data"] + L extends unknown + ? undefined extends L["data"] ? Omit & Partial : L : never; @@ -231,7 +231,7 @@ class Messenger extends TypedEmitter { this.encodeTransform.write(message); } - send(data: any) { + send(data: unknown) { this.encodeTransform.write(data); } } diff --git a/app/src/transforms.ts b/app/src/transforms.ts index 6e3e1c8..c73f9f0 100755 --- a/app/src/transforms.ts +++ b/app/src/transforms.ts @@ -1,9 +1,9 @@ "use strict"; -import { Transform } from "stream"; +import { Transform, TransformCallback } from "stream"; import { Message } from "./bridge/messaging"; -type ResponseHandlerFunction = (message: Message) => Promise; +type ResponseHandlerFunction = (message: Message) => Promise; /** * Takes a handler function that implements the transform @@ -20,8 +20,7 @@ export class ResponseTransform extends Transform { public _transform( chunk: Message, _encoding: string, - // tslint:disable-next-line:ban-types - callback: Function + callback: TransformCallback ) { Promise.resolve(this._handler(chunk)).then(res => { if (res) { @@ -49,10 +48,10 @@ export class DecodeTransform extends Transform { } public _transform( - chunk: any, + chunk: Uint8Array, _encoding: string, // tslint:disable-next-line:ban-types - callback: Function + callback: TransformCallback ) { // Append next chunk to buffer this._messageBuffer = Buffer.concat([this._messageBuffer, chunk]); @@ -108,10 +107,10 @@ export class EncodeTransform extends Transform { } public _transform( - chunk: any, + chunk: Uint8Array, _encoding: string, // tslint:disable-next-line:ban-types - callback: Function + callback: TransformCallback ) { const messageLength = Buffer.alloc(4); const message = Buffer.from(JSON.stringify(chunk)); diff --git a/ext/bin/build.js b/ext/bin/build.js index 4d951cd..f32d711 100644 --- a/ext/bin/build.js +++ b/ext/bin/build.js @@ -53,7 +53,7 @@ const preactCompatPlugin = { "../node_modules/preact/compat/dist/compat.module.js" ); - build.onResolve({ filter: /^(react|react-dom)$/ }, args => ({ + build.onResolve({ filter: /^(react|react-dom)$/ }, () => ({ path: preactPath })); } diff --git a/ext/src/background/receiverDevices.ts b/ext/src/background/receiverDevices.ts index 5c19e1b..cbb1604 100644 --- a/ext/src/background/receiverDevices.ts +++ b/ext/src/background/receiverDevices.ts @@ -5,7 +5,7 @@ import logger from "../lib/logger"; import { TypedEventTarget } from "../lib/TypedEventTarget"; import { Message, Port } from "../messaging"; -import { ReceiverDevice, ReceiverDeviceCapabilities } from "../types"; +import { ReceiverDevice } from "../types"; import { ReceiverStatus } from "../cast/sdk/types"; interface EventMap { diff --git a/ext/src/cast/eventMessaging.ts b/ext/src/cast/eventMessaging.ts index b6f937a..7b40af7 100644 --- a/ext/src/cast/eventMessaging.ts +++ b/ext/src/cast/eventMessaging.ts @@ -1,7 +1,6 @@ "use strict"; import logger from "../lib/logger"; -import { TypedEventTarget } from "../lib/TypedEventTarget"; import { Message } from "../messaging"; type EventMessengerListener = (message: Message) => void; diff --git a/ext/src/cast/export.ts b/ext/src/cast/export.ts index 8f259b2..171f1ea 100644 --- a/ext/src/cast/export.ts +++ b/ext/src/cast/export.ts @@ -1,6 +1,6 @@ "use strict"; -import messaging, { Message } from "../messaging"; +import { Message } from "../messaging"; import { BridgeInfo } from "../lib/bridge"; import { TypedMessagePort } from "../lib/TypedMessagePort"; diff --git a/ext/src/cast/index.ts b/ext/src/cast/index.ts index 486911d..1de6adc 100644 --- a/ext/src/cast/index.ts +++ b/ext/src/cast/index.ts @@ -17,8 +17,7 @@ if (!_window.chrome) { // Create page-accessible API object _window.chrome.cast = new CastSDK(); -let bridgeInfo: any; -let frameworkScriptPromise: Promise; +let frameworkScriptPromise: Promise | undefined; /** * If loaded within a page via a