web: Enforce camelCase

This commit is contained in:
Nathan Adams 2020-11-17 23:16:35 +01:00 committed by Mike Welsh
parent 1519642a9a
commit bccdaf77d4
7 changed files with 39 additions and 30 deletions

View File

@ -18,6 +18,13 @@
], ],
"rules": { "rules": {
"@typescript-eslint/no-non-null-assertion": "off", "@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"]
}
]
} }
} }

View File

@ -1,3 +1,5 @@
/* eslint @typescript-eslint/naming-convention:off */
declare let __webpack_public_path__: string; declare let __webpack_public_path__: string;
declare let runtime_path: string; declare let runtime_path: string;
declare let __CHANNEL__: string; declare let __CHANNEL__: string;

View File

@ -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, //We currently assume that if we are not executing inside the extension,
//then we can use webpack to get Ruffle. //then we can use webpack to get Ruffle.
const ruffle_module = await import("../pkg/ruffle_web"); const module = await import("../pkg/ruffle_web");
return ruffle_module.Ruffle; 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`. * 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. * This function returns a promise which yields `Ruffle` asynchronously.
*/ */
export function load_ruffle(): Promise<{ new (...args: any[]): Ruffle }> { export function load_ruffle(): Promise<{ new (...args: any[]): Ruffle }> {
if (last_loaded_ruffle == null) { if (lastLoaded == null) {
last_loaded_ruffle = fetch_ruffle(); lastLoaded = fetch_ruffle();
} }
return last_loaded_ruffle; return lastLoaded;
} }

View File

@ -127,10 +127,10 @@ export class PublicAPI {
for (const k in this.sources) { for (const k in this.sources) {
if (Object.prototype.hasOwnProperty.call(this.sources, k)) { if (Object.prototype.hasOwnProperty.call(this.sources, k)) {
const k_version = Version.fromSemver(this.sources[k].version); const kVersion = Version.fromSemver(this.sources[k].version);
if (k_version.hasPrecedenceOver(newestVersion)) { if (kVersion.hasPrecedenceOver(newestVersion)) {
newestName = k; newestName = k;
newestVersion = k_version; newestVersion = kVersion;
} }
} }
} }

View File

@ -21,15 +21,15 @@ import { Config } from "./config";
* @returns The public path for the given source. * @returns The public path for the given source.
*/ */
export function public_path(config: Config, source_name: string): string { export function public_path(config: Config, source_name: string): string {
let public_path = ""; let path = "";
if ( if (
config !== undefined && config !== undefined &&
config.public_paths !== undefined && config.public_paths !== undefined &&
config.public_paths[source_name] !== 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) { } else if (config !== undefined && config.public_path !== undefined) {
public_path = config.public_path; path = config.public_path;
} else if ( } else if (
document.currentScript !== undefined && document.currentScript !== undefined &&
document.currentScript !== null && 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. // Default to the directory where this script resides.
try { try {
public_path = new URL(".", document.currentScript.src).href; path = new URL(".", document.currentScript.src).href;
} catch (e) { } catch (e) {
console.warn("Unable to get currentScript URL"); console.warn("Unable to get currentScript URL");
} }
} }
// Webpack expects the paths to end with a /. // Webpack expects the paths to end with a /.
if (public_path !== "" && !public_path.endsWith("/")) { if (path !== "" && !path.endsWith("/")) {
public_path += "/"; path += "/";
} }
return public_path; return path;
} }

View File

@ -10,17 +10,17 @@
* @internal * @internal
*/ */
export function copyToAudioBuffer( export function copyToAudioBuffer(
audio_buffer: AudioBuffer, audioBuffer: AudioBuffer,
left_data: ArrayLike<number>, leftData: ArrayLike<number>,
right_data: ArrayLike<number> rightData: ArrayLike<number>
): void { ): void {
if (left_data) { if (leftData) {
const dst_buffer = audio_buffer.getChannelData(0); const dstBuffer = audioBuffer.getChannelData(0);
dst_buffer.set(left_data); dstBuffer.set(leftData);
} }
if (right_data) { if (rightData) {
const dst_buffer = audio_buffer.getChannelData(1); const dstBuffer = audioBuffer.getChannelData(1);
dst_buffer.set(right_data); dstBuffer.set(rightData);
} }
} }

View File

@ -79,7 +79,7 @@ export class RufflePlayer extends HTMLElement {
private _trace_observer: ((message: string) => void) | null; private _trace_observer: ((message: string) => void) | null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // 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; private panicked = false;
/** /**
@ -123,7 +123,7 @@ export class RufflePlayer extends HTMLElement {
this.allowScriptAccess = false; this.allowScriptAccess = false;
this._trace_observer = null; this._trace_observer = null;
this.Ruffle = load_ruffle(); this.ruffleConstructor = load_ruffle();
return this; return this;
} }
@ -251,7 +251,7 @@ export class RufflePlayer extends HTMLElement {
console.log("Ruffle instance destroyed."); 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); console.error("Serious error loading Ruffle: " + e);
// Serious duck typing. In error conditions, let's not make assumptions. // Serious duck typing. In error conditions, let's not make assumptions.
@ -278,7 +278,7 @@ export class RufflePlayer extends HTMLElement {
throw e; throw e;
}); });
this.instance = new Ruffle( this.instance = new ruffleConstructor(
this.container, this.container,
this, this,
this.allowScriptAccess this.allowScriptAccess