mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Enable eslint rule 'no-sparse-arrays'
Enable recommended rule 'no-sparse-arrays' [1] and manually fix violations. Solution proposed by elexis. [1] https://eslint.org/docs/latest/rules/no-sparse-arrays Fixes: #8068 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
parent
9a4708cb71
commit
b382a4c47a
2 changed files with 10 additions and 7 deletions
|
|
@ -8,6 +8,8 @@ const CAPTYPE_PLAYER_POPULATION = "player";
|
|||
const CAPTYPE_TEAM_POPULATION = "team";
|
||||
const CAPTYPE_WORLD_POPULATION = "world";
|
||||
|
||||
const DEFAULT_POPCAP = 999;
|
||||
|
||||
const cmpPopulationCapManager = ConstructComponent(SYSTEM_ENTITY, "PopulationCapManager");
|
||||
const playerData = [
|
||||
{
|
||||
|
|
@ -48,7 +50,7 @@ const playerData = [
|
|||
}
|
||||
];
|
||||
|
||||
const currentPopCaps = [];
|
||||
const currentPopCaps = Object.keys(playerData).fill(DEFAULT_POPCAP);
|
||||
|
||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
|
||||
"GetNonGaiaPlayers": () => { return Object.keys(playerData).slice(1); },
|
||||
|
|
@ -68,24 +70,24 @@ for (const playerID in Object.keys(playerData))
|
|||
|
||||
cmpPopulationCapManager.SetPopulationCap(400);
|
||||
cmpPopulationCapManager.SetPopulationCapType(CAPTYPE_PLAYER_POPULATION);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 400, 400, 400, 400, 400, 400, 400, 400]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 400, 400, 400, 400, 400, 400, 400, 400]);
|
||||
|
||||
cmpPopulationCapManager.SetPopulationCapType(CAPTYPE_TEAM_POPULATION);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 400, 400, 400, 133, 133, 133, 200, 200]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 400, 400, 400, 133, 133, 133, 200, 200]);
|
||||
|
||||
playerData[6].team = 2;
|
||||
cmpPopulationCapManager.OnTeamChanged({ "player": 6, "oldTeam": 1, "newTeam": 2 });
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 400, 400, 400, 200, 200, 133, 133, 133]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 400, 400, 400, 200, 200, 133, 133, 133]);
|
||||
|
||||
playerData[8].state = "defeated";
|
||||
currentPopCaps.pop();
|
||||
cmpPopulationCapManager.OnGlobalPlayerDefeated({ "playerId": 8 });
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 400, 400, 400, 200, 200, 200, 200]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 400, 400, 400, 200, 200, 200, 200]);
|
||||
|
||||
cmpPopulationCapManager.SetPopulationCapType(CAPTYPE_WORLD_POPULATION);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 57, 57, 57, 57, 57, 57, 57]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 57, 57, 57, 57, 57, 57, 57]);
|
||||
|
||||
playerData[7].state = "defeated";
|
||||
currentPopCaps.pop();
|
||||
cmpPopulationCapManager.OnGlobalPlayerDefeated({ "playerId": 7 });
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [, 67, 67, 67, 67, 67, 67]);
|
||||
TS_ASSERT_UNEVAL_EQUALS(currentPopCaps, [DEFAULT_POPCAP, 67, 67, 67, 67, 67, 67]);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ const configEslintRecommended = {
|
|||
"no-self-assign": "warn",
|
||||
"no-setter-return": "warn",
|
||||
"no-shadow-restricted-names": "warn",
|
||||
"no-sparse-arrays": "warn",
|
||||
"no-this-before-super": "warn",
|
||||
/* "no-undef": "warn", */
|
||||
"no-unexpected-multiline": "warn",
|
||||
|
|
|
|||
Loading…
Reference in a new issue