From bccdaf77d4a8fd28c8a3032a18617f420ff5d3ee Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Tue, 17 Nov 2020 23:16:35 +0100 Subject: [PATCH] web: Enforce camelCase --- web/packages/core/src/.eslintrc.json | 9 ++++++++- web/packages/core/src/globals.d.ts | 2 ++ web/packages/core/src/load-ruffle.ts | 12 ++++++------ web/packages/core/src/public-api.ts | 6 +++--- web/packages/core/src/public-path.ts | 14 +++++++------- web/packages/core/src/ruffle-imports.ts | 18 +++++++++--------- web/packages/core/src/ruffle-player.ts | 8 ++++---- 7 files changed, 39 insertions(+), 30 deletions(-) diff --git a/web/packages/core/src/.eslintrc.json b/web/packages/core/src/.eslintrc.json index f63ef3ffc..0743314d6 100644 --- a/web/packages/core/src/.eslintrc.json +++ b/web/packages/core/src/.eslintrc.json @@ -18,6 +18,13 @@ ], "rules": { "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_" }] + "@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_" }], + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": ["variable", "function"], + "format": ["camelCase", "UPPER_CASE"] + } + ] } } diff --git a/web/packages/core/src/globals.d.ts b/web/packages/core/src/globals.d.ts index fc0282c84..578250722 100644 --- a/web/packages/core/src/globals.d.ts +++ b/web/packages/core/src/globals.d.ts @@ -1,3 +1,5 @@ +/* eslint @typescript-eslint/naming-convention:off */ + declare let __webpack_public_path__: string; declare let runtime_path: string; declare let __CHANNEL__: string; diff --git a/web/packages/core/src/load-ruffle.ts b/web/packages/core/src/load-ruffle.ts index 0bc64ada1..8d5b7642f 100644 --- a/web/packages/core/src/load-ruffle.ts +++ b/web/packages/core/src/load-ruffle.ts @@ -28,11 +28,11 @@ async function fetch_ruffle(): Promise<{ new (...args: any[]): Ruffle }> { //We currently assume that if we are not executing inside the extension, //then we can use webpack to get Ruffle. - const ruffle_module = await import("../pkg/ruffle_web"); - return ruffle_module.Ruffle; + const module = await import("../pkg/ruffle_web"); + return module.Ruffle; } -let last_loaded_ruffle: Promise<{ new (...args: any[]): Ruffle }> | null = null; +let lastLoaded: Promise<{ new (...args: any[]): Ruffle }> | null = null; /** * Obtain an instance of `Ruffle`. @@ -40,9 +40,9 @@ let last_loaded_ruffle: Promise<{ new (...args: any[]): Ruffle }> | null = null; * This function returns a promise which yields `Ruffle` asynchronously. */ export function load_ruffle(): Promise<{ new (...args: any[]): Ruffle }> { - if (last_loaded_ruffle == null) { - last_loaded_ruffle = fetch_ruffle(); + if (lastLoaded == null) { + lastLoaded = fetch_ruffle(); } - return last_loaded_ruffle; + return lastLoaded; } diff --git a/web/packages/core/src/public-api.ts b/web/packages/core/src/public-api.ts index 609340f0c..83d7b4246 100644 --- a/web/packages/core/src/public-api.ts +++ b/web/packages/core/src/public-api.ts @@ -127,10 +127,10 @@ export class PublicAPI { for (const k in this.sources) { if (Object.prototype.hasOwnProperty.call(this.sources, k)) { - const k_version = Version.fromSemver(this.sources[k].version); - if (k_version.hasPrecedenceOver(newestVersion)) { + const kVersion = Version.fromSemver(this.sources[k].version); + if (kVersion.hasPrecedenceOver(newestVersion)) { newestName = k; - newestVersion = k_version; + newestVersion = kVersion; } } } diff --git a/web/packages/core/src/public-path.ts b/web/packages/core/src/public-path.ts index bd20db88b..431681130 100644 --- a/web/packages/core/src/public-path.ts +++ b/web/packages/core/src/public-path.ts @@ -21,15 +21,15 @@ import { Config } from "./config"; * @returns The public path for the given source. */ export function public_path(config: Config, source_name: string): string { - let public_path = ""; + let path = ""; if ( config !== undefined && config.public_paths !== undefined && config.public_paths[source_name] !== undefined ) { - public_path = config.public_paths[source_name]; + path = config.public_paths[source_name]; } else if (config !== undefined && config.public_path !== undefined) { - public_path = config.public_path; + path = config.public_path; } else if ( document.currentScript !== undefined && document.currentScript !== null && @@ -37,16 +37,16 @@ export function public_path(config: Config, source_name: string): string { ) { // Default to the directory where this script resides. try { - public_path = new URL(".", document.currentScript.src).href; + path = new URL(".", document.currentScript.src).href; } catch (e) { console.warn("Unable to get currentScript URL"); } } // Webpack expects the paths to end with a /. - if (public_path !== "" && !public_path.endsWith("/")) { - public_path += "/"; + if (path !== "" && !path.endsWith("/")) { + path += "/"; } - return public_path; + return path; } diff --git a/web/packages/core/src/ruffle-imports.ts b/web/packages/core/src/ruffle-imports.ts index 99bbab3b7..de700716e 100644 --- a/web/packages/core/src/ruffle-imports.ts +++ b/web/packages/core/src/ruffle-imports.ts @@ -10,17 +10,17 @@ * @internal */ export function copyToAudioBuffer( - audio_buffer: AudioBuffer, - left_data: ArrayLike, - right_data: ArrayLike + audioBuffer: AudioBuffer, + leftData: ArrayLike, + rightData: ArrayLike ): void { - if (left_data) { - const dst_buffer = audio_buffer.getChannelData(0); - dst_buffer.set(left_data); + if (leftData) { + const dstBuffer = audioBuffer.getChannelData(0); + dstBuffer.set(leftData); } - if (right_data) { - const dst_buffer = audio_buffer.getChannelData(1); - dst_buffer.set(right_data); + if (rightData) { + const dstBuffer = audioBuffer.getChannelData(1); + dstBuffer.set(rightData); } } diff --git a/web/packages/core/src/ruffle-player.ts b/web/packages/core/src/ruffle-player.ts index 7f20bec7d..cb341e058 100644 --- a/web/packages/core/src/ruffle-player.ts +++ b/web/packages/core/src/ruffle-player.ts @@ -79,7 +79,7 @@ export class RufflePlayer extends HTMLElement { private _trace_observer: ((message: string) => void) | null; // eslint-disable-next-line @typescript-eslint/no-explicit-any - private Ruffle: Promise<{ new (...args: any[]): Ruffle }>; + private ruffleConstructor: Promise<{ new (...args: any[]): Ruffle }>; private panicked = false; /** @@ -123,7 +123,7 @@ export class RufflePlayer extends HTMLElement { this.allowScriptAccess = false; this._trace_observer = null; - this.Ruffle = load_ruffle(); + this.ruffleConstructor = load_ruffle(); return this; } @@ -251,7 +251,7 @@ export class RufflePlayer extends HTMLElement { console.log("Ruffle instance destroyed."); } - const Ruffle = await this.Ruffle.catch((e) => { + const ruffleConstructor = await this.ruffleConstructor.catch((e) => { console.error("Serious error loading Ruffle: " + e); // Serious duck typing. In error conditions, let's not make assumptions. @@ -278,7 +278,7 @@ export class RufflePlayer extends HTMLElement { throw e; }); - this.instance = new Ruffle( + this.instance = new ruffleConstructor( this.container, this, this.allowScriptAccess