Fine-tuning the @typescript-eslint/no-unused-vars rule

We now allow parameters to be unused. This is quite common in inherited methods.
This allows removing a bunch of: //eslint-disable-next-line @typescript-eslint/no-unused-vars
Also, "err" variables in catch MUST now be used and the special _exhaustiveCheck variable used in ":never" assigns can be unused.
This commit is contained in:
David Négrier 2022-04-22 17:46:02 +02:00
parent db11a465ef
commit 5cc97483e0
20 changed files with 15 additions and 76 deletions

View File

@ -27,7 +27,7 @@
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [ "@typescript-eslint/no-unused-vars": [
"error" "error", { "args": "none", "caughtErrors": "all", "varsIgnorePattern": "_exhaustiveCheck" }
], ],
"no-throw-literal": "error" "no-throw-literal": "error"
} }

View File

@ -71,7 +71,6 @@ export class Zone {
/** /**
* Notify listeners of this zone that this user entered * Notify listeners of this zone that this user entered
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
private notifyEnter(thing: Movable, oldZone: Zone | null, position: PositionInterface) { private notifyEnter(thing: Movable, oldZone: Zone | null, position: PositionInterface) {
for (const listener of this.listeners) { for (const listener of this.listeners) {
this.onEnters(thing, oldZone, listener); this.onEnters(thing, oldZone, listener);

View File

@ -4,12 +4,10 @@ import { VariablesRepositoryInterface } from "./VariablesRepositoryInterface";
* Mock class in charge of NOT saving/loading variables from the data store * Mock class in charge of NOT saving/loading variables from the data store
*/ */
export class VoidVariablesRepository implements VariablesRepositoryInterface { export class VoidVariablesRepository implements VariablesRepositoryInterface {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
loadVariables(roomUrl: string): Promise<{ [key: string]: string }> { loadVariables(roomUrl: string): Promise<{ [key: string]: string }> {
return Promise.resolve({}); return Promise.resolve({});
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveVariable(roomUrl: string, key: string, value: string): Promise<number> { saveVariable(roomUrl: string, key: string, value: string): Promise<number> {
return Promise.resolve(0); return Promise.resolve(0);
} }

View File

@ -36,7 +36,7 @@ module.exports = {
"eol-last": ["error", "always"], "eol-last": ["error", "always"],
"@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-explicit-any": "error",
"no-throw-literal": "error", "no-throw-literal": "error",
"@typescript-eslint/no-unused-vars": ["error"], "@typescript-eslint/no-unused-vars": ["error", { "args": "none", "caughtErrors": "all", "varsIgnorePattern": "_exhaustiveCheck" }],
// TODO: remove those ignored rules and write a stronger code! // TODO: remove those ignored rules and write a stronger code!
"@typescript-eslint/no-unsafe-call": "off", "@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/restrict-plus-operands": "off", "@typescript-eslint/restrict-plus-operands": "off",

View File

@ -294,7 +294,6 @@ class IframeListener {
handleMenuUnregisterEvent(iframeEvent.data.name); handleMenuUnregisterEvent(iframeEvent.data.name);
} else { } else {
// Keep the line below. It will throw an error if we forget to handle one of the possible values. // Keep the line below. It will throw an error if we forget to handle one of the possible values.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _exhaustiveCheck: never = iframeEvent; const _exhaustiveCheck: never = iframeEvent;
} }
} }

View File

@ -88,7 +88,6 @@ export function createState(target: "global" | "player"): WorkadventureStateComm
} }
return target.loadVariable(p.toString()); return target.loadVariable(p.toString());
}, },
// eslint-disable-next-line @typescript-eslint/no-unused-vars
set(target: WorkadventureStateCommands, p: PropertyKey, value: unknown, receiver: unknown): boolean { set(target: WorkadventureStateCommands, p: PropertyKey, value: unknown, receiver: unknown): boolean {
// Note: when using "set", there is no way to wait, so we ignore the return of the promise. // Note: when using "set", there is no way to wait, so we ignore the return of the promise.
// User must use WA.state.saveVariable to have error message. // User must use WA.state.saveVariable to have error message.

View File

@ -303,8 +303,7 @@ export class RoomConnection implements RoomConnection {
} }
default: { default: {
// Security check: if we forget a "case", the line below will catch the error at compile-time. // Security check: if we forget a "case", the line below will catch the error at compile-time.
// eslint-disable-next-line @typescript-eslint/no-unused-vars const _exhaustiveCheck: never = subMessage;
const tmp: never = subMessage;
} }
} }
} }
@ -491,8 +490,7 @@ export class RoomConnection implements RoomConnection {
} }
default: { default: {
// Security check: if we forget a "case", the line below will catch the error at compile-time. // Security check: if we forget a "case", the line below will catch the error at compile-time.
// eslint-disable-next-line @typescript-eslint/no-unused-vars const _exhaustiveCheck: never = message;
const tmp: never = message;
} }
} }
}; };

View File

@ -97,7 +97,6 @@ export class CameraManager extends Phaser.Events.EventEmitter {
}); });
return; return;
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.camera.pan(setTo.x, setTo.y, duration, Easing.SineEaseOut, true, (camera, progress, x, y) => { this.camera.pan(setTo.x, setTo.y, duration, Easing.SineEaseOut, true, (camera, progress, x, y) => {
if (this.cameraMode === CameraMode.Positioned) { if (this.cameraMode === CameraMode.Positioned) {
this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange; this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange;
@ -139,7 +138,6 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.emit(CameraManagerEvent.CameraUpdate, this.getCameraUpdateEventData()); this.emit(CameraManagerEvent.CameraUpdate, this.getCameraUpdateEventData());
return; return;
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.camera.pan(focusOn.x, focusOn.y, duration, Easing.SineEaseOut, true, (camera, progress, x, y) => { this.camera.pan(focusOn.x, focusOn.y, duration, Easing.SineEaseOut, true, (camera, progress, x, y) => {
this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange; this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange;
if (progress === 1) { if (progress === 1) {

View File

@ -1695,7 +1695,6 @@ ${escapedMessage}
private createCollisionWithPlayer() { private createCollisionWithPlayer() {
//add collision layer //add collision layer
for (const phaserLayer of this.gameMap.phaserLayers) { for (const phaserLayer of this.gameMap.phaserLayers) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.physics.add.collider(this.CurrentPlayer, phaserLayer, (object1: GameObject, object2: GameObject) => { this.physics.add.collider(this.CurrentPlayer, phaserLayer, (object1: GameObject, object2: GameObject) => {
//this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name) //this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name)
}); });
@ -1746,11 +1745,9 @@ ${escapedMessage}
emoteMenuStore.openEmoteMenu(); emoteMenuStore.openEmoteMenu();
} }
}); });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.CurrentPlayer.on(Phaser.Input.Events.POINTER_OVER, (pointer: Phaser.Input.Pointer) => { this.CurrentPlayer.on(Phaser.Input.Events.POINTER_OVER, (pointer: Phaser.Input.Pointer) => {
this.CurrentPlayer.pointerOverOutline(0x365dff); this.CurrentPlayer.pointerOverOutline(0x365dff);
}); });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.CurrentPlayer.on(Phaser.Input.Events.POINTER_OUT, (pointer: Phaser.Input.Pointer) => { this.CurrentPlayer.on(Phaser.Input.Events.POINTER_OUT, (pointer: Phaser.Input.Pointer) => {
this.CurrentPlayer.pointerOutOutline(); this.CurrentPlayer.pointerOutOutline();
}); });
@ -1852,8 +1849,7 @@ ${escapedMessage}
break; break;
} }
default: { default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars const _exhaustiveCheck: never = event;
const tmp: never = event;
} }
} }
} }

View File

@ -28,7 +28,7 @@ export class TexturesHelper {
}); });
} catch (error) { } catch (error) {
rt.destroy(); rt.destroy();
throw new Error("Could not get the snapshot"); throw new Error("Could not get the snapshot: " + error);
} }
} }

View File

@ -112,7 +112,6 @@ export class CustomizeScene extends AbstractCharacterScene {
this.onResize(); this.onResize();
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public update(time: number, dt: number): void { public update(time: number, dt: number): void {
this.customWokaPreviewer.update(); this.customWokaPreviewer.update();
} }

View File

@ -13,6 +13,5 @@ export class EmptyScene extends Scene {
create() {} create() {}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
update(time: number, delta: number): void {} update(time: number, delta: number): void {}
} }

View File

@ -24,7 +24,6 @@ export class EnableCameraScene extends ResizableScene {
public onResize(): void {} public onResize(): void {}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
update(time: number, delta: number): void {} update(time: number, delta: number): void {}
public login(): void { public login(): void {

View File

@ -49,7 +49,6 @@ export class LoginScene extends ResizableScene {
loginSceneVisibleStore.set(false); loginSceneVisibleStore.set(false);
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
update(time: number, delta: number): void {} update(time: number, delta: number): void {}
public onResize(): void {} public onResize(): void {}

View File

@ -16,7 +16,6 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
gameObjects: Phaser.GameObjects.GameObject[], gameObjects: Phaser.GameObjects.GameObject[],
deltaX: number, deltaX: number,
deltaY: number, deltaY: number,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
deltaZ: number deltaZ: number
): void { ): void {
this.gameScene.zoomByFactor(1 - (deltaY / 53) * 0.1); this.gameScene.zoomByFactor(1 - (deltaY / 53) * 0.1);
@ -51,7 +50,6 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
}); });
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {} public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {}
public handleSpaceKeyUpEvent(event: Event): Event { public handleSpaceKeyUpEvent(event: Event): Event {

View File

@ -14,15 +14,6 @@ export function getColorRgbFromHue(hue: number): { r: number; g: number; b: numb
return hsv_to_rgb(hue, 0.5, 0.95); return hsv_to_rgb(hue, 0.5, 0.95);
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function stringToDouble(string: string): number {
let num = 1;
for (const char of string.split("")) {
num *= char.charCodeAt(0);
}
return (num % 255) / 255;
}
//todo: test this. //todo: test this.
function hsv_to_rgb(hue: number, saturation: number, brightness: number): { r: number; g: number; b: number } { function hsv_to_rgb(hue: number, saturation: number, brightness: number): { r: number; g: number; b: number } {
const h_i = Math.floor(hue * 6); const h_i = Math.floor(hue * 6);

View File

@ -27,7 +27,7 @@
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [ "@typescript-eslint/no-unused-vars": [
"error" "error", { "args": "none", "caughtErrors": "all", "varsIgnorePattern": "_exhaustiveCheck" }
], ],
"no-throw-literal": "error" "no-throw-literal": "error"
} }

View File

@ -40,12 +40,13 @@ class AdminApi implements AdminInterface {
try { try {
authTokenData = jwtTokenManager.verifyJWTToken(authToken); authTokenData = jwtTokenManager.verifyJWTToken(authToken);
userId = authTokenData.identifier; userId = authTokenData.identifier;
//eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) { } catch (e) {
try { try {
// Decode token, in this case we don't need to create new token. // Decode token, in this case we don't need to create new token.
authTokenData = jwtTokenManager.verifyJWTToken(authToken, true); authTokenData = jwtTokenManager.verifyJWTToken(authToken, true);
userId = authTokenData.identifier; userId = authTokenData.identifier;
console.info("JWT expire, but decoded", userId); console.info("JWT expire, but decoded:", userId);
} catch (e) { } catch (e) {
if (e instanceof InvalidTokenError) { if (e instanceof InvalidTokenError) {
throw new Error("Token decrypted error"); throw new Error("Token decrypted error");

View File

@ -12,13 +12,9 @@ import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
class LocalAdmin implements AdminInterface { class LocalAdmin implements AdminInterface {
fetchMemberDataByUuid( fetchMemberDataByUuid(
userIdentifier: string, userIdentifier: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
playUri: string, playUri: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ipAddress: string, ipAddress: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
characterLayers: string[], characterLayers: string[],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string locale?: string
): Promise<FetchMemberDataByUuidResponse> { ): Promise<FetchMemberDataByUuidResponse> {
return Promise.resolve({ return Promise.resolve({
@ -32,13 +28,7 @@ class LocalAdmin implements AdminInterface {
}); });
} }
fetchMapDetails( fetchMapDetails(playUri: string, authToken?: string, locale?: string): Promise<MapDetailsData | RoomRedirect> {
playUri: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
authToken?: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string
): Promise<MapDetailsData | RoomRedirect> {
const roomUrl = new URL(playUri); const roomUrl = new URL(playUri);
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname); const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname);
@ -63,65 +53,42 @@ class LocalAdmin implements AdminInterface {
} }
async fetchMemberDataByToken( async fetchMemberDataByToken(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
organizationMemberToken: string, organizationMemberToken: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
playUri: string | null, playUri: string | null,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string locale?: string
): Promise<AdminApiData> { ): Promise<AdminApiData> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
reportPlayer( reportPlayer(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
reportedUserUuid: string, reportedUserUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
reportedUserComment: string, reportedUserComment: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
reporterUserUuid: string, reporterUserUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
reportWorldSlug: string, reportWorldSlug: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string locale?: string
) { ) {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
async verifyBanUser( async verifyBanUser(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
userUuid: string, userUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ipAddress: string, ipAddress: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
roomUrl: string, roomUrl: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string locale?: string
): Promise<AdminBannedData> { ): Promise<AdminBannedData> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
async getUrlRoomsFromSameWorld( async getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise<string[]> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
roomUrl: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale?: string
): Promise<string[]> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
getProfileUrl( getProfileUrl(accessToken: string): string {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
accessToken: string
): string {
new Error("No admin backoffice set!"); new Error("No admin backoffice set!");
return ""; return "";
} }
async logoutOauth( async logoutOauth(token: string): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
token: string
): Promise<void> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
} }

View File

@ -5,7 +5,6 @@ class LocalWokaService implements WokaServiceInterface {
/** /**
* Returns the list of all available Wokas & Woka Parts for the current user. * Returns the list of all available Wokas & Woka Parts for the current user.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getWokaList(roomId: string, token: string): Promise<WokaList | undefined> { async getWokaList(roomId: string, token: string): Promise<WokaList | undefined> {
const wokaData: WokaList = await require("../../data/woka.json"); const wokaData: WokaList = await require("../../data/woka.json");
if (!wokaData) { if (!wokaData) {