Skip to content

Commit

Permalink
refactor: fix explicit type declarations
Browse files Browse the repository at this point in the history
Explicit types where they can be easily inferred may add unnecessary verbosity for variables or parameters initialized to a number, string, or boolean
  • Loading branch information
deepsource-autofix[bot] authored Apr 2, 2024
1 parent b63a555 commit 861e7e1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions tools/shared-packets/src/GameMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { ISerializable, IMessage } from "./interfaces.js";
*/
export class GameMessageHeader extends Serializable implements ISerializable {
// Version 0: 4 bytes
private id: number = 0; // 2 bytes
private length: number = 0; // 2 bytes
private id = 0; // 2 bytes
private length = 0; // 2 bytes

// Version 1: v0 + 8 bytes
private version: 0 | 257 = 0; // 2 bytes
Expand Down
10 changes: 5 additions & 5 deletions tools/shared-packets/src/ServerMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type { ISerializable, IMessage } from "./interfaces.js";
*/
export class ServerMessageHeader extends Serializable implements ISerializable {
// All fields are little-endian
private length: number = 0; // 2 bytes
private signature: string = ""; // 4 bytes
private sequence: number = 0; // 4 bytes
private flags: number = 0; // 1
private length = 0; // 2 bytes
private signature = ""; // 4 bytes
private sequence = 0; // 4 bytes
private flags = 0; // 1

getDataOffset(): number {
return 11;
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ServerMessagePayload
extends Serializable
implements ISerializable
{
private messageId: number = 0; // 2 bytes
private messageId = 0; // 2 bytes

override getByteSize(): number {
return 2 + this._data.length;
Expand Down
6 changes: 3 additions & 3 deletions tools/shared/src/NetworkMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { SerializedBuffer } from "./SerializedBuffer.js";
*/
export class NetworkMessage extends SerializedBuffer {
private _messageId: number;
version: number = 0x101;
reserved: number = 0x0000;
private _checksum: number = 0x00000000;
version = 0x101;
reserved = 0x0000;
private _checksum = 0x00000000;
constructor(messageId: number, data?: Buffer) {
super(data);
this._messageId = messageId;
Expand Down
6 changes: 3 additions & 3 deletions tools/shared/src/ServerMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class HeaderShim {
*/
export class ServerMessage extends SerializedBuffer {
private _signature = "TOMC";
private _sequence: number = 0;
private _flags: number = 0;
private _sequence = 0;
private _flags = 0;
_header: HeaderShim;

constructor(sequence: number = 0, flags: number = 0, data?: Buffer) {
constructor(sequence = 0, flags = 0, data?: Buffer) {
super();
this._sequence = sequence;
this._flags = flags;
Expand Down
30 changes: 15 additions & 15 deletions tools/transactions/src/messageHandlers/_getCompleteVehicleInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const log = getServerLogger();
const DAMAGE_SIZE = 2000;

export class VehicleStruct {
VehicleID: number = 0; // 4 bytes
SkinID: number = 0; // 4 bytes
Flags: number = 0; // 4 bytes
Delta: number = 0; // 4 bytes
CarClass: number = 0; // 1 byte
VehicleID = 0; // 4 bytes
SkinID = 0; // 4 bytes
Flags = 0; // 4 bytes
Delta = 0; // 4 bytes
CarClass = 0; // 1 byte
Damage: Buffer = Buffer.alloc(DAMAGE_SIZE); // buffer, max DAMAGE_SIZE

serialize() {
Expand Down Expand Up @@ -56,14 +56,14 @@ export class VehicleStruct {
}

export class PartStruct {
partId: number = 0; // 4 bytes
partId = 0; // 4 bytes
parentPartId: number | null = 0; // 4 bytes
brandedPartId: number = 0; // 4 bytes
repairCost: number = 0; // 4 bytes
junkyardValue: number = 0; // 4 bytes
wear: number = 0; // 4 bytes
arttachmentPoint: number = 0; // 1 byte
damage: number = 0; // 1 byte
brandedPartId = 0; // 4 bytes
repairCost = 0; // 4 bytes
junkyardValue = 0; // 4 bytes
wear = 0; // 4 bytes
arttachmentPoint = 0; // 1 byte
damage = 0; // 1 byte

serialize() {
try {
Expand Down Expand Up @@ -101,10 +101,10 @@ export class PartStruct {
}

class CarInfoStruct {
msgNo: number = 0; // 2 bytes
playerId: number = 0; // 4 bytes
msgNo = 0; // 2 bytes
playerId = 0; // 4 bytes
vehicle: VehicleStruct = new VehicleStruct();
noOfParts: number = 0; // 2 bytes
noOfParts = 0; // 2 bytes
parts: PartStruct[] = [];

serialize() {
Expand Down

0 comments on commit 861e7e1

Please sign in to comment.