mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 18:23:25 +00:00
Enabled the @typescript-eslint/no-unused-expressions eslint rule (#2014)
## Description: - Fixes #1790 - Fixed the codebase: - expressions short-circuiting with `&&` changed to proper `if` statements - `A instanceof B;` expressions now emit warnings ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: michal7952 --------- Co-authored-by: Evan <evanpelle@gmail.com>
This commit is contained in:
@@ -40,7 +40,6 @@ export default [
|
||||
rules: {
|
||||
// Disable rules that would fail. The failures should be fixed, and the entries here removed.
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-unused-expressions": "off",
|
||||
"no-unused-vars": "off",
|
||||
},
|
||||
},
|
||||
|
||||
+41
-12
@@ -106,10 +106,9 @@ class Client {
|
||||
gameVersion.innerText = version;
|
||||
|
||||
const newsModal = document.querySelector("news-modal") as NewsModal;
|
||||
if (!newsModal) {
|
||||
if (!newsModal || !(newsModal instanceof NewsModal)) {
|
||||
console.warn("News modal element not found");
|
||||
}
|
||||
newsModal instanceof NewsModal;
|
||||
const newsButton = document.querySelector("news-button") as NewsButton;
|
||||
if (!newsButton) {
|
||||
console.warn("News button element not found");
|
||||
@@ -168,7 +167,9 @@ class Client {
|
||||
const spModal = document.querySelector(
|
||||
"single-player-modal",
|
||||
) as SinglePlayerModal;
|
||||
spModal instanceof SinglePlayerModal;
|
||||
if (!spModal || !(spModal instanceof SinglePlayerModal)) {
|
||||
console.warn("Singleplayer modal element not found");
|
||||
}
|
||||
|
||||
const singlePlayer = document.getElementById("single-player");
|
||||
if (singlePlayer === null) throw new Error("Missing single-player");
|
||||
@@ -185,7 +186,9 @@ class Client {
|
||||
// });
|
||||
|
||||
const hlpModal = document.querySelector("help-modal") as HelpModal;
|
||||
hlpModal instanceof HelpModal;
|
||||
if (!hlpModal || !(hlpModal instanceof HelpModal)) {
|
||||
console.warn("Help modal element not found");
|
||||
}
|
||||
const helpButton = document.getElementById("help-button");
|
||||
if (helpButton === null) throw new Error("Missing help-button");
|
||||
helpButton.addEventListener("click", () => {
|
||||
@@ -195,7 +198,10 @@ class Client {
|
||||
const flagInputModal = document.querySelector(
|
||||
"flag-input-modal",
|
||||
) as FlagInputModal;
|
||||
flagInputModal instanceof FlagInputModal;
|
||||
if (!flagInputModal || !(flagInputModal instanceof FlagInputModal)) {
|
||||
console.warn("Flag input modal element not found");
|
||||
}
|
||||
|
||||
const flgInput = document.getElementById("flag-input_");
|
||||
if (flgInput === null) throw new Error("Missing flag-input_");
|
||||
flgInput.addEventListener("click", () => {
|
||||
@@ -205,6 +211,12 @@ class Client {
|
||||
this.patternsModal = document.querySelector(
|
||||
"territory-patterns-modal",
|
||||
) as TerritoryPatternsModal;
|
||||
if (
|
||||
!this.patternsModal ||
|
||||
!(this.patternsModal instanceof TerritoryPatternsModal)
|
||||
) {
|
||||
console.warn("Territory patterns modal element not found");
|
||||
}
|
||||
const patternButton = document.getElementById(
|
||||
"territory-patterns-input-preview-button",
|
||||
);
|
||||
@@ -212,7 +224,12 @@ class Client {
|
||||
patternButton.style.display = "none";
|
||||
}
|
||||
|
||||
this.patternsModal instanceof TerritoryPatternsModal;
|
||||
if (
|
||||
!this.patternsModal ||
|
||||
!(this.patternsModal instanceof TerritoryPatternsModal)
|
||||
) {
|
||||
console.warn("Territory patterns modal element not found");
|
||||
}
|
||||
if (patternButton === null)
|
||||
throw new Error("territory-patterns-input-preview-button");
|
||||
this.patternsModal.previewButton = patternButton;
|
||||
@@ -224,7 +241,12 @@ class Client {
|
||||
this.tokenLoginModal = document.querySelector(
|
||||
"token-login",
|
||||
) as TokenLoginModal;
|
||||
this.tokenLoginModal instanceof TokenLoginModal;
|
||||
if (
|
||||
!this.tokenLoginModal ||
|
||||
!(this.tokenLoginModal instanceof TokenLoginModal)
|
||||
) {
|
||||
console.warn("Token login modal element not found");
|
||||
}
|
||||
|
||||
const onUserMe = async (userMeResponse: UserMeResponse | false) => {
|
||||
document.dispatchEvent(
|
||||
@@ -335,7 +357,9 @@ class Client {
|
||||
const settingsModal = document.querySelector(
|
||||
"user-setting",
|
||||
) as UserSettingModal;
|
||||
settingsModal instanceof UserSettingModal;
|
||||
if (!settingsModal || !(settingsModal instanceof UserSettingModal)) {
|
||||
console.warn("User settings modal element not found");
|
||||
}
|
||||
document
|
||||
.getElementById("settings-button")
|
||||
?.addEventListener("click", () => {
|
||||
@@ -345,7 +369,9 @@ class Client {
|
||||
const hostModal = document.querySelector(
|
||||
"host-lobby-modal",
|
||||
) as HostPrivateLobbyModal;
|
||||
hostModal instanceof HostPrivateLobbyModal;
|
||||
if (!hostModal || !(hostModal instanceof HostPrivateLobbyModal)) {
|
||||
console.warn("Host private lobby modal element not found");
|
||||
}
|
||||
const hostLobbyButton = document.getElementById("host-lobby-button");
|
||||
if (hostLobbyButton === null) throw new Error("Missing host-lobby-button");
|
||||
hostLobbyButton.addEventListener("click", () => {
|
||||
@@ -358,7 +384,9 @@ class Client {
|
||||
this.joinModal = document.querySelector(
|
||||
"join-private-lobby-modal",
|
||||
) as JoinPrivateLobbyModal;
|
||||
this.joinModal instanceof JoinPrivateLobbyModal;
|
||||
if (!this.joinModal || !(this.joinModal instanceof JoinPrivateLobbyModal)) {
|
||||
console.warn("Join private lobby modal element not found");
|
||||
}
|
||||
const joinPrivateLobbyButton = document.getElementById(
|
||||
"join-private-lobby-button",
|
||||
);
|
||||
@@ -573,8 +601,9 @@ class Client {
|
||||
const startingModal = document.querySelector(
|
||||
"game-starting-modal",
|
||||
) as GameStartingModal;
|
||||
startingModal instanceof GameStartingModal;
|
||||
startingModal.show();
|
||||
if (startingModal && startingModal instanceof GameStartingModal) {
|
||||
startingModal.show();
|
||||
}
|
||||
},
|
||||
() => {
|
||||
this.joinModal.close();
|
||||
|
||||
@@ -1051,7 +1051,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
? this.renderButton({
|
||||
content: this.getEventDescription(event),
|
||||
onClick: () => {
|
||||
event.focusID &&
|
||||
if (event.focusID)
|
||||
this.emitGoToPlayerEvent(event.focusID);
|
||||
},
|
||||
className: "text-left",
|
||||
@@ -1060,7 +1060,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
? this.renderButton({
|
||||
content: this.getEventDescription(event),
|
||||
onClick: () => {
|
||||
event.unitView &&
|
||||
if (event.unitView)
|
||||
this.emitGoToUnitEvent(
|
||||
event.unitView,
|
||||
);
|
||||
|
||||
@@ -255,7 +255,9 @@ export class StructureIconsLayer implements Layer {
|
||||
this.potentialUpgrade.iconContainer.filters = [];
|
||||
this.potentialUpgrade.dotContainer.filters = [];
|
||||
}
|
||||
this.ghostUnit?.container && (this.ghostUnit.container.filters = []);
|
||||
if (this.ghostUnit?.container) {
|
||||
this.ghostUnit.container.filters = [];
|
||||
}
|
||||
|
||||
if (!this.ghostUnit) return;
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ export class RailroadExecution implements Execution {
|
||||
}
|
||||
|
||||
private redrawBuildings() {
|
||||
this.railRoad.from.unit.isActive() && this.railRoad.from.unit.touch();
|
||||
this.railRoad.to.unit.isActive() && this.railRoad.to.unit.touch();
|
||||
if (this.railRoad.from.unit.isActive()) this.railRoad.from.unit.touch();
|
||||
if (this.railRoad.to.unit.isActive()) this.railRoad.to.unit.touch();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user