Skip to content

Commit

Permalink
Add ESLint rule to enforce array types (foundryvtt#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
In3luki authored Aug 14, 2022
1 parent 3025e9a commit 175491b
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off", // Handled by tsconfig
"@typescript-eslint/array-type": ["error", { "default": "array" }],
},
settings: {
"import/resolver": {
Expand Down
4 changes: 2 additions & 2 deletions src/module/actor/sheet/loot/loot-npcs-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { PhysicalItemSource } from "@item/data";
import { ErrorPF2e } from "@util";

interface PopupData extends FormApplicationData<ActorPF2e> {
tokenInfo: Array<{
tokenInfo: {
id: string;
name: string;
checked: boolean;
}>;
}[];
}

export class LootNPCsPopup extends FormApplication<ActorPF2e> {
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class ItemPF2e extends Item<ActorPF2e> {
// Get item and actor data and format it for the damage roll
const systemData = this.system;
const rollData: HazardSystemData & { item?: MeleeSystemData } = this.actor.toObject(false).system;
let parts: Array<string | number> = [];
let parts: (string | number)[] = [];
const partsType: string[] = [];

// If the NPC is using the updated NPC Attack data object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MigrationBase } from "../base";
export class Migration651EphemeralFocusPool extends MigrationBase {
static override version = 0.651;

private needsRuleElement(rules: Array<RuleElementSource & { path?: string }>): boolean {
private needsRuleElement(rules: (RuleElementSource & { path?: string })[]): boolean {
return !rules.some((rule) => rule.key === "ActiveEffectLike" && rule.path === "system.resources.focus.max");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MigrationBase } from "../base";
export class Migration656OtherFocusPoolSources extends MigrationBase {
static override version = 0.656;

private needsRuleElement(rules: Array<RuleElementSource & { path?: string }>): boolean {
private needsRuleElement(rules: (RuleElementSource & { path?: string })[]): boolean {
return !rules.some((rule) => rule.key === "ActiveEffectLike" && rule.path === "system.resources.focus.max");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Migration702REFormulasAtInstanceLevel extends MigrationBase {
}

override async updateItem(itemSource: ItemSourcePF2e): Promise<void> {
const rules: Array<RuleElementSource & { text?: string }> = itemSource.system.rules;
const rules: (RuleElementSource & { text?: string })[] = itemSource.system.rules;
for (const rule of rules) {
try {
if (typeof rule.value === "string") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Migration704MartialProficiencyRE extends MigrationBase {

if (itemSource.type === "class") {
if (itemSource.system.slug === "gunslinger" && itemSource.system.rules.length === 0) {
const gunslingerRules: Array<RuleElementSource & { definition?: object }> = [
const gunslingerRules: (RuleElementSource & { definition?: object })[] = [
{
definition: {
all: ["weapon:category:simple"],
Expand Down
2 changes: 1 addition & 1 deletion src/module/system/settings/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export abstract class SettingsMenuPF2e extends FormApplication {
return (this.constructor as typeof SettingsMenuPF2e).namespace;
}

static readonly SETTINGS: ReadonlyArray<string>;
static readonly SETTINGS: readonly string[];

/** Settings to be registered and also later referenced during user updates */
protected static get settings(): Record<string, PartialSettingsData> {
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/client/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ declare global {

/** Configuration for dice rolling behaviors in the Foundry VTT client */
Dice: {
types: Array<typeof Die | typeof DiceTerm>;
types: (typeof Die | typeof DiceTerm)[];
rollModes: Record<RollMode, string>;
rolls: ConstructorOf<Roll>[];
termTypes: Record<string, ConstructorOf<RollTerm>>;
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/client/pixi/helpers/ruler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare class Ruler extends PIXI.Container {
* The first waypoint is always the origin of the route.
* @type {Array<PIXI.Point>}
*/
public waypoints: Array<PIXI.Point>;
public waypoints: PIXI.Point[];

/**
* The current destination point at the end of the measurement
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/client/roll.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ declare global {
* @param _formula The raw formula to split
* @returns An array of terms, split on arithmetic operators
*/
protected static _splitOperators(_formula: string): Array<string | OperatorTerm>;
protected static _splitOperators(_formula: string): (string | OperatorTerm)[];

/**
* Temporarily remove flavor text from a string formula allowing it to be accurately parsed.
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/common/utils/helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ declare global {
* @param b The blue color value
* @return The HSV representation
*/
function rgbToHsv(r: number, g: number, b: number): Array<number>;
function rgbToHsv(r: number, g: number, b: number): number[];

/**
* Converts an HSV color value to RGB. Conversion formula
Expand Down
4 changes: 2 additions & 2 deletions types/foundry/common/utils/primitives.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ declare interface Number {
/* -------------------------------------------- */

declare interface Array<T> {
fromRange(n: number): Array<T>;
fromRange(n: number): T[];

deepFlatten(): Array<T>;
deepFlatten(): T[];

/**
* Test equality of the values of this array against the values of some other Array
Expand Down

0 comments on commit 175491b

Please sign in to comment.