From 9bcdc9ba338df6fcfe6140e217d036bac18ea950 Mon Sep 17 00:00:00 2001 From: jonny Date: Fri, 2 Jul 2021 19:05:03 +0200 Subject: [PATCH] linter fixes --- front/src/Connexion/Room.ts | 36 ++++---- front/src/Phaser/Components/TextUtils.ts | 12 +-- front/src/iframe_api.ts | 66 +++++++-------- front/tests/Phaser/Game/RoomTest.ts | 102 +++++++++++------------ 4 files changed, 108 insertions(+), 108 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 7b138198..fe9d3211 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -1,6 +1,6 @@ -import Axios from "axios"; -import { PUSHER_URL } from "../Enum/EnvironmentVariable"; -import type { CharacterTexture } from "./LocalUser"; +import Axios from 'axios'; +import { PUSHER_URL } from '../Enum/EnvironmentVariable'; +import type { CharacterTexture } from './LocalUser'; export class MapDetail { constructor(public readonly mapUrl: string, public readonly textures: CharacterTexture[] | undefined) {} @@ -15,19 +15,19 @@ export class Room { private _search: URLSearchParams; constructor(id: string) { - const url = new URL(id, "https://example.com"); + const url = new URL(id, 'https://example.com'); this.id = url.pathname; - if (this.id.startsWith("/")) { + if (this.id.startsWith('/')) { this.id = this.id.substr(1); } - if (this.id.startsWith("_/")) { + if (this.id.startsWith('_/')) { this.isPublic = true; - } else if (this.id.startsWith("@/")) { + } else if (this.id.startsWith('@/')) { this.isPublic = false; } else { - throw new Error("Invalid room ID"); + throw new Error('Invalid room ID'); } this._search = new URLSearchParams(url.search); @@ -38,16 +38,16 @@ export class Room { baseUrl: string, currentInstance: string ): { roomId: string; hash: string | null } { - let roomId = ""; + let roomId = ''; let hash = null; - if (!identifier.startsWith("/_/") && !identifier.startsWith("/@/")) { + if (!identifier.startsWith('/_/') && !identifier.startsWith('/@/')) { //relative file link //Relative identifier can be deep enough to rewrite the base domain, so we cannot use the variable 'baseUrl' as the actual base url for the URL objects. //We instead use 'workadventure' as a dummy base value. const baseUrlObject = new URL(baseUrl); const absoluteExitSceneUrl = new URL( identifier, - "http://workadventure/_/" + currentInstance + "/" + baseUrlObject.hostname + baseUrlObject.pathname + 'http://workadventure/_/' + currentInstance + '/' + baseUrlObject.hostname + baseUrlObject.pathname ); roomId = absoluteExitSceneUrl.pathname; //in case of a relative url, we need to create a public roomId roomId = roomId.substring(1); //remove the leading slash @@ -58,7 +58,7 @@ export class Room { } } else { //absolute room Id - const parts = identifier.split("#"); + const parts = identifier.split('#'); roomId = parts[0]; roomId = roomId.substring(1); //remove the leading slash if (parts.length > 1) { @@ -78,7 +78,7 @@ export class Room { if (this.isPublic) { const match = /_\/[^/]+\/(.+)/.exec(this.id); if (!match) throw new Error('Could not extract url from "' + this.id + '"'); - this.mapUrl = window.location.protocol + "//" + match[1]; + this.mapUrl = window.location.protocol + '//' + match[1]; resolve(new MapDetail(this.mapUrl, this.textures)); return; } else { @@ -89,7 +89,7 @@ export class Room { params: urlParts, }) .then(({ data }) => { - console.log("Map ", this.id, " resolves to URL ", data.mapUrl); + console.log('Map ', this.id, ' resolves to URL ', data.mapUrl); resolve(data); return; }) @@ -118,7 +118,7 @@ export class Room { } else { const match = /@\/([^/]+)\/([^/]+)\/.+/.exec(this.id); if (!match) throw new Error('Could not extract instance from "' + this.id + '"'); - this.instance = match[1] + "/" + match[2]; + this.instance = match[1] + '/' + match[2]; return this.instance; } } @@ -127,7 +127,7 @@ export class Room { const regex = /@\/([^/]+)\/([^/]+)(?:\/([^/]*))?/gm; const match = regex.exec(url); if (!match) { - throw new Error("Invalid URL " + url); + throw new Error('Invalid URL ' + url); } const results: { organizationSlug: string; worldSlug: string; roomSlug?: string } = { organizationSlug: match[1], @@ -140,8 +140,8 @@ export class Room { } public isDisconnected(): boolean { - const alone = this._search.get("alone"); - if (alone && alone !== "0" && alone.toLowerCase() !== "false") { + const alone = this._search.get('alone'); + if (alone && alone !== '0' && alone.toLowerCase() !== 'false') { return true; } return false; diff --git a/front/src/Phaser/Components/TextUtils.ts b/front/src/Phaser/Components/TextUtils.ts index e1ef6d21..3626d3a5 100644 --- a/front/src/Phaser/Components/TextUtils.ts +++ b/front/src/Phaser/Components/TextUtils.ts @@ -1,10 +1,10 @@ -import type { ITiledMapObject } from "../Map/ITiledMap"; -import type { GameScene } from "../Game/GameScene"; +import type { ITiledMapObject } from '../Map/ITiledMap'; +import type { GameScene } from '../Game/GameScene'; export class TextUtils { public static createTextFromITiledMapObject(scene: GameScene, object: ITiledMapObject): void { if (object.text === undefined) { - throw new Error("This object has not textual representation."); + throw new Error('This object has not textual representation.'); } const options: { fontStyle?: string; @@ -18,18 +18,18 @@ export class TextUtils { }; } = {}; if (object.text.italic) { - options.fontStyle = "italic"; + options.fontStyle = 'italic'; } // Note: there is no support for "strikeout" and "underline" let fontSize: number = 16; if (object.text.pixelsize) { fontSize = object.text.pixelsize; } - options.fontSize = fontSize + "px"; + options.fontSize = fontSize + 'px'; if (object.text.fontfamily) { options.fontFamily = '"' + object.text.fontfamily + '"'; } - let color = "#000000"; + let color = '#000000'; if (object.text.color !== undefined) { color = object.text.color; } diff --git a/front/src/iframe_api.ts b/front/src/iframe_api.ts index 1cd94d13..cd5f882d 100644 --- a/front/src/iframe_api.ts +++ b/front/src/iframe_api.ts @@ -1,4 +1,4 @@ -import { registeredCallbacks } from "./Api/iframe/registeredCallbacks"; +import { registeredCallbacks } from './Api/iframe/registeredCallbacks'; import { IframeResponseEvent, IframeResponseEventMap, @@ -6,19 +6,19 @@ import { isIframeErrorAnswerEvent, isIframeResponseEventWrapper, TypedMessageEvent, -} from "./Api/Events/IframeEvent"; -import chat from "./Api/iframe/chat"; -import type { IframeCallback } from "./Api/iframe/IframeApiContribution"; -import nav from "./Api/iframe/nav"; -import controls from "./Api/iframe/controls"; -import ui from "./Api/iframe/ui"; -import sound from "./Api/iframe/sound"; -import room from "./Api/iframe/room"; -import player from "./Api/iframe/player"; -import type { ButtonDescriptor } from "./Api/iframe/Ui/ButtonDescriptor"; -import type { Popup } from "./Api/iframe/Ui/Popup"; -import type { Sound } from "./Api/iframe/Sound/Sound"; -import { answerPromises, sendToWorkadventure } from "./Api/iframe/IframeApiContribution"; +} from './Api/Events/IframeEvent'; +import chat from './Api/iframe/chat'; +import type { IframeCallback } from './Api/iframe/IframeApiContribution'; +import nav from './Api/iframe/nav'; +import controls from './Api/iframe/controls'; +import ui from './Api/iframe/ui'; +import sound from './Api/iframe/sound'; +import room from './Api/iframe/room'; +import player from './Api/iframe/player'; +import type { ButtonDescriptor } from './Api/iframe/Ui/ButtonDescriptor'; +import type { Popup } from './Api/iframe/Ui/Popup'; +import type { Sound } from './Api/iframe/Sound/Sound'; +import { answerPromises, sendToWorkadventure } from './Api/iframe/IframeApiContribution'; const wa = { ui, @@ -36,7 +36,7 @@ const wa = { * @deprecated Use WA.chat.sendChatMessage instead */ sendChatMessage(message: string, author: string): void { - console.warn("Method WA.sendChatMessage is deprecated. Please use WA.chat.sendChatMessage instead"); + console.warn('Method WA.sendChatMessage is deprecated. Please use WA.chat.sendChatMessage instead'); chat.sendChatMessage(message, author); }, @@ -45,7 +45,7 @@ const wa = { */ disablePlayerControls(): void { console.warn( - "Method WA.disablePlayerControls is deprecated. Please use WA.controls.disablePlayerControls instead" + 'Method WA.disablePlayerControls is deprecated. Please use WA.controls.disablePlayerControls instead' ); controls.disablePlayerControls(); }, @@ -55,7 +55,7 @@ const wa = { */ restorePlayerControls(): void { console.warn( - "Method WA.restorePlayerControls is deprecated. Please use WA.controls.restorePlayerControls instead" + 'Method WA.restorePlayerControls is deprecated. Please use WA.controls.restorePlayerControls instead' ); controls.restorePlayerControls(); }, @@ -64,7 +64,7 @@ const wa = { * @deprecated Use WA.ui.displayBubble instead */ displayBubble(): void { - console.warn("Method WA.displayBubble is deprecated. Please use WA.ui.displayBubble instead"); + console.warn('Method WA.displayBubble is deprecated. Please use WA.ui.displayBubble instead'); ui.displayBubble(); }, @@ -72,7 +72,7 @@ const wa = { * @deprecated Use WA.ui.removeBubble instead */ removeBubble(): void { - console.warn("Method WA.removeBubble is deprecated. Please use WA.ui.removeBubble instead"); + console.warn('Method WA.removeBubble is deprecated. Please use WA.ui.removeBubble instead'); ui.removeBubble(); }, @@ -80,7 +80,7 @@ const wa = { * @deprecated Use WA.nav.openTab instead */ openTab(url: string): void { - console.warn("Method WA.openTab is deprecated. Please use WA.nav.openTab instead"); + console.warn('Method WA.openTab is deprecated. Please use WA.nav.openTab instead'); nav.openTab(url); }, @@ -88,7 +88,7 @@ const wa = { * @deprecated Use WA.sound.loadSound instead */ loadSound(url: string): Sound { - console.warn("Method WA.loadSound is deprecated. Please use WA.sound.loadSound instead"); + console.warn('Method WA.loadSound is deprecated. Please use WA.sound.loadSound instead'); return sound.loadSound(url); }, @@ -96,7 +96,7 @@ const wa = { * @deprecated Use WA.nav.goToPage instead */ goToPage(url: string): void { - console.warn("Method WA.goToPage is deprecated. Please use WA.nav.goToPage instead"); + console.warn('Method WA.goToPage is deprecated. Please use WA.nav.goToPage instead'); nav.goToPage(url); }, @@ -104,15 +104,15 @@ const wa = { * @deprecated Use WA.nav.goToRoom instead */ goToRoom(url: string): void { - console.warn("Method WA.goToRoom is deprecated. Please use WA.nav.goToRoom instead"); + console.warn('Method WA.goToRoom is deprecated. Please use WA.nav.goToRoom instead'); nav.goToRoom(url); }, /** * @deprecated Use WA.nav.openCoWebSite instead */ - openCoWebSite(url: string, allowApi: boolean = false, allowPolicy: string = ""): void { - console.warn("Method WA.openCoWebSite is deprecated. Please use WA.nav.openCoWebSite instead"); + openCoWebSite(url: string, allowApi: boolean = false, allowPolicy: string = ''): void { + console.warn('Method WA.openCoWebSite is deprecated. Please use WA.nav.openCoWebSite instead'); nav.openCoWebSite(url, allowApi, allowPolicy); }, @@ -120,7 +120,7 @@ const wa = { * @deprecated Use WA.nav.closeCoWebSite instead */ closeCoWebSite(): void { - console.warn("Method WA.closeCoWebSite is deprecated. Please use WA.nav.closeCoWebSite instead"); + console.warn('Method WA.closeCoWebSite is deprecated. Please use WA.nav.closeCoWebSite instead'); nav.closeCoWebSite(); }, @@ -128,28 +128,28 @@ const wa = { * @deprecated Use WA.controls.restorePlayerControls instead */ openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup { - console.warn("Method WA.openPopup is deprecated. Please use WA.ui.openPopup instead"); + console.warn('Method WA.openPopup is deprecated. Please use WA.ui.openPopup instead'); return ui.openPopup(targetObject, message, buttons); }, /** * @deprecated Use WA.chat.onChatMessage instead */ onChatMessage(callback: (message: string) => void): void { - console.warn("Method WA.onChatMessage is deprecated. Please use WA.chat.onChatMessage instead"); + console.warn('Method WA.onChatMessage is deprecated. Please use WA.chat.onChatMessage instead'); chat.onChatMessage(callback); }, /** * @deprecated Use WA.room.onEnterZone instead */ onEnterZone(name: string, callback: () => void): void { - console.warn("Method WA.onEnterZone is deprecated. Please use WA.room.onEnterZone instead"); + console.warn('Method WA.onEnterZone is deprecated. Please use WA.room.onEnterZone instead'); room.onEnterZone(name, callback); }, /** * @deprecated Use WA.room.onLeaveZone instead */ onLeaveZone(name: string, callback: () => void): void { - console.warn("Method WA.onLeaveZone is deprecated. Please use WA.room.onLeaveZone instead"); + console.warn('Method WA.onLeaveZone is deprecated. Please use WA.room.onLeaveZone instead'); room.onLeaveZone(name, callback); }, }; @@ -166,7 +166,7 @@ declare global { window.WA = wa; window.addEventListener( - "message", + 'message', (message: TypedMessageEvent>) => { if (message.source !== window.parent) { return; // Skip message in this event listener @@ -181,7 +181,7 @@ window.addEventListener( const resolver = answerPromises.get(queryId); if (resolver === undefined) { - throw new Error("In Iframe API, got an answer for a question that we have no track of."); + throw new Error('In Iframe API, got an answer for a question that we have no track of.'); } resolver.resolve(payloadData); @@ -192,7 +192,7 @@ window.addEventListener( const resolver = answerPromises.get(queryId); if (resolver === undefined) { - throw new Error("In Iframe API, got an error answer for a question that we have no track of."); + throw new Error('In Iframe API, got an error answer for a question that we have no track of.'); } resolver.reject(payloadError); diff --git a/front/tests/Phaser/Game/RoomTest.ts b/front/tests/Phaser/Game/RoomTest.ts index 3a5ccb52..2211c8cf 100644 --- a/front/tests/Phaser/Game/RoomTest.ts +++ b/front/tests/Phaser/Game/RoomTest.ts @@ -1,89 +1,89 @@ -import "jasmine"; -import { Room } from "../../../src/Connexion/Room"; +import 'jasmine'; +import { Room } from '../../../src/Connexion/Room'; -describe("Room getIdFromIdentifier()", () => { - it("should work with an absolute room id and no hash as parameter", () => { - const { roomId, hash } = Room.getIdFromIdentifier("/_/global/maps.workadventu.re/test2.json", "", ""); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); +describe('Room getIdFromIdentifier()', () => { + it('should work with an absolute room id and no hash as parameter', () => { + const { roomId, hash } = Room.getIdFromIdentifier('/_/global/maps.workadventu.re/test2.json', '', ''); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); expect(hash).toEqual(null); }); - it("should work with an absolute room id and a hash as parameters", () => { - const { roomId, hash } = Room.getIdFromIdentifier("/_/global/maps.workadventu.re/test2.json#start", "", ""); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); - expect(hash).toEqual("start"); + it('should work with an absolute room id and a hash as parameters', () => { + const { roomId, hash } = Room.getIdFromIdentifier('/_/global/maps.workadventu.re/test2.json#start', '', ''); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); + expect(hash).toEqual('start'); }); - it("should work with an absolute room id, regardless of baseUrl or instance", () => { + it('should work with an absolute room id, regardless of baseUrl or instance', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "/_/global/maps.workadventu.re/test2.json", - "https://another.domain/_/global/test.json", - "lol" + '/_/global/maps.workadventu.re/test2.json', + 'https://another.domain/_/global/test.json', + 'lol' ); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link and no hash as parameters", () => { + it('should work with a relative file link and no hash as parameters', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "./test2.json", - "https://maps.workadventu.re/test.json", - "global" + './test2.json', + 'https://maps.workadventu.re/test.json', + 'global' ); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link with no dot", () => { + it('should work with a relative file link with no dot', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "test2.json", - "https://maps.workadventu.re/test.json", - "global" + 'test2.json', + 'https://maps.workadventu.re/test.json', + 'global' ); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link two levels deep", () => { + it('should work with a relative file link two levels deep', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "../floor1/Floor1.json", - "https://maps.workadventu.re/floor0/Floor0.json", - "global" + '../floor1/Floor1.json', + 'https://maps.workadventu.re/floor0/Floor0.json', + 'global' ); - expect(roomId).toEqual("_/global/maps.workadventu.re/floor1/Floor1.json"); + expect(roomId).toEqual('_/global/maps.workadventu.re/floor1/Floor1.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link that rewrite the map domain", () => { + it('should work with a relative file link that rewrite the map domain', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "../../maps.workadventure.localhost/Floor1/floor1.json", - "https://maps.workadventu.re/floor0/Floor0.json", - "global" + '../../maps.workadventure.localhost/Floor1/floor1.json', + 'https://maps.workadventu.re/floor0/Floor0.json', + 'global' ); - expect(roomId).toEqual("_/global/maps.workadventure.localhost/Floor1/floor1.json"); + expect(roomId).toEqual('_/global/maps.workadventure.localhost/Floor1/floor1.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link that rewrite the map instance", () => { + it('should work with a relative file link that rewrite the map instance', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "../../../notglobal/maps.workadventu.re/Floor1/floor1.json", - "https://maps.workadventu.re/floor0/Floor0.json", - "global" + '../../../notglobal/maps.workadventu.re/Floor1/floor1.json', + 'https://maps.workadventu.re/floor0/Floor0.json', + 'global' ); - expect(roomId).toEqual("_/notglobal/maps.workadventu.re/Floor1/floor1.json"); + expect(roomId).toEqual('_/notglobal/maps.workadventu.re/Floor1/floor1.json'); expect(hash).toEqual(null); }); - it("should work with a relative file link that change the map type", () => { + it('should work with a relative file link that change the map type', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "../../../../@/tcm/is/great", - "https://maps.workadventu.re/floor0/Floor0.json", - "global" + '../../../../@/tcm/is/great', + 'https://maps.workadventu.re/floor0/Floor0.json', + 'global' ); - expect(roomId).toEqual("@/tcm/is/great"); + expect(roomId).toEqual('@/tcm/is/great'); expect(hash).toEqual(null); }); - it("should work with a relative file link and a hash as parameters", () => { + it('should work with a relative file link and a hash as parameters', () => { const { roomId, hash } = Room.getIdFromIdentifier( - "./test2.json#start", - "https://maps.workadventu.re/test.json", - "global" + './test2.json#start', + 'https://maps.workadventu.re/test.json', + 'global' ); - expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json"); - expect(hash).toEqual("start"); + expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); + expect(hash).toEqual('start'); }); });