Skip to content

Commit

Permalink
Fix some eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Aug 13, 2024
1 parent ce2c9f4 commit 2116453
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = {
'prefer-const': 'off',
'no-case-declarations': 'off',
'no-async-promise-executor': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',

// Use tabs for indentation and require 'case' in switch to be indented 1 level (default 0)
indent: ['error', 'tab', {SwitchCase: 1}],
Expand All @@ -37,11 +40,11 @@ module.exports = {
// Require spaces before and after keywords (like "if")
'keyword-spacing': 'error',
// Don't allow unused variables, but allow unused function args (e.g. in callbacks) and global vars
'no-unused-vars': ['error', {vars: 'local', args: 'none', varsIgnorePattern: '^_'}],
'@typescript-eslint/no-unused-vars': ['error', {vars: 'local', args: 'none', varsIgnorePattern: '^_'}],
// Require using dot notation (obj.prop instead of obj['prop']) where possible
'dot-notation': 'error',
// Don't use spaces before parens in anonymous or named functions
'space-before-function-paren': ['error', {anonymous: 'never', named: 'never', asyncArrow: 'always'}]
'space-before-function-paren': ['error', {anonymous: 'never', named: 'never', asyncArrow: 'always'}],

// We will NOT be using eqeqeq for a few reasons:
// 1. I'm only using ESLint to enforce style, not actual differences in functionality. ==/=== is not merely a style choice.
Expand Down
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/components/00-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import BaseConnection, {CMServer} from './connection_protocols/base';

import type {IncomingMessageQueueItem} from './02-connection';
import type {OptionsObject} from '../resources/default_options';
import type {CMsgClientLogon} from '../protobuf-generated/types';
import type FileManager from '../types/FileManager';
import type {HttpClient} from '@doctormckay/stdlib/http';
import type {SteamUserEvents} from '../types/events';
import {InternalLogOnDetails} from '../types/logon';
import type {InternalLogOnDetails} from '../types/logon';
import type {MessageCallback} from './03-messages';

/**
* I admit, this is a pretty unorthodox pattern, but this is the only way I've found to define a class across multiple
Expand Down Expand Up @@ -49,7 +49,7 @@ abstract class SteamUserBase extends TypedEmitter<SteamUserEvents> {
_httpClient: HttpClient|null = null;

_currentJobID: number = 0;
_jobs: TTLCache<Function>;
_jobs: TTLCache<MessageCallback>;

// Timers
_changelistUpdateTimer: NodeJS.Timeout|null = null;
Expand All @@ -62,7 +62,7 @@ abstract class SteamUserBase extends TypedEmitter<SteamUserEvents> {
super();

this._ttlCache = new TTLCache<any>(1000 * 60 * 5); // default 5 minutes
this._jobs = new TTLCache<Function>(1000 * 60 * 2); // default 2 minutes
this._jobs = new TTLCache<MessageCallback>(1000 * 60 * 2); // default 2 minutes
}

_warn(message: string) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/03-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {CMsgClientLogonResponse, CMsgMulti, CMsgProtoBufHeader} from '../protobu
import BaseConnection from './connection_protocols/base';

type FreeFormObject = {[name: string]: any};
type MessageCallback = (body: FreeFormObject|ByteBuffer, header: MessageHeader, callback?: MessageCallback) => void;
export type MessageCallback = (body: FreeFormObject|ByteBuffer, header: MessageHeader, callback?: MessageCallback) => void;

interface MessageHeader {
msg: number;
Expand Down Expand Up @@ -524,6 +524,7 @@ abstract class SteamUserMessages extends SteamUserConnection {

if (this._useMessageQueue && !multiId) {
// Multi sub-messages skip the queue because we need messages contained in a decoded multi to be processed first
// eslint-disable-next-line
this._incomingMessageQueue.push(Array.prototype.slice.call(arguments) as IncomingMessageQueueItem);
this.emit('debug', `Enqueued incoming message; queue size is now ${this._incomingMessageQueue.length}`);
return;
Expand Down Expand Up @@ -725,7 +726,7 @@ abstract class SteamUserMessages extends SteamUserConnection {
// Continue to pop items from the message queue until it's empty, or it gets re-enabled. If the message queue gets
// re-enabled, immediately stop popping items from it to avoid stuff getting out of order.
while (this._incomingMessageQueue.length > 0 && !this._useMessageQueue) {
this._handleNetMessage.apply(this, this._incomingMessageQueue.shift());
this._handleNetMessage(...this._incomingMessageQueue.shift());
}

if (this._incomingMessageQueue.length > 0) {
Expand Down
10 changes: 6 additions & 4 deletions src/components/04-utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ abstract class SteamUserUtility extends SteamUserMessages {
* Same as emit() except the second argument (the first provided to the callback function) is a SteamID and will be appended to the event name with a hash.
* @protected
*/
_emitIdEvent() {
this.emit.apply(this, arguments);
arguments[0] += '#' + arguments[1].getSteamID64();
this.emit.apply(this, arguments);
_emitIdEvent(...args: any[]): void {
// @ts-ignore
this.emit(...args);
args[0] += '#' + args[1].getSteamID64();
// @ts-ignore
this.emit(...args);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/connection_protocols/tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class TCPConnection extends BaseConnection {
if (andIgnore) {
this.removeAllListeners();
this.stream.removeAllListeners();
this.stream.on('error', () => {
});
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.stream.on('error', () => {});
}

this.stream.end();
Expand Down
8 changes: 4 additions & 4 deletions src/components/connection_protocols/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class WebSocketConnection extends BaseConnection {

if (andIgnore) {
this.stream.removeAllListeners();
this.stream.on('error', () => {
});
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.stream.on('error', () => {});
}

this.stream.disconnect();
Expand Down Expand Up @@ -186,8 +186,8 @@ class WebSocketConnection extends BaseConnection {

let latency = Date.now() - start;

res.on('data', () => {
}); // there is no body, so just throw it away
// eslint-disable-next-line @typescript-eslint/no-empty-function
res.on('data', () => {}); // there is no body, so just throw it away

if (res.statusCode != 200) {
// CM is disqualified
Expand Down
4 changes: 4 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {ErrorWithEResult} from './errors';

export interface SteamUserEvents {
debug: (...args: any[]) => void;
'debug-verbose': (...args: any[]) => void;
'debug-traffic-outgoing': (...args: any[]) => void;
'debug-traffic-incoming': (...args: any[]) => void;

error: (err: ErrorWithEResult) => void;
webSession: (sessionID: string, cookies: string[]) => void;
machineAuthToken: (machineToken: string) => void;
Expand Down

0 comments on commit 2116453

Please sign in to comment.