Skip to content

Commit

Permalink
Turn on no-unused-expressions in eslint (foundryvtt#12425)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Dec 21, 2023
1 parent 38a2d46 commit 42d6305
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"allowForLoopAfterthoughts": true
}
],
"no-unused-expressions": [
"error",
{
"allowShortCircuit": true
}
],
"spaced-comment": [
"error",
"always",
Expand Down
14 changes: 4 additions & 10 deletions src/module/actor/character/crafting/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ class CraftingEntry implements Omit<CraftingEntryData, "parentItem"> {

if (this.isAlchemical && index !== -1) {
const formula = this.preparedFormulaData[index];
formula.quantity ? (formula.quantity += 1) : (formula.quantity = 2);
formula.quantity = Math.max((formula.quantity ?? 0) + 1, 2);
} else {
this.preparedFormulaData.push({
itemUUID: formula.uuid,
quantity: 1,
});
this.preparedFormulaData.push({ itemUUID: formula.uuid, quantity: 1 });
}

return this.#updateRE();
Expand Down Expand Up @@ -160,17 +157,15 @@ class CraftingEntry implements Omit<CraftingEntryData, "parentItem"> {
async increaseFormulaQuantity(index: number, itemUUID: string): Promise<void> {
const formula = this.preparedFormulaData[index];
if (!formula || formula.itemUUID !== itemUUID) return;

formula.quantity ? (formula.quantity += 1) : (formula.quantity = 2);
formula.quantity = Math.max((formula.quantity ?? 0) + 1, 2);

return this.#updateRE();
}

async decreaseFormulaQuantity(index: number, itemUUID: string): Promise<void> {
const formula = this.preparedFormulaData[index];
if (!formula || formula.itemUUID !== itemUUID) return;

formula.quantity ? (formula.quantity -= 1) : (formula.quantity = 0);
formula.quantity = Math.max((formula.quantity ?? 0) - 1, 0);

if (formula.quantity <= 0) {
await this.unprepareFormula(index, itemUUID);
Expand All @@ -188,7 +183,6 @@ class CraftingEntry implements Omit<CraftingEntryData, "parentItem"> {

const formula = this.preparedFormulaData[index];
if (!formula || formula.itemUUID !== itemUUID) return;

formula.quantity = quantity;

return this.#updateRE();
Expand Down
12 changes: 6 additions & 6 deletions src/module/apps/compendium-browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@ class CompendiumBrowser extends Application {
filter.isExpanded = !filter.isExpanded;
const contentElement = title.nextElementSibling;
if (contentElement instanceof HTMLElement) {
filter.isExpanded
? (contentElement.style.display = "")
: (contentElement.style.display = "none");
contentElement.style.display = filter.isExpanded ? "" : "none";
}
};
switch (filterType) {
Expand Down Expand Up @@ -546,9 +544,11 @@ class CompendiumBrowser extends Application {
const checkbox = currentTab.filterData.checkboxes[filterName];
const option = checkbox.options[optionName];
option.selected = !option.selected;
option.selected
? checkbox.selected.push(optionName)
: (checkbox.selected = checkbox.selected.filter((name) => name !== optionName));
if (option.selected) {
checkbox.selected.push(optionName);
} else {
checkbox.selected = checkbox.selected.filter((name) => name !== optionName);
}
this.#clearScrollLimit(true);
}
});
Expand Down
6 changes: 5 additions & 1 deletion src/module/apps/sidebar/chat-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ class ChatLogPF2e extends ChatLog<ChatMessagePF2e> {
if (!canvas) return;
const token = message.token?.object;
if (token?.isVisible && token.isOwner) {
token.controlled ? token.release() : token.control({ releaseOthers: !event.shiftKey });
if (token.controlled) {
token.release();
} else {
token.control({ releaseOthers: !event.shiftKey });
}
// If a double click, also pan to the token
if (event.type === "dblclick") {
const scale = Math.max(1, canvas.stage.scale.x);
Expand Down
1 change: 0 additions & 1 deletion src/module/item/shield/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class ShieldPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ph
{ options: [mainDamageType, versatileDamageType], selection: mainDamageType },
this.system.traits.integrated.versatile ?? {},
);
this.system.traits.integrated.versatile.options;
} else if (this.system.traits.integrated) {
this.system.traits.integrated.versatile = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Migration659MultipleDamageRows extends MigrationBase {
}

if ("damageType" in data) {
"game" in globalThis ? (data["-=damageType"] = null) : (data.damageType = undefined);
data["-=damageType"] = null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Migration666UsageAndStowingContainers extends MigrationBase {
if (isPhysical && keepUsage && source.system.usage) {
source.system.usage.value = traits.usage.value;
}
"game" in globalThis ? (traits["-=usage"] = null) : delete traits.usage;
traits["-=usage"] = null;
}

// Set usage on containers and whether they're for stowing
Expand Down
4 changes: 2 additions & 2 deletions src/module/migration/migrations/670-ancestry-vision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export class Migration670AncestryVision extends MigrationBase {
const features: Record<string, MaybeOldABCFeatureEntryData | null> = ancestry.system.items;
for (const [key, value] of Object.entries(features)) {
if (value?.id === this.LOWLIGHTVISION_ID) {
"game" in globalThis ? (features[`-=${key}`] = null) : delete features[key];
features[`-=${key}`] = null;
// Prefer darkvision if the ancestry item somehow has both features
ancestry.system.vision = ancestry.system.vision === "darkvision" ? "darkvision" : "lowLightVision";
} else if (value?.id === this.DARKVISION_ID) {
"game" in globalThis ? (features[`-=${key}`] = null) : delete features[key];
features[`-=${key}`] = null;
ancestry.system.vision = "darkvision";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Migration672RemoveNPCBaseProperties extends MigrationBase {
property[replace] = Number(property[replace]) || 0;
if (typeof property.base === "number") {
property[replace] = property.base;
"game" in globalThis ? (property["-=base?"] = null) : delete property.base;
property["-=base"] = null;
}
}

Expand Down Expand Up @@ -39,5 +39,5 @@ interface PropertyWithBase {
value: number;
max?: number;
base?: number;
"-=base?"?: null;
"-=base"?: null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Migration679TowerShieldSpeedPenalty extends MigrationBase {
potencyRune.value = (Number(systemData.potencyRune?.value) || 0) as ZeroToFour;
if ("resilient" in systemData) {
// Aborted attempt to store rune data?
"game" in globalThis ? (systemData["-=resilient"] = null) : delete systemData.resilient;
systemData["-=resilient"] = null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ export class Migration820RemoveUnusedTraitsData extends MigrationBase {
static override version = 0.82;

override async updateItem(source: ItemSourcePF2e): Promise<void> {
source.system.traits;
const systemSource: MaybeWithTraits = source.system;

if (!systemSource.traits) return;

if ("custom" in systemSource.traits) {
delete systemSource.traits.custom;
systemSource.traits["-=custom"] = null;
}

if (source.type === "spellcastingEntry" || source.type === "condition") {
delete systemSource.traits;
systemSource["-=traits"] = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Migration862SpecificMagicArmor extends MigrationBase {
source.system.baseItem = "power-suit";
break;
case "subterfuge-suit":
source.system.baseItem === "subterfuge-suit";
source.system.baseItem = "subterfuge-suit";
break;
case "clothing-explorers":
source.system.slug = "explorers-clothing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Migration895FixVariantSpellTraits extends MigrationBase {
#fixOtherVariants(source: SpellSource): void {
for (const partial of Object.values(source.system.damage).filter((p) => R.isObject(p))) {
if (typeof partial.type === "string") {
partial.type === ("healing" as DamageType) ? "untyped" : partial.type;
partial.type = partial.type === ("healing" as DamageType) ? "untyped" : partial.type;
partial.type ||= "untyped";
}
}
Expand Down
1 change: 0 additions & 1 deletion src/module/rules/rule-element/ae-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ class AELikeRuleElement<TSchema extends AELikeSchema> extends RuleElementPF2e<TS
typeof value === "boolean" || typeof value === "number" || typeof value === "string" || value === null;
if (!isLoggable) return;

value;
const level = item.isOfType("feat")
? Number(/-(\d+)$/.exec(item.system.location ?? "")?.[1]) || item.level
: "level" in item && typeof item["level"] === "number"
Expand Down
1 change: 0 additions & 1 deletion src/module/rules/rule-element/grant-item/rule-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ class GrantItemRuleElement extends RuleElementPF2e<GrantItemSchema> {
}

const flags = { pf2e: { grantedBy: { id: this.item.id, onDelete: "cascade" } } };
conditionSource.flags.pf2e?.grantedBy;
const condition = new ConditionPF2e(
fu.mergeObject(conditionSource, {
_id: fu.randomID(),
Expand Down
3 changes: 2 additions & 1 deletion src/module/rules/rule-element/multiple-attack-penalty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class MultipleAttackPenaltyRuleElement extends RuleElementPF2e<MAPRuleSchema> {
if (this.ignored) return;

const selector = this.resolveInjectedProperties(this.selector);
if (this.ignored || selector.length === 0) true;
if (this.ignored || selector.length === 0) return;

const value = Number(this.resolveValue(this.value)) || 0;
if (value < 0) {
const label = game.i18n.format("PF2E.UI.RuleElements.MultipleAttackPenalty.Breakdown", {
Expand Down

0 comments on commit 42d6305

Please sign in to comment.