Enable @typescript eslint/prefer nullish coalescing eslint rule (#1420)

## Description:

Fixes #952 
Enabled @typescript-eslint/prefer-nullish-coalescing rule and worked
through every error, introducing ?? and ??= operators or disabling
errors with inline comments where appropriate, to the best of my
ability.

## 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
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

g_santos_m
This commit is contained in:
g-santos-m
2025-07-15 05:00:06 +02:00
committed by GitHub
parent ac9a9ec253
commit 31381f67f4
28 changed files with 95 additions and 85 deletions
+3 -5
View File
@@ -97,11 +97,9 @@ export class AttackExecution implements Execution {
}
}
if (this.startTroops === null) {
this.startTroops = this.mg
.config()
.attackAmount(this._owner, this.target);
}
this.startTroops ??= this.mg
.config()
.attackAmount(this._owner, this.target);
if (this.removeTroops) {
this.startTroops = Math.min(this._owner.troops(), this.startTroops);
this._owner.removeTroops(this.startTroops);
+1 -3
View File
@@ -19,9 +19,7 @@ export class DonateGoldExecution implements Execution {
}
this.recipient = mg.player(this.recipientID);
if (this.gold === null) {
this.gold = this.sender.gold() / 3n;
}
this.gold ??= this.sender.gold() / 3n;
}
tick(ticks: number): void {
+1 -3
View File
@@ -19,9 +19,7 @@ export class DonateTroopsExecution implements Execution {
}
this.recipient = mg.player(this.recipientID);
if (this.troops === null) {
this.troops = mg.config().defaultDonationAmount(this.sender);
}
this.troops ??= mg.config().defaultDonationAmount(this.sender);
const maxDonation =
mg.config().maxPopulation(this.recipient) - this.recipient.population();
this.troops = Math.min(this.troops, maxDonation);
+1 -3
View File
@@ -109,9 +109,7 @@ export class SAMLauncherExecution implements Execution {
this.player = this.sam.owner();
}
if (this.pseudoRandom === undefined) {
this.pseudoRandom = new PseudoRandom(this.sam.id());
}
this.pseudoRandom ??= new PseudoRandom(this.sam.id());
const mirvWarheadTargets = this.mg.nearbyUnits(
this.sam.tile(),
+5 -7
View File
@@ -31,13 +31,11 @@ export class SAMMissileExecution implements Execution {
}
tick(ticks: number): void {
if (this.SAMMissile === undefined) {
this.SAMMissile = this._owner.buildUnit(
UnitType.SAMMissile,
this.spawn,
{},
);
}
this.SAMMissile ??= this._owner.buildUnit(
UnitType.SAMMissile,
this.spawn,
{},
);
if (!this.SAMMissile.isActive()) {
this.active = false;
return;
+1 -3
View File
@@ -23,9 +23,7 @@ export class ShellExecution implements Execution {
}
tick(ticks: number): void {
if (this.shell === undefined) {
this.shell = this._owner.buildUnit(UnitType.Shell, this.spawn, {});
}
this.shell ??= this._owner.buildUnit(UnitType.Shell, this.spawn, {});
if (!this.shell.isActive()) {
this.active = false;
return;
+3 -5
View File
@@ -89,11 +89,9 @@ export class TransportShipExecution implements Execution {
this.target = mg.player(this.targetID);
}
if (this.troops === null) {
this.troops = this.mg
.config()
.boatAttackAmount(this.attacker, this.target);
}
this.troops ??= this.mg
.config()
.boatAttackAmount(this.attacker, this.target);
this.troops = Math.min(this.troops, this.attacker.troops());