Skip to content

Commit

Permalink
Enforce Consistent Spacing with ESLint's space-before-blocks and keyw…
Browse files Browse the repository at this point in the history
…ord-spacing Rules (pagefaultgames#1308)

* added rule no-trailing-spaces

* added rule space-before-block

* added rule keyword spacing
  • Loading branch information
Greenlamp2 authored May 24, 2024
1 parent e2be6ba commit 6228857
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"no-trailing-spaces": ["error", { // Disallows trailing whitespace at the end of lines
"skipBlankLines": false, // Enforces the rule even on blank lines
"ignoreComments": false // Enforces the rule on lines containing comments
}]
}],
"space-before-blocks": ["error", "always"], // Enforces a space before blocks
"keyword-spacing": ["error", { "before": true, "after": true }] // Enforces spacing before and after keywords
}
}
]
Expand Down
24 changes: 12 additions & 12 deletions src/data/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class PreDefendFullHpEndureAbAttr extends PreDefendAbAttr {
applyPreDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, cancelled: Utils.BooleanHolder, args: any[]): boolean {
if (pokemon.hp === pokemon.getMaxHp() &&
pokemon.getMaxHp() > 1 && //Checks if pokemon has wonder_guard (which forces 1hp)
(args[0] as Utils.NumberHolder).value >= pokemon.hp){ //Damage >= hp
(args[0] as Utils.NumberHolder).value >= pokemon.hp) { //Damage >= hp
return pokemon.addTag(BattlerTagType.STURDY, 1);
}

Expand Down Expand Up @@ -499,11 +499,11 @@ export class FieldPriorityMoveImmunityAbAttr extends PreDefendAbAttr {
applyMoveAttrs(IncrementMovePriorityAttr,attacker,null,move.getMove(),attackPriority);
applyAbAttrs(IncrementMovePriorityAbAttr, attacker, null, move.getMove(), attackPriority);

if(move.getMove().moveTarget===MoveTarget.USER) {
if (move.getMove().moveTarget===MoveTarget.USER) {
return false;
}

if(attackPriority.value > 0 && !move.getMove().isMultiTarget()) {
if (attackPriority.value > 0 && !move.getMove().isMultiTarget()) {
cancelled.value = true;
return true;
}
Expand Down Expand Up @@ -955,7 +955,7 @@ export class MoveTypeChangePowerMultiplierAbAttr extends VariableMoveTypeAbAttr
private newType: Type;
private powerMultiplier: number;

constructor(matchType: Type, newType: Type, powerMultiplier: number){
constructor(matchType: Type, newType: Type, powerMultiplier: number) {
super(true);
this.matchType = matchType;
this.newType = newType;
Expand Down Expand Up @@ -986,7 +986,7 @@ export class MoveTypeChangeAttr extends PreAttackAbAttr {
private powerMultiplier: number;
private condition: PokemonAttackCondition;

constructor(newType: Type, powerMultiplier: number, condition: PokemonAttackCondition){
constructor(newType: Type, powerMultiplier: number, condition: PokemonAttackCondition) {
super(true);
this.newType = newType;
this.powerMultiplier = powerMultiplier;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ export class DamageBoostAbAttr extends PreAttackAbAttr {
private damageMultiplier: number;
private condition: PokemonAttackCondition;

constructor(damageMultiplier: number, condition: PokemonAttackCondition){
constructor(damageMultiplier: number, condition: PokemonAttackCondition) {
super(true);
this.damageMultiplier = damageMultiplier;
this.condition = condition;
Expand Down Expand Up @@ -1860,7 +1860,7 @@ export class MultCritAbAttr extends AbAttr {

apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean {
const critMult = args[0] as Utils.NumberHolder;
if (critMult.value > 1){
if (critMult.value > 1) {
critMult.value *= this.multAmount;
return true;
}
Expand Down Expand Up @@ -1892,7 +1892,7 @@ export class ConditionalCritAbAttr extends AbAttr {
apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean {
const target = (args[1] as Pokemon);
const move = (args[2] as Move);
if(!this.condition(pokemon,target,move)) {
if (!this.condition(pokemon,target,move)) {
return false;
}

Expand Down Expand Up @@ -2410,8 +2410,8 @@ export class PostTurnHurtIfSleepingAbAttr extends PostTurnAbAttr {
*/
applyPostTurn(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise<boolean> {
let hadEffect: boolean = false;
for(const opp of pokemon.getOpponents()) {
if(opp.status !== undefined && opp.status.effect === StatusEffect.SLEEP) {
for (const opp of pokemon.getOpponents()) {
if (opp.status !== undefined && opp.status.effect === StatusEffect.SLEEP) {
opp.damageAndUpdate(Math.floor(Math.max(1, opp.getMaxHp() / 8)), HitResult.OTHER);
pokemon.scene.queueMessage(i18next.t("abilityTriggers:badDreams", {pokemonName: `${getPokemonPrefix(opp)}${opp.name}`}));
hadEffect = true;
Expand Down Expand Up @@ -2440,7 +2440,7 @@ export class FetchBallAbAttr extends PostTurnAbAttr {
*/
applyPostTurn(pokemon: Pokemon, passive: boolean, args: any[]): boolean {
const lastUsed = pokemon.scene.currentBattle.lastUsedPokeball;
if(lastUsed !== null && pokemon.isPlayer) {
if (lastUsed !== null && pokemon.isPlayer) {
pokemon.scene.pokeballCounts[lastUsed]++;
pokemon.scene.currentBattle.lastUsedPokeball = null;
pokemon.scene.queueMessage(getPokemonMessage(pokemon, ` found a\n${getPokeballName(lastUsed)}!`));
Expand Down Expand Up @@ -2575,7 +2575,7 @@ export class ArenaTrapAbAttr extends CheckTrappedAbAttr {
* @returns if enemy Pokemon is trapped or not
*/
applyCheckTrapped(pokemon: Pokemon, passive: boolean, trapped: Utils.BooleanHolder, otherPokemon: Pokemon, args: any[]): boolean {
if (otherPokemon.getTypes().includes(Type.GHOST)){
if (otherPokemon.getTypes().includes(Type.GHOST)) {
trapped.value = false;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export async function printPokemon() {
let generationIndex = 0;

if (!region) {
while (++generationIndex < 9 && dexId > generationDexNumbers[generationIndex]){}
while (++generationIndex < 9 && dexId > generationDexNumbers[generationIndex]) {}
} else {
generationIndex = regionalForms.indexOf(region.toLowerCase()) + 6;
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/battler-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class FlinchedTag extends BattlerTag {
}

export class InterruptedTag extends BattlerTag {
constructor(sourceMove: Moves){
constructor(sourceMove: Moves) {
super(BattlerTagType.INTERRUPTED, BattlerTagLapseType.PRE_MOVE, 0, sourceMove);
}

Expand Down Expand Up @@ -585,7 +585,7 @@ export class MinimizeTag extends BattlerTag {

lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
//If a pokemon dynamaxes they lose minimized status
if(pokemon.isMax()){
if (pokemon.isMax()) {
return false;
}
return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType);
Expand Down
2 changes: 1 addition & 1 deletion src/data/berry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
pokemon.battleData.berriesEaten.push(berryType);
}
const ppRestoreMove = pokemon.getMoveset().find(m => !m.getPpRatio()) ? pokemon.getMoveset().find(m => !m.getPpRatio()) : pokemon.getMoveset().find(m => m.getPpRatio() < 1);
if(ppRestoreMove !== undefined){
if (ppRestoreMove !== undefined) {
ppRestoreMove.ppUsed = Math.max(ppRestoreMove.ppUsed - 10, 0);
pokemon.scene.queueMessage(getPokemonMessage(pokemon, ` restored PP to its move ${ppRestoreMove.getName()}\nusing its ${getBerryName(berryType)}!`));
}
Expand Down
50 changes: 25 additions & 25 deletions src/data/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ export class HalfSacrificialAttr extends MoveEffectAttr {
const cancelled = new Utils.BooleanHolder(false);
// Check to see if the Pokemon has an ability that blocks non-direct damage
applyAbAttrs(BlockNonDirectDamageAbAttr, user, cancelled);
if (!cancelled.value){
if (!cancelled.value) {
user.damageAndUpdate(Math.ceil(user.getMaxHp()/2), HitResult.OTHER, false, true, true);
user.scene.queueMessage(getPokemonMessage(user, " cut its own HP to power up its move!")); // Queue recoil message
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr {
/** The {@linkcode WeatherType} this move ignores */
public weather: WeatherType;

constructor(weather: WeatherType){
constructor(weather: WeatherType) {
super();
this.weather = weather;
}
Expand Down Expand Up @@ -1542,9 +1542,9 @@ export class EatBerryAttr extends MoveEffectAttr {
return false;
}

if(this.chosenBerry === undefined) { // if no berry has been provided, pick a random berry from their inventory
if (this.chosenBerry === undefined) { // if no berry has been provided, pick a random berry from their inventory
const heldBerries = this.getTargetHeldBerries(target);
if(heldBerries.length <= 0) {
if (heldBerries.length <= 0) {
return false;
}
this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)];
Expand All @@ -1555,7 +1555,7 @@ export class EatBerryAttr extends MoveEffectAttr {
const preserve = new Utils.BooleanHolder(false);
target.scene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve);

if (!preserve.value){ // remove the eaten berry if not preserved
if (!preserve.value) { // remove the eaten berry if not preserved
if (!--this.chosenBerry.stackCount) {
target.scene.removeModifier(this.chosenBerry, !target.isPlayer());
}
Expand Down Expand Up @@ -1592,7 +1592,7 @@ export class StealEatBerryAttr extends EatBerryAttr {

const cancelled = new Utils.BooleanHolder(false);
applyAbAttrs(BlockItemTheftAbAttr, target, cancelled); // check for abilities that block item theft
if(cancelled.value === true) {
if (cancelled.value === true) {
return false;
}

Expand Down Expand Up @@ -2012,7 +2012,7 @@ export class PostVictoryStatChangeAttr extends MoveAttr {
this.showMessage = showMessage;
}
applyPostVictory(user: Pokemon, target: Pokemon, move: Move): void {
if(this.condition && !this.condition(user, target, move)) {
if (this.condition && !this.condition(user, target, move)) {
return false;
}
const statChangeAttr = new StatChangeAttr(this.stats, this.levels, this.showMessage);
Expand Down Expand Up @@ -2257,7 +2257,7 @@ export class LessPPMorePowerAttr extends VariablePowerAttr {

let ppRemains = ppMax - ppUsed;
/** Reduce to 0 to avoid negative numbers if user has 1PP before attack and target has Ability.PRESSURE */
if(ppRemains < 0) {
if (ppRemains < 0) {
ppRemains = 0;
}

Expand Down Expand Up @@ -2713,7 +2713,7 @@ export class PresentPowerAttr extends VariablePowerAttr {

export class KnockOffPowerAttr extends VariablePowerAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if(target.getHeldItems().length > 0){
if (target.getHeldItems().length > 0) {
(args[0] as Utils.NumberHolder).value *= 1.5;
return true;
}
Expand Down Expand Up @@ -2744,7 +2744,7 @@ export class VariableAtkAttr extends MoveAttr {
}

export class TargetAtkUserAtkAttr extends VariableAtkAttr {
constructor(){
constructor() {
super();
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
Expand Down Expand Up @@ -2831,7 +2831,7 @@ export class MinimizeAccuracyAttr extends VariableAccuracyAttr {
* @returns true if the function succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (target.getTag(BattlerTagType.MINIMIZED)){
if (target.getTag(BattlerTagType.MINIMIZED)) {
const accuracy = args[0] as Utils.NumberHolder;
accuracy.value = -1;

Expand Down Expand Up @@ -3086,7 +3086,7 @@ export class TerrainPulseTypeAttr extends VariableMoveTypeAttr {
* @returns true if the function succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if(!user.isGrounded) {
if (!user.isGrounded) {
return false;
}

Expand Down Expand Up @@ -3140,7 +3140,7 @@ export class MatchUserTypeAttr extends VariableMoveTypeAttr {

const userTypes = user.getTypes(true);

if(userTypes.includes(Type.STELLAR)) { // will not change to stellar type
if (userTypes.includes(Type.STELLAR)) { // will not change to stellar type
const nonTeraTypes = user.getTypes();
type.value = nonTeraTypes[0];
return true;
Expand Down Expand Up @@ -3594,7 +3594,7 @@ export class ProtectAttr extends AddBattlerTagAttr {

while (moveHistory.length) {
turnMove = moveHistory.shift();
if(!allMoves[turnMove.move].getAttrs(ProtectAttr).length || turnMove.result !== MoveResult.SUCCESS) {
if (!allMoves[turnMove.move].getAttrs(ProtectAttr).length || turnMove.result !== MoveResult.SUCCESS) {
break;
}
timesUsed++;
Expand Down Expand Up @@ -3746,7 +3746,7 @@ export class RemoveArenaTrapAttr extends MoveEffectAttr {
return false;
}

if(this.targetBothSides){
if (this.targetBothSides) {
user.scene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.PLAYER);
user.scene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.PLAYER);
user.scene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.PLAYER);
Expand Down Expand Up @@ -3782,15 +3782,15 @@ export class RemoveScreensAttr extends MoveEffectAttr {
return false;
}

if(this.targetBothSides){
if (this.targetBothSides) {
user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.PLAYER);
user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.PLAYER);
user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.PLAYER);

user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.ENEMY);
user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.ENEMY);
user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.ENEMY);
} else{
} else {
user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
Expand Down Expand Up @@ -3821,13 +3821,13 @@ export class RevivalBlessingAttr extends MoveEffectAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
return new Promise(resolve => {
// If user is player, checks if the user has fainted pokemon
if(user instanceof PlayerPokemon
if (user instanceof PlayerPokemon
&& user.scene.getParty().findIndex(p => p.isFainted())>-1) {
(user as PlayerPokemon).revivalBlessing().then(() => {
resolve(true);
});
// If user is enemy, checks that it is a trainer, and it has fainted non-boss pokemon in party
} else if(user instanceof EnemyPokemon
} else if (user instanceof EnemyPokemon
&& user.hasTrainer()
&& user.scene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) {
// Selects a random fainted pokemon
Expand All @@ -3838,11 +3838,11 @@ export class RevivalBlessingAttr extends MoveEffectAttr {
pokemon.heal(Math.min(Math.max(Math.ceil(Math.floor(0.5 * pokemon.getMaxHp())), 1), pokemon.getMaxHp()));
user.scene.queueMessage(`${pokemon.name} was revived!`,0,true);

if(user.scene.currentBattle.double && user.scene.getEnemyParty().length > 1) {
if (user.scene.currentBattle.double && user.scene.getEnemyParty().length > 1) {
const allyPokemon = user.getAlly();
if(slotIndex<=1) {
if (slotIndex<=1) {
user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, pokemon.getFieldIndex(), slotIndex, false, false, false));
} else if(allyPokemon.isFainted()){
} else if (allyPokemon.isFainted()) {
user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, allyPokemon.getFieldIndex(), slotIndex, false, false,false));
}
}
Expand All @@ -3855,7 +3855,7 @@ export class RevivalBlessingAttr extends MoveEffectAttr {
}

getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
if(user.hasTrainer() && user.scene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) {
if (user.hasTrainer() && user.scene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) {
return 20;
}

Expand Down Expand Up @@ -3994,7 +3994,7 @@ export class RemoveTypeAttr extends MoveEffectAttr {
return false;
}

if(user.isTerastallized && user.getTeraType() === this.removedType) { // active tera types cannot be removed
if (user.isTerastallized && user.getTeraType() === this.removedType) { // active tera types cannot be removed
return false;
}

Expand Down Expand Up @@ -4804,7 +4804,7 @@ export class FirstMoveCondition extends MoveCondition {
export class hitsSameTypeAttr extends VariableMoveTypeMultiplierAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const multiplier = args[0] as Utils.NumberHolder;
if (!user.getTypes().some(type => target.getTypes().includes(type))){
if (!user.getTypes().some(type => target.getTypes().includes(type))) {
multiplier.value = 0;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/nature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export enum Nature {
export function getNatureName(nature: Nature, includeStatEffects: boolean = false, forStarterSelect: boolean = false, ignoreBBCode: boolean = false, uiTheme: UiTheme = UiTheme.DEFAULT): string {
let ret = Utils.toReadableString(Nature[nature]);
//Translating nature
if(i18next.exists("nature:" + ret)){
if (i18next.exists("nature:" + ret)) {
ret = i18next.t("nature:" + ret as any);
}
if (includeStatEffects) {
Expand Down
Loading

0 comments on commit 6228857

Please sign in to comment.