Fix/Improve linting

This commit is contained in:
2026-08-06 08:50:21 +02:00
parent f641ad5f43
commit 06a16c5b64
288 changed files with 3372 additions and 1536 deletions
+6 -3
View File
@@ -177,8 +177,9 @@ export class AdminModel {
return this.liveEvents.finished;
}
initialize(live: boolean) {
if (this.initializedLive)
if (this.initializedLive) {
return;
}
notification.requestPermission();
@@ -545,8 +546,9 @@ export class AdminModel {
}
private updateStateTimeout: any;
private updateState(): void {
if (!this.running)
if (!this.running) {
return;
}
clearTimeout(this.updateStateTimeout);
@@ -590,7 +592,8 @@ export class AdminModel {
function decodeDate(value: number | undefined, base: string | undefined): Date {
if (value == null || base == null) {
return new Date(0);
} else {
}
else {
const d = new Date(base);
d.setTime(d.getTime() + value);
return d;
+19 -11
View File
@@ -76,7 +76,8 @@ function fadeOut(track: Track, id: number, volume: number) {
howl
.fade(volume, 0, 1000, id)
.once('fade', () => howl.pause(id).stop(id), id);
} else {
}
else {
howl
.volume(0, id)
.pause(id)
@@ -124,7 +125,8 @@ export class Audio {
if (this.playing) {
if (this.instance) {
this.setInstanceVolume(this.instance, this.volume);
} else if (this.volume) {
}
else if (this.volume) {
this.playRandomTrack();
}
}
@@ -137,12 +139,14 @@ export class Audio {
if (this.volume) {
if (this.instance) {
this.resumeInstance(this.instance);
} else {
}
else {
this.playRandomTrack();
}
}
}
} catch (e) {
}
catch (e) {
console.error(e);
}
}
@@ -150,10 +154,12 @@ export class Audio {
if (FADE_TRACKS) {
if (this.playing && this.volume) {
this.playRandomTrack();
} else {
}
else {
this.play();
}
} else {
}
else {
this.play();
}
}
@@ -175,15 +181,15 @@ export class Audio {
private switchToTrack(track: Track) {
if (this.instance && this.instance.track === track) {
return false;
} else {
}
else {
this.stopInstance(this.instance);
this.instance = this.playTrack(track);
return true;
}
}
playRandomTrack() {
while (!this.switchToTrack(sample(this.tracks)!))
;
while (!this.switchToTrack(sample(this.tracks)!)) {}
this.loops = random(4, 7);
}
@@ -215,7 +221,8 @@ export class Audio {
if (volume && !howl.playing(instance.id)) {
howl.play(instance.id);
} else if (!volume && howl.playing(instance.id)) {
}
else if (!volume && howl.playing(instance.id)) {
howl.pause(instance.id);
}
}
@@ -243,7 +250,8 @@ export class Audio {
if (this.volume && this.playing) {
this.playRandomTrack();
} else {
}
else {
this.stopInstance(this.instance);
}
}
+2 -1
View File
@@ -13,7 +13,8 @@ export class AuthGuard implements CanActivate {
.then(account => {
if (account) {
return true;
} else {
}
else {
this.router.navigate(['/']);
return false;
}
+14 -7
View File
@@ -14,7 +14,7 @@ import { meetsRequirement } from '../../common/accountUtils';
import { isLanguage, isFocused, sortServersForRussian } from '../../client/clientUtils';
import { StorageService } from './storageService';
export interface ClientSocketService extends SocketService<ClientActions, IServerActions> { }
export type ClientSocketService = SocketService<ClientActions, IServerActions>;
function createSocket(
gameService: GameService, game: PonyTownGame, model: Model, zone: NgZone, options: ClientOptions,
@@ -183,7 +183,8 @@ export class GameService {
if (reason === LeaveReason.Swearing) {
this.leftMessage = 'Kicked for swearing or inappropriate language';
this.locked = true;
} else {
}
else {
this.leftMessage = undefined;
}
@@ -233,11 +234,14 @@ export class GameService {
private getAndUpdateStatus(account: AccountData | undefined) {
if (this.joining || this.playing || !account || !isFocused()) {
return Promise.resolve();
} else {
}
else {
return this.model.status(this.initialized)
.then(status => this.updateStatus(account, status))
.catch((e: RequestError) => {
DEVELOPMENT && console.error(e);
if (DEVELOPMENT) {
console.error(e);
}
this.offline = e.message === OFFLINE_ERROR;
this.versionError = e.message === VERSION_ERROR;
this.protectionError = e.message === PROTECTION_ERROR;
@@ -255,14 +259,16 @@ export class GameService {
if (existing) {
merge(existing, server);
} else if ('name' in server) {
}
else if ('name' in server) {
const info = server as ServerInfo;
info.countryFlags = info.flag && /^[a-z]{2}( [a-z]{2})*$/.test(info.flag) ? info.flag.split(/ /g) : [];
if (info.name && account && meetsRequirement(account, info.require)) {
this.servers.push(info);
}
} else {
}
else {
// got new server on the list
this.initialized = false;
}
@@ -302,7 +308,8 @@ export class GameService {
if (socket.isConnected) {
clearInterval(interval);
this.zone.run(resolve);
} else if (!this.joining) {
}
else if (!this.joining) {
clearInterval(interval);
this.zone.run(() => reject(new Error('Cancelled (poll)')));
}
@@ -35,7 +35,8 @@ export class IntervalUpdateService {
return (on: boolean) => {
if (on && !unsubscribe) {
unsubscribe = this.subscribe(action);
} else if (!on && unsubscribe) {
}
else if (!on && unsubscribe) {
unsubscribe();
unsubscribe = undefined;
}
+8 -4
View File
@@ -51,7 +51,8 @@ export class LiveCollection<T extends Document> {
if (removeFromList || this.options.deleteItems) {
removeItem(this.items, item);
this.itemsMap.delete(key);
} else if (deleted) {
}
else if (deleted) {
item.deleted = true;
}
@@ -64,8 +65,9 @@ export class LiveCollection<T extends Document> {
return this.server.assignAccount(this.name, id, account);
}
live(): Promise<void> {
if (!this.running)
if (!this.running) {
return Promise.resolve();
}
clearTimeout(this.liveTimeout);
@@ -129,11 +131,13 @@ export class LiveCollection<T extends Document> {
if (doc) {
if (this.options.onUpdate) {
this.options.onUpdate(doc, update);
} else {
}
else {
Object.assign(doc, update);
}
all.push(doc);
} else if (!liveFetch || !this.options.ignore || !this.options.ignore(update)) {
}
else if (!liveFetch || !this.options.ignore || !this.options.ignore(update)) {
this.push(update);
added.push(update);
all.push(update);
+32 -15
View File
@@ -78,7 +78,8 @@ export function getPonyTag(pony: PonyObject, account: AccountData | undefined) {
if (account) {
const tag = canUseTag(account, pony.tag || '') ? pony.tag : undefined;
return (!tag && account.supporter && !pony.hideSupport) ? `sup${account.supporter}` : tag;
} else {
}
else {
return undefined;
}
}
@@ -179,7 +180,8 @@ export class Model {
modStatus.mod = isMod(account);
modStatus.check = account.check;
modStatus.editor = account.editor || modStatus.editor;
} catch { }
}
catch { }
if (modStatus.editor) {
modStatus.editor.typeToName.forEach(({ type, name }) => entityTypeToName.set(type, name));
@@ -208,18 +210,22 @@ export class Model {
if (e.message === ACCESS_ERROR) {
this.loading = false;
this.storage.setItem('vid', '---');
} else if (e.message === LIMIT_ERROR) {
}
else if (e.message === LIMIT_ERROR) {
this.loadingError = 'request-limit';
return delay(5000).then(() => this.initializeAccount());
} else if (e.message === OFFLINE_ERROR) {
}
else if (e.message === OFFLINE_ERROR) {
this.loadingError = 'cannot-connect';
return delay(5000).then(() => this.initializeAccount());
} else if (e.message === PROTECTION_ERROR) {
}
else if (e.message === PROTECTION_ERROR) {
this.loadingError = 'cloudflare-error';
this.protectionErrors.next();
// } else if (e.message === VERSION_ERROR) {
// this.updating = true;
} else {
}
else {
setTimeout(() => this.loadingError = 'unexpected-error', 5 * SECOND);
console.error(e);
}
@@ -240,7 +246,9 @@ export class Model {
})).sort(compareFriends);
})
.catch(e => {
DEVELOPMENT && console.error(e);
if (DEVELOPMENT) {
console.error(e);
}
setTimeout(() => this.fetchFriends(), 5000);
});
}
@@ -275,7 +283,8 @@ export class Model {
try {
const ponyInfo = decompressPonyString(pony.info, true);
return { ponyInfo, ...pony };
} catch (e) {
}
catch (e) {
this.errorReporter.reportError(e, { ponyInfo: pony.info });
this.errorReporter.reportError('Pony info reading error', { originalError: isErrorAlike(e) ? e.message: '', ponyInfo: pony.info });
throw new Error('Error while reading pony info');
@@ -283,7 +292,9 @@ export class Model {
}
selectPony(pony: PonyObject) {
const copy = this.parsePonyObject(pony);
copy.ponyInfo && syncLockedPonyInfo(copy.ponyInfo);
if (copy.ponyInfo) {
syncLockedPonyInfo(copy.ponyInfo);
}
this._pony = copy;
}
// account
@@ -308,7 +319,8 @@ export class Model {
if (isStandalone()) {
window.open(url);
} else {
}
else {
location.href = url;
}
}
@@ -394,7 +406,8 @@ export class Model {
if (pony.id) {
removeById(this.ponies, pony.id);
} else {
}
else {
this.account!.characterCount++;
}
@@ -443,7 +456,8 @@ export class Model {
if (this.account.birthyear) {
age = currentYear - this.account.birthyear;
} else if (this.account.birthdate) {
}
else if (this.account.birthdate) {
const [year, month] = this.account.birthdate.split('-');
const before = parseInt(month, 10) > currentMonth;
age = Math.max(0, currentYear - parseInt(year, 10) - (before ? 1 : 0));
@@ -458,12 +472,15 @@ export class Model {
return observableToPromise(this.http.get<GameStatus>('/api2/game/status', { params }));
}
join(serverId: string, ponyId: string): Promise<JoinResponse> {
if (this.pending)
if (this.pending) {
return Promise.reject(new Error('Joining in progress'));
if (!serverId)
}
if (!serverId) {
return Promise.reject(new Error('Invalid server ID'));
if (!ponyId)
}
if (!ponyId) {
return Promise.reject(new Error('Invalid pony ID'));
}
this.pending = true;
@@ -60,7 +60,8 @@ export class ModelSubscriber<T> {
if (subscription.value !== undefined) {
callback(subscription.value);
}
} else {
}
else {
this.socket.server.subscribe(this.type, id);
this.subscriptions.set(id, {
value: this.defaultValue,
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import { ErrorHandler, Injectable, Injector, InjectionToken } from '@angular/core';
import Rollbar from 'rollbar';
import { version } from '../../client/data';
@@ -34,7 +35,8 @@ export const RollbarService = new InjectionToken<Rollbar>('rollbar');
export function rollbarFactory() {
if (DEVELOPMENT) {
return undefined;
} else {
}
else {
const rollbar = Rollbar.init(rollbarConfig);
rollbar.configure({ checkIgnore: rollbarCheckIgnore });
return rollbar;
@@ -25,7 +25,9 @@ export class RollbarErrorReporter extends ErrorReporter {
}
}
reportError(error: any, data?: any) {
DEVELOPMENT && console.error(error, data);
if (DEVELOPMENT) {
console.error(error, data);
}
if (this.rollbar && !isIgnoredError(error)) {
this.rollbar.error(error, data);
@@ -32,7 +32,8 @@ export class SettingsService {
if (this.save(settings)) {
return Promise.resolve();
} else {
}
else {
return this.model.saveSettings(settings);
}
}
+20 -10
View File
@@ -9,18 +9,21 @@ export class StorageService {
if (typeof localStorage === 'undefined') {
this.data = new Map();
}
} catch {
}
catch {
this.data = new Map();
}
}
getItem(key: string) {
if (this.data) {
return this.data.get(key);
} else {
}
else {
try {
const value = localStorage.getItem(key);
return value == null ? undefined : value;
} catch {
}
catch {
return undefined;
}
}
@@ -29,7 +32,8 @@ export class StorageService {
try {
localStorage.setItem(key, data);
this.data = undefined;
} catch {
}
catch {
if (!this.data) {
this.data = new Map();
}
@@ -40,25 +44,30 @@ export class StorageService {
removeItem(key: string) {
if (this.data) {
this.data.delete(key);
} else {
}
else {
try {
localStorage.removeItem(key);
} catch { }
}
catch { }
}
}
clear() {
if (this.data) {
this.data.clear();
} else {
}
else {
try {
localStorage.clear();
} catch { }
}
catch { }
}
}
getJSON<T>(key: string, defaultValue: T): T {
try {
return JSON.parse(this.getItem(key) || '');
} catch {
}
catch {
return defaultValue;
}
}
@@ -77,7 +86,8 @@ export class StorageService {
setBoolean(key: string, value: boolean) {
if (value) {
this.setItem(key, 'true');
} else {
}
else {
this.removeItem(key);
}
}