Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
cwegrzyn committed May 17, 2024
1 parent e1054ad commit 618b4c3
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 42 deletions.
7 changes: 4 additions & 3 deletions src/datastore/parsers/dataforged.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Ruleset } from "@datasworn/core";
import data from "@datasworn/starforged/json/starforged.json";
import { OracleGrouping, OracleGroupingType } from "../../model/oracle";
import { indexIntoOracleMap } from "./dataforged";
const data = require("@datasworn/starforged/json/starforged.json");

describe("indexIntoOracleMap", () => {
it("indexes included starforged data", () => {
const map = indexIntoOracleMap(data);
const map = indexIntoOracleMap(data as Ruleset);
expect(map.get("starforged/oracles/core/action")).toHaveProperty(
"id",
"starforged/oracles/core/action",
);
});

it("indexes each Ask The Oracle entry", () => {
const map = indexIntoOracleMap(data);
const map = indexIntoOracleMap(data as Ruleset);
const almostCertain = map.get(
"starforged/oracles/moves/ask_the_oracle/almost_certain",
)!;
Expand Down
4 changes: 3 additions & 1 deletion src/datastore/parsers/datasworn/oracles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import assert from "assert";
import { OracleGrouping, OracleGroupingType } from "../../../model/oracle";
import { DataswornOracle } from "./oracles";

const data = require("@datasworn/starforged/json/starforged.json") as Ruleset;
import rawSfData from "@datasworn/starforged/json/starforged.json";

const data: Ruleset = rawSfData as Ruleset;

function loadOracle(...[first, ...rest]: string[]): DataswornOracle {
let collection: OracleCollection = data.oracles[first];
Expand Down
6 changes: 4 additions & 2 deletions src/datastore/parsers/datasworn/oracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class DataswornOracle implements Oracle {
for (const [, id] of template.result.matchAll(
/\{\{result:([^{}]+)\}\}/g,
)) {
let prevRoll = subrolls[id];
const prevRoll = subrolls[id];
if (!prevRoll) {
const subTable = context.lookup(id);
if (subTable == null) {
Expand Down Expand Up @@ -151,7 +151,7 @@ export class DataswornOracle implements Oracle {
}
}

let subrollable: Oracle | undefined =
const subrollable: Oracle | undefined =
subOracle.oracle == null ? this : context.lookup(subOracle.oracle);
if (!subrollable)
throw new Error(
Expand Down Expand Up @@ -186,6 +186,8 @@ export class DataswornOracle implements Oracle {
this.id,
subOracle.oracle,
);
results.push(roll);
break;
case "keep":
results.push(roll);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/parsers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function parserForFrontmatter(
}

export function dataforgedInlineParser(content: string): ParserReturn {
let matches = content.match(
const matches = content.match(
/^```[^\S\r\n]*data(forged|sworn)\s?\n([\s\S]+?)^```/m,
);
if (matches == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/parsers/oracle-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function parseRange(input: string): NumberRange | undefined {
};
}

const TEMPLATE_REGEX = /\[[^\[\]]+\]\(id:([\w_\-/]+)\)/gi;
const TEMPLATE_REGEX = /\[[^[\]]+\]\(id:([\w_\-/]+)\)/gi;

export function parseResultTemplate(
input: string,
Expand Down
10 changes: 1 addition & 9 deletions src/datastore/parsers/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ export function matchTable(content: string): MarkdownTable {
export function matchTables(content: string): MarkdownTable[] {
const tables: Array<MarkdownTable> = [];
for (const tableMatch of content.matchAll(TABLE_REGEX)) {
let table;
// try {
table = parseTable(tableMatch);
// } catch {
// table = null;
// }
if (table) {
tables.push(table);
}
tables.push(parseTable(tableMatch));
}

return tables;
Expand Down
2 changes: 2 additions & 0 deletions src/datastore/paths.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// NOTE: This whole thing is a currently unused experiment.
import {
Asset,
AssetAbility,
Expand Down
5 changes: 3 additions & 2 deletions src/datastore/priority-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getHighestPriorityChecked<K extends string, V>(
function getHighestPriority<K extends string, V>(
entries: Array<Sourced<K, V>>,
): Sourced<K, V> | undefined {
// eslint-disable-next-line prefer-const
let [first, ...rest] = entries;
if (first === undefined) {
return undefined;
Expand Down Expand Up @@ -59,8 +60,8 @@ export class PriorityIndexer<K extends string, V> implements ReadonlyMap<K, V> {
}

forEach(
callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void,
thisArg?: any,
_callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void,
_thisArg?: unknown,
): void {
throw new Error("Method not implemented.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/entity/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const ENTITIES: Record<string, EntityDescriptor<EntitySpec>> = {

creature: {
label: "Creature",
nameGen: (ent) => "TBD",
nameGen: (_ent) => "TBD",
spec: {
environment: {
id: "starforged/oracles/creatures/environment",
Expand Down Expand Up @@ -222,7 +222,7 @@ export async function generateEntityCommand(
plugin: ForgedPlugin,
editor: Editor,
): Promise<void> {
const [_key, entityDesc] = await CustomSuggestModal.select(
const [, entityDesc] = await CustomSuggestModal.select(
plugin.app,
Object.entries(ENTITIES),
([_key, { label }]) => label,
Expand Down
5 changes: 3 additions & 2 deletions src/model/rolls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class RollWrapper {
return [this.row.result];
case RollResultKind.Multi:
return this.selfRolls.flatMap((r) => r.results);
case RollResultKind.Templated:
case RollResultKind.Templated: {
const templateString = this.row.template?.result;
if (templateString == null) {
throw new Error(
Expand All @@ -202,7 +202,7 @@ export class RollWrapper {
return [
templateString.replace(
/\{\{result:([^{}]+)\}\}/g,
(_: any, id: string) => {
(_, id: string) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const templateRolls = this.subrolls[id];
if (templateRolls == null) {
Expand All @@ -212,6 +212,7 @@ export class RollWrapper {
},
),
];
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/moves/move-line-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function modifierWithDesc(): Parser<{ amount: number; desc: string }> {
function descriptor(): Parser<string> {
return takeMid(
string("{"),
regexp(/[^\}\{]+/g, "string without curly braces"),
regexp(/[^}{]+/g, "string without curly braces"),
string("}"),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/oracles/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class OracleRollerModal extends Modal {
});
});

this.scope.register([], "r", (evt, ctx) => {
this.scope.register([], "r", () => {
setRoll(this.currentRoll.reroll());
return false;
});
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/progress-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GenericTextSuggest extends TextInputSuggest<FuzzyMatch<string>> {
}
}

const OBSIDIAN_ILLEGAL_FILENAME_CHARS = /[/\\:*?"<>|#^\[\]]/g;
const OBSIDIAN_ILLEGAL_FILENAME_CHARS = /[/\\:*?"<>|#^[\]]/g;

function generateTrackName(name: string): string {
return name
Expand Down
4 changes: 2 additions & 2 deletions src/tracks/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ProgressTrackFileWriter implements ProgressTrackWriterContext {
public readonly adapter: ProgressTrackFileAdapter,
public readonly settings: ProgressTrackSettings,
public readonly processor: (
process: (data: any) => object,
process: (data: unknown) => object,
) => Promise<void>,
public readonly location: string,
) {}
Expand All @@ -47,7 +47,7 @@ export class LegacyTrackWriter implements ProgressTrackWriterContext {
constructor(
public readonly character: CharacterContext,
public readonly processor: (
process: (data: any) => object,
process: (data: unknown) => object,
) => Promise<void>,
public readonly trackKey: string,
public readonly location: string,
Expand Down
6 changes: 5 additions & 1 deletion src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ declare module "obsidian" {

declare module "obsidian" {
interface MetadataCache {
on(name: "forged:index-changed", callback: () => any, ctx?: any): EventRef;
on(
name: "forged:index-changed",
callback: () => unknown,
ctx?: unknown,
): EventRef;
}

interface App {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Left<T> {
return Left.create(fn(this.error));
}

map<V>(fn: (val: never) => V): Left<T> {
map<V>(_fn: (val: never) => V): Left<T> {
return this;
}

Expand All @@ -52,15 +52,15 @@ export class Right<U> {
return new Right(value);
}

mapError<V>(fn: (err: any) => V): Right<U> {
mapError<V>(_fn: (err: unknown) => V): Right<U> {
return this;
}

map<V>(fn: (val: U) => V): Right<V> {
return Right.create<V>(fn(this.value));
}

expect(msg: string): U {
expect(_msg: string): U {
return this.value;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/obsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export function pluginAsset(plug: Plugin, assetPath: string): string {
export function vaultProcess(
app: App,
path: string,
): (processor: (data: any) => object) => Promise<void> {
): (processor: (data: unknown) => object) => Promise<void> {
return async (processor) => {
const file = app.vault.getAbstractFileByPath(path);
if (!(file instanceof TFile)) {
throw new Error(`invalid character file ${path}`);
}
await app.fileManager.processFrontMatter(file, (frontmatter: any) => {
await app.fileManager.processFrontMatter(file, (frontmatter: object) => {
const updated = processor(frontmatter);
// TODO: this isn't actually going to work right... for deletes
Object.assign(frontmatter, updated);
Expand Down
4 changes: 0 additions & 4 deletions src/utils/tracking-proxy.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/utils/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export function updater<T>(
fromData: (data: object) => T,
toData: (obj: T) => object,
): (
process: (processer: (data: any) => object) => Promise<void>,
process: (processer: (data: unknown) => object) => Promise<void>,
updater: (obj: T) => T,
) => Promise<T> {
return async (process, updater) => {
let updated: T | undefined;
await process((data: any) => {
await process((data: unknown) => {
updated = updater(fromData(Object.freeze(Object.assign({}, data))));
return toData(updated);
});
Expand All @@ -21,12 +21,12 @@ export function updaterWithContext<T, U>(
toData: (obj: T) => object,
context: U,
): (
process: (processer: (data: any) => object) => Promise<void>,
process: (processer: (data: unknown) => object) => Promise<void>,
updater: (obj: T, context: U) => T,
) => Promise<T> {
return async (process, updater) => {
let updated: T | undefined;
await process((data: any) => {
await process((data: unknown) => {
updated = updater(
fromData(Object.freeze(Object.assign({}, data))),
context,
Expand Down

0 comments on commit 618b4c3

Please sign in to comment.