Switch to eslint and fix issues

This commit is contained in:
hensm
2021-04-26 05:36:55 +01:00
parent 2d0fa4c844
commit d478742c4b
100 changed files with 1537 additions and 608 deletions

40
.eslintrc.json Normal file
View File

@@ -0,0 +1,40 @@
{
"root": true
, "parser": "@typescript-eslint/parser"
, "plugins": ["@typescript-eslint"]
, "extends": [
"eslint:recommended"
, "plugin:@typescript-eslint/recommended"
]
, "rules": {
"max-len": [ "error", 80, {
"tabWidth": 4
, "ignorePattern": "//|.*(\"|`);?$"
, "ignoreStrings": true
, "ignoreTemplateLiterals": true
, "ignoreRegExpLiterals": true
}]
, "space-before-function-paren": [ "error", {
"anonymous": "always"
, "named": "never"
, "asyncArrow": "always"
}]
, "no-useless-escape": "off"
, "no-prototype-builtins": "off"
, "no-async-promise-executor": "off"
, "semi": [ "error", "always"]
, "comma-dangle": [ "error", "never"]
, "comma-style": [ "error", "first"]
, "no-multiple-empty-lines": [ "error", { "max": 2 }]
, "no-console": [ "error", {
"allow": [ "info", "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"
}
}

5
app/.eslintrc.json Normal file
View File

@@ -0,0 +1,5 @@
{
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}

View File

@@ -8,7 +8,7 @@
"package": "node bin/build.js --package",
"install-manifest": "node bin/install-manifest.js",
"remove-manifest": "node bin/install-manifest.js --remove",
"lint": "tslint -c tslint.json -p ."
"lint": "eslint src --ext .ts,.tsx"
},
"dependencies": {
"bplist-creator": "0.0.8",

View File

@@ -5,7 +5,7 @@ import castv2 from "castv2";
import Session from "./Session";
import { Message } from "../../messaging";
import { sendMessage } from "../../lib/nativeMessaging"
import { sendMessage } from "../../lib/nativeMessaging";
const NS_MEDIA = "urn:x-cast:com.google.cast.media";

View File

@@ -67,7 +67,7 @@ export default class Session {
transportHeartbeat.send({ type: "PING" });
}
this.clientHeartbeat!.send({ type: "PING" });
this.clientHeartbeat?.send({ type: "PING" });
}, 5000);
this.clientReceiver.send({

View File

@@ -44,7 +44,7 @@ export function handleMediaMessage (message: any) {
if (existingMedia.has(mediaId)) {
// Forward message to instance message handler
existingMedia.get(mediaId)!.messageHandler(message);
existingMedia.get(mediaId)?.messageHandler(message);
} else {
if (message.subject === "bridge:media/initialize") {
// Get Session object media belongs to

View File

@@ -16,7 +16,7 @@ export let mediaServer: http.Server | undefined;
export async function startMediaServer(filePath: string, port: number) {
if (mediaServer?.listening) {
await stopMediaServer();
stopMediaServer();
}
let fileDir: string;
@@ -74,7 +74,9 @@ export async function startMediaServer (filePath: string, port: number) {
path.join(fileDir, dirEntry.name)));
}
}
} catch (err) {}
} catch (err) {
// TODO: Handle?
}
mediaServer = http.createServer(async (req, res) => {
if (!req.url) {

View File

@@ -14,10 +14,12 @@ export function init (port: number) {
process.stdout.write("Starting WebSocket server... ");
const wss = new WebSocket.Server({ port }, () => {
// eslint-disable-next-line no-console
console.log("Done!");
});
wss.on("error", (err) => {
// eslint-disable-next-line no-console
console.log("Failed!");
console.error(err);
});
@@ -26,6 +28,7 @@ export function init (port: number) {
wss.on("connection", socket => {
// Stream for incoming WebSocket messages
const messageStream = new Readable({ objectMode: true });
// eslint-disable-next-line @typescript-eslint/no-empty-function
messageStream._read = () => {};
socket.on("message", (message: string) => {

View File

@@ -22,8 +22,10 @@ const argv = minimist(process.argv.slice(2), {
if (argv.version) {
// eslint-disable-next-line no-console
console.log(`v${__applicationVersion}`);
} else if (argv.help) {
// eslint-disable-next-line no-console
console.log(
`Usage: ${argv.__name} [options]

View File

@@ -1,5 +0,0 @@
{
"extends": [
"../tslint.json"
]
}

View File

@@ -1,13 +0,0 @@
"use strict";
const { spawnSync } = require("child_process");
const { ROOT, INCLUDE_PATH } = require("./lib/paths");
spawnSync(`tslint --config ${ROOT}/tslint.json \
--project ${ROOT}/tsconfig.json \
"${INCLUDE_PATH}/**/*.ts{,x}"`
, {
shell: true
, stdio: [ process.stdin, process.stdout, process.stderr ]
});

View File

@@ -8,7 +8,7 @@
"package": "node bin/build.js --package",
"watch": "node bin/build.js --watch",
"start": "web-ext run -s ../dist/ext/",
"lint": "node bin/lint.js"
"lint": "eslint src --ext .ts,.tsx"
},
"devDependencies": {
"@types/firefox-webext-browser": "^82.0.0",

View File

@@ -26,7 +26,6 @@ export interface Shim {
}
// tslint:disable-next-line:new-parens
export default new class ShimManager {
private activeShims = new Set<Shim>();
@@ -164,8 +163,6 @@ export default new class ShimManager {
throw logger.error("Shim associated with content sender missing tab/frame ID");
}
const contentTab = await browser.tabs.get(shim.contentTabId);
try {
const selection =
await ReceiverSelectorManager.getSelection(
@@ -231,8 +228,8 @@ export default new class ShimManager {
}
/**
* TODO: If we're closing a selector, make sure it's the
* same one that caused the session creation.
* TODO: If we're closing a selector, make sure it's the same
* one that caused the session creation.
*/
case "main:sessionCreated": {
const selector = await ReceiverSelectorManager.getSelector();

View File

@@ -14,7 +14,6 @@ interface EventMap {
"statusUpdate": { id: string, status: ReceiverStatus };
}
// tslint:disable-next-line:new-parens
export default new class StatusManager
extends TypedEventTarget<EventMap> {

View File

@@ -193,7 +193,7 @@ async function init () {
*/
messaging.onConnect.addListener(async port => {
if (port.name === "shim") {
ShimManager.createShim(port as any);
ShimManager.createShim(port);
}
});
}

View File

@@ -4,7 +4,7 @@ import loadSender from "../lib/loadSender";
import logger from "../lib/logger";
import options from "../lib/options";
import { getMediaTypesForPageUrl, stringify } from "../lib/utils";
import { stringify } from "../lib/utils";
import { ReceiverSelectionActionType
, ReceiverSelectorMediaType } from "./receiverSelector";
@@ -98,9 +98,6 @@ browser.menus.onClicked.addListener(async (info, tab) => {
throw logger.error("Menu handler page URL not found.");
}
const availableMediaTypes = getMediaTypesForPageUrl(info.pageUrl);
switch (info.menuItemId) {
case menuIdCast: {
const selection = await ReceiverSelectorManager.getSelection(

View File

@@ -20,7 +20,7 @@ const _ = browser.i18n.getMessage;
// TODO: Figure out lifetime properly
export default class NativeReceiverSelector extends ReceiverSelector {
private bridgePort: (Port | null) = null;
private wasReceiverSelected: boolean = false;
private wasReceiverSelected = false;
#isOpen = false;

View File

@@ -24,7 +24,7 @@ export default class PopupReceiverSelector extends ReceiverSelector {
private defaultMediaType?: ReceiverSelectorMediaType;
private availableMediaTypes?: ReceiverSelectorMediaType;
private wasReceiverSelected: boolean = false;
private wasReceiverSelected = false;
private appId?: string;

18
ext/src/global.d.ts vendored
View File

@@ -5,7 +5,7 @@ declare const APPLICATION_VERSION: string;
declare interface Object {
// tslint:disable-next-line:ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
wrappedJSObject: Object;
}
@@ -67,7 +67,6 @@ declare function exportFunction (
, options?: ExportFunctionOptions): ExportFunctionFunc;
// Fix issues with @types/firefox-webext-browser
declare namespace browser.events {
/**
@@ -96,18 +95,3 @@ declare namespace browser.runtime {
, includeTlsChannelId?: boolean
}): browser.runtime.Port;
}
// Allow default attribute on <button>
declare namespace React {
interface ButtonHTMLAttributes<T> {
default?: boolean;
}
}
declare namespace JSX {
interface IntrinsicElements {
button: React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
}
}

View File

@@ -33,4 +33,4 @@ export default class Messenger<T> {
return browser.runtime.onConnect.hasListener(cb as any);
}
}
};
}

View File

@@ -6,10 +6,10 @@ export class Logger {
public log(message: string, data?: any) {
const formattedMessage = `${this.prefix} (Log): ${message}`;
if (data) {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.log(formattedMessage, data);
} else {
// tslint:disable-next-line:no-console
// eslint-disable-next-line no-console
console.log(formattedMessage);
}
}

View File

@@ -6,7 +6,6 @@ import options from "./options";
import { Message, Port } from "../messaging";
type DisconnectListener = (port: Port) => void;
type MessageListener = (message: Message) => void;

View File

@@ -41,7 +41,6 @@ interface EventMap {
"changed": Array<keyof Options>;
}
// tslint:disable-next-line:new-parens
export default new class extends TypedEventTarget<EventMap> {
constructor() {
super();

View File

@@ -6,12 +6,10 @@ import { ReceiverSelectorMediaType } from "../background/receiverSelector";
export function getNextEllipsis(ellipsis: string): string {
/* tslint:disable:curly */
if (ellipsis === "") return ".";
if (ellipsis === ".") return "..";
if (ellipsis === "..") return "...";
if (ellipsis === "...") return "";
/* tslint:enable:curly */
return "";
}
@@ -111,7 +109,6 @@ export function getWindowCenteredProps (
}
// tslint:disable-next-line:max-line-length
export const REMOTE_MATCH_PATTERN_REGEX = /^(?:(?:(\*|https?|ftp):\/\/(\*|(?:\*\.(?:[^\/\*:]\.?)+(?:[^\.])|[^\/\*:]*))?)(\/.*)|<all_urls>)$/;

View File

@@ -234,8 +234,6 @@ function getMedia (opts: InitOptions): Promise<cast.media.Media> {
let ignoreMediaEvents = false;
async function registerMediaElementListeners() {
if (await options.get("mediaSyncElement")) {
function checkIgnore(ev: Event) {
if (ignoreMediaEvents) {
ignoreMediaEvents = false;
@@ -243,6 +241,7 @@ async function registerMediaElementListeners () {
}
}
if (await options.get("mediaSyncElement")) {
mediaElement.addEventListener("play", checkIgnore, true);
mediaElement.addEventListener("pause", checkIgnore, true);
mediaElement.addEventListener("suspend", checkIgnore, true);
@@ -380,8 +379,7 @@ export async function init (opts: InitOptions) {
});
if (await options.get("mediaStopOnUnload")) {
// tslint:disable-next-line: no-empty
currentSession.stop(() => {}, () => {});
currentSession.stop();
}
});
}

View File

@@ -28,7 +28,6 @@ Element.prototype.attachShadow = function (init) {
};
function getShadowRootFromNode(node: Node): ShadowRoot | undefined {
// Don't touch our custom element
if (node instanceof PlayerElement) {
@@ -51,7 +50,7 @@ function deepQuerySelector (selector: string): Element | null {
, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
// eslint-disable-next-line no-cond-assign
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (!shadowRoot) {
@@ -79,7 +78,7 @@ function deepQuerySelectorAll (selector: string): Node[] {
const nodes: Node[] = [];
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
// eslint-disable-next-line no-cond-assign
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (shadowRoot) {

View File

@@ -14,7 +14,7 @@ export default class SessionRequest {
public appId: string
, public capabilities = [ Capability.VIDEO_OUT
, Capability.AUDIO_OUT ]
, public requestSessionTimeout: number = (new Timeout()).requestSession
, public requestSessionTimeout = (new Timeout()).requestSession
, public androidReceiverCompatible = false
, public credentialsData: (CredentialsData | null) = null) {}
}

View File

@@ -116,7 +116,7 @@ export function initialize (
}
export function logMessage(message: string): void {
/* tslint:disable-next-line:no-console */
// eslint-disable-next-line no-console
console.log("CAST MSG:", message);
}
@@ -343,6 +343,7 @@ onMessage(async message => {
(selectedReceiver as any)._address = message.data.receiver.host;
(selectedReceiver as any)._port = message.data.receiver.port;
// eslint-disable-next-line no-inner-declarations
function createSession() {
sessionList.push(new Session(
sessionList.length.toString() // sessionId

View File

@@ -1,7 +1,8 @@
"use strict";
export default class LiveSeekableRange {
constructor (public start?: number
constructor(
public start?: number
, public end?: number
, public isMovingWindow?: boolean
, public isLiveDone?: boolean) {}

View File

@@ -11,9 +11,9 @@ export default class LoadRequest {
public currentTime: (number | null) = null;
public customData: any = null;
public media: MediaInfo;
public requestId: number = 0;
public requestId = 0;
public sessionId: (string | null) = null;
public type: string = "LOAD";
public type = "LOAD";
constructor(mediaInfo: MediaInfo) {
this.media = mediaInfo;

View File

@@ -103,13 +103,13 @@ export default class Media {
public breakStatus?: BreakStatus;
public currentItemId: (number | null) = null;
public customData: any = null;
public currentTime: number = 0;
public currentTime = 0;
public idleReason: (string | null) = null;
public items: (QueueItem[] | null) = null;
public liveSeekableRange?: LiveSeekableRange;
public loadingItemId: (number | null) = null;
public media: (MediaInfo | null) = null;
public playbackRate: number = 1;
public playbackRate = 1;
public playerState: string = PlayerState.IDLE;
public preloadedItemId: (number | null) = null;
public queueData?: QueueData;

View File

@@ -8,7 +8,7 @@ export default class QueueInsertItemsRequest {
public insertBefore: (number | null) = null;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public type: string = "QUEUE_INSERT";
public type = "QUEUE_INSERT";
constructor(
public items: QueueItem[]) {}

View File

@@ -5,13 +5,13 @@ import MediaInfo from "./MediaInfo";
export default class QueueItem {
public activeTrackIds: (number[] | null) = null;
public autoplay: boolean = true;
public autoplay = true;
public customData: any = null;
public itemId: (number | null) = null;
public media: MediaInfo;
public playbackDuration: (number | null) = null;
public preloadTime: number = 0;
public startTime: number = 0;
public preloadTime = 0;
public startTime = 0;
constructor(mediaInfo: MediaInfo) {
this.media = mediaInfo;

View File

@@ -10,8 +10,8 @@ export default class QueueLoadRequest {
public repeatMode: string = RepeatMode.OFF;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public startIndex: number = 0;
public type: string = "QUEUE_LOAD";
public startIndex = 0;
public type = "QUEUE_LOAD";
constructor(
public items: QueueItem[]) {}

View File

@@ -4,7 +4,7 @@ export default class QueueRemoveItemsRequest {
public customData: any = null;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public type: string = "QUEUE_REMOVE";
public type = "QUEUE_REMOVE";
constructor(
public itemIds: number[]) {}

View File

@@ -5,7 +5,7 @@ export default class QueueReorderItemsRequest {
public insertBefore: (number | null) = null;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public type: string = "QUEUE_REORDER";
public type = "QUEUE_REORDER";
constructor(
public itemIds: number[]) {}

View File

@@ -5,5 +5,5 @@ export default class QueueSetPropertiesRequest {
public repeatMode: (string | null) = null;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public type: string = "QUEUE_UPDATE";
public type = "QUEUE_UPDATE";
}

View File

@@ -7,7 +7,7 @@ export default class QueueUpdateItemsRequest {
public customData: any = null;
public requestId: (number | null) = null;
public sessionId: (string | null) = null;
public type: string = "QUEUE_UPDATE";
public type = "QUEUE_UPDATE";
constructor(
public items: QueueItem[]) {}

View File

@@ -6,5 +6,6 @@ import { UserAction } from "../enums";
export default class UserActionState {
public customData: any = null;
constructor (public userAction: UserAction) {}
constructor(
public userAction: UserAction) {}
}

View File

@@ -4,7 +4,8 @@ import { HdrType } from "../enums";
export default class VideoInformation {
constructor (public width: number
constructor(
public width: number
, public height: number
, public hdrType: HdrType) {}
}

View File

@@ -26,8 +26,6 @@ export default class GoogleCastLauncher extends HTMLElement {
}
`;
// tslint:disable:max-line-length
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
const icon = document.createElementNS(SVG_NAMESPACE, "svg");
@@ -67,9 +65,6 @@ export default class GoogleCastLauncher extends HTMLElement {
// Add icon paths to SVG
icon.append(iconArch0, iconArch1, iconArch2, iconBox, iconBoxFill);
// tslint:enable:max-line-length
const shadow = this.attachShadow({ mode: "open" });
shadow.append(icon, style);

View File

@@ -7,7 +7,7 @@ export default class CastOptions {
public autoJoinPolicy: string = cast.AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED;
public language: (string | null) = null;
public receiverApplicationId: (string | null) = null;
public resumeSavedSession: boolean = true;
public resumeSavedSession = true;
constructor(options: CastOptions = ({} as CastOptions)) {
if (options.autoJoinPolicy) {

View File

@@ -1,4 +1,4 @@
/* tslint:disable:max-line-length */
/* eslint-disable max-len */
"use strict";
import React, { Component } from "react";

View File

@@ -1,4 +1,4 @@
/* tslint:disable:max-line-length */
/* eslint-disable max-len */
"use strict";
import React, { Component } from "react";

View File

@@ -1,4 +1,4 @@
/* tslint:disable:max-line-length */
/* eslint-disable max-len */
"use strict";
import React, { Component } from "react";
@@ -402,6 +402,7 @@ class OptionsApp extends Component<
{ _("optionsReset") }
</button>
<button type="submit"
// @ts-ignore
default
disabled={ !this.state.isFormValid }>
{ _("optionsSave") }
@@ -469,7 +470,8 @@ class OptionsApp extends Component<
this.setState(currentState => {
if (currentState.options) {
currentState.options[ev.target.name] = parseInt(ev.target.value);
currentState.options[ev.target.name] =
parseInt(ev.target.value);
}
return currentState;

View File

@@ -1,4 +1,4 @@
/* tslint:disable:max-line-length */
/* eslint-disable max-len */
"use strict";
import React, { Component } from "react";
@@ -29,6 +29,7 @@ browser.runtime.getPlatformInfo()
});
interface PopupAppProps {}
interface PopupAppState {
receivers: Receiver[];
mediaType: ReceiverSelectorMediaType;
@@ -41,12 +42,12 @@ interface PopupAppState {
mirroringEnabled: boolean;
}
class PopupApp extends Component<{}, PopupAppState> {
class PopupApp extends Component<PopupAppProps, PopupAppState> {
private port?: Port;
private win?: browser.windows.Window;
private defaultMediaType?: ReceiverSelectorMediaType;
constructor (props: {}) {
constructor(props: PopupAppProps) {
super(props);
this.state = {
@@ -128,6 +129,10 @@ class PopupApp extends Component<{}, PopupAppState> {
}
public render() {
/*
// TODO: Add file support back to popup
let truncatedFileName: string;
if (this.state.filePath) {
@@ -138,6 +143,7 @@ class PopupApp extends Component<{}, PopupAppState> {
? `${fileName.substring(0, 12)}...`
: fileName;
}
*/
const isAppMediaTypeSelected =
this.state.mediaType === ReceiverSelectorMediaType.App;
@@ -147,7 +153,7 @@ class PopupApp extends Component<{}, PopupAppState> {
this.state.mediaType === ReceiverSelectorMediaType.Screen;
const isSelectedMediaTypeAvailable =
!!(this.state.availableMediaTypes & this.state.mediaType)
!!(this.state.availableMediaTypes & this.state.mediaType);
const isAppMediaTypeAvailable = !!(this.state.availableMediaTypes
& ReceiverSelectorMediaType.App);

View File

@@ -1,8 +0,0 @@
{
"extends": [
"../tslint.json"
]
, "rules": {
"no-bitwise": false
}
}

1148
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -26,13 +26,15 @@
"@types/semver": "^7.3.4",
"@types/uuid": "^8.3.0",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"fs-extra": "^9.1.0",
"glob": "^7.1.6",
"jasmine-console-reporter": "^3.1.0",
"minimist": "^1.2.5",
"selenium-webdriver": "^4.0.0-beta.1",
"semver": "^7.3.4",
"tslint": "^6.1.3",
"typescript": "^4.1.5",
"uuid": "^8.3.2",
"ws": "^7.4.3"

View File

@@ -1,33 +0,0 @@
{
"defaultSeverity": "error"
, "extends": [
"tslint:recommended"
]
, "jsRules": false
, "rules": {
"array-type": [ true, "array-simple" ],
"arrow-parens": false
, "import-spacing": false
, "interface-name": false
, "max-classes-per-file": false
, "max-line-length": [ true, {
"limit": 80
, "ignore-pattern": "//|.*(\"|`);?$"
}]
, "member-access": [ true ]
, "no-consecutive-blank-lines": false
, "no-console": [ true, "log" ]
, "no-namespace": [ true, "allow-declarations" ]
, "object-literal-sort-keys": false
, "radix": false
, "semicolon": [ true, "always" ]
, "space-before-function-paren": [ true, "always" ]
, "trailing-comma": false
, "variable-name": [ true
, "ban-keywords"
, "check-format"
, "allow-pascal-case"
, "allow-leading-underscore" ]
}
, "rulesDirectory": []
}