mirror of
https://github.com/sboulema/mtg-deck.git
synced 2026-07-22 06:50:39 +00:00
fix: Down to 3 eslint errors
This commit is contained in:
parent
896aa72f2b
commit
067802691a
7 changed files with 128 additions and 328 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import esbuild from "esbuild";
|
||||
import process from "process";
|
||||
import builtins from 'builtin-modules'
|
||||
import { builtinModules } from 'node:module'
|
||||
|
||||
const banner =
|
||||
`/*
|
||||
|
|
@ -31,7 +31,7 @@ const buildOptions = {
|
|||
'@lezer/common',
|
||||
'@lezer/highlight',
|
||||
'@lezer/lr',
|
||||
...builtins],
|
||||
...builtinModules],
|
||||
format: 'cjs',
|
||||
target: 'es2018',
|
||||
logLevel: "info",
|
||||
|
|
|
|||
10
main.ts
10
main.ts
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "src/collection";
|
||||
import { renderDecklist } from "src/renderer";
|
||||
import { ObsidianPluginMtgSettings } from "src/settings";
|
||||
import { CardCounts } from "src/collection";
|
||||
|
||||
const DEFAULT_SETTINGS: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
|
|
@ -29,7 +30,7 @@ export default class ObsidianPluginMtg extends Plugin {
|
|||
settings: ObsidianPluginMtgSettings;
|
||||
|
||||
// This keeps a record of the collection in memory
|
||||
cardCounts: Record<string, number>;
|
||||
cardCounts: CardCounts;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
|
@ -57,8 +58,6 @@ export default class ObsidianPluginMtg extends Plugin {
|
|||
this.registerMarkdownCodeBlockProcessor(
|
||||
"mtg-deck",
|
||||
async (source: string, el: HTMLElement, ctx) => {
|
||||
let error = null;
|
||||
|
||||
// Sync card counts once if they haven't been already
|
||||
if (!this.cardCounts) {
|
||||
this.cardCounts = await syncCounts(vault, this.settings);
|
||||
|
|
@ -72,10 +71,9 @@ export default class ObsidianPluginMtg extends Plugin {
|
|||
this.settings
|
||||
);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
console.error(err);
|
||||
el.createDiv({
|
||||
text: String(error),
|
||||
text: String(err),
|
||||
cls: "obsidian-plugin-mtg-error",
|
||||
});
|
||||
}
|
||||
|
|
@ -232,4 +230,4 @@ class ObsidianPluginMtgSettingsTab extends PluginSettingTab {
|
|||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
217
package-lock.json
generated
217
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -25,7 +25,6 @@
|
|||
"@types/node": "^25.6.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.59.1",
|
||||
"@typescript-eslint/parser": "8.59.1",
|
||||
"builtin-modules": "5.1.0",
|
||||
"esbuild": "0.28.0",
|
||||
"eslint": "^10.2.1",
|
||||
"eslint-plugin-obsidianmd": "^0.2.9",
|
||||
|
|
@ -40,5 +39,8 @@
|
|||
"ts-node": "^10.9.2",
|
||||
"tslib": "2.8.1",
|
||||
"typescript": "^6.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jest/globals": "^30.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
register.js
10
register.js
|
|
@ -2,12 +2,10 @@
|
|||
* Overrides the tsconfig used for the app.
|
||||
* In the test environment we need some tweaks.
|
||||
*/
|
||||
|
||||
const tsNode = require("ts-node");
|
||||
const testTSConfig = require("./test/tsconfig.json");
|
||||
|
||||
tsNode.register({
|
||||
files: true,
|
||||
transpileOnly: true,
|
||||
project: "./test/tsconfig.json",
|
||||
});
|
||||
files: true,
|
||||
transpileOnly: true,
|
||||
project: "./test/tsconfig.json",
|
||||
});
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import { describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { createCardCountsMapping, nameToId } from "./collection";
|
||||
import { ObsidianPluginMtgSettings } from "./settings";
|
||||
|
||||
|
|
@ -18,61 +17,54 @@ Delver of Secrets // Insectile Aberration,1,MID
|
|||
Ledger Shredder,5,SNC
|
||||
`;
|
||||
|
||||
// Empty
|
||||
const EXAMPLE_CSV_3 = `Name,Count,Set`;
|
||||
|
||||
describe("Collection", () => {
|
||||
describe("#nameToId()", () => {
|
||||
test("handles split cards", () => {
|
||||
const result = nameToId(
|
||||
"Delver of Secrets // Insectile Aberration"
|
||||
);
|
||||
expect(result).toEqual("delver of secrets");
|
||||
});
|
||||
describe("#nameToId()", () => {
|
||||
test("handles split cards", () => {
|
||||
const result = nameToId(
|
||||
"Delver of Secrets // Insectile Aberration"
|
||||
);
|
||||
expect(result).toEqual("delver of secrets");
|
||||
});
|
||||
test("handles spacing around name", () => {
|
||||
const result = nameToId(" Black Lotus ");
|
||||
expect(result).toEqual("black lotus");
|
||||
});
|
||||
test("handles commas", () => {
|
||||
const result = nameToId("Otawara, Soaring City");
|
||||
expect(result).toEqual("otawara, soaring city");
|
||||
});
|
||||
test("handles apostrophes", () => {
|
||||
const result = nameToId("Rona's Vortex");
|
||||
expect(result).toEqual("rona's vortex");
|
||||
});
|
||||
});
|
||||
|
||||
test("handles spacing around name", () => {
|
||||
const result = nameToId(" Black Lotus ");
|
||||
expect(result).toEqual("black lotus");
|
||||
});
|
||||
describe("#createCardCountsMapping", () => {
|
||||
const settings: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
fileExtension: "mtg.collection.csv",
|
||||
nameColumn: "Name",
|
||||
countColumn: "Count",
|
||||
syncIntervalMs: 10,
|
||||
},
|
||||
decklist: {
|
||||
preferredCurrency: "usd",
|
||||
showCardNamesAsHyperlinks: true,
|
||||
showCardPreviews: true,
|
||||
showBuylist: true,
|
||||
hidePrices: false,
|
||||
},
|
||||
};
|
||||
|
||||
test("handles commas", () => {
|
||||
const result = nameToId("Otawara, Soaring City");
|
||||
expect(result).toEqual("otawara, soaring city");
|
||||
});
|
||||
|
||||
test("handles apostrophes", () => {
|
||||
const result = nameToId("Rona's Vortex");
|
||||
expect(result).toEqual("rona's vortex");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createCardCountsMapping", () => {
|
||||
const settings: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
fileExtension: "mtg.collection.csv",
|
||||
nameColumn: "Name",
|
||||
countColumn: "Count",
|
||||
syncIntervalMs: 10,
|
||||
},
|
||||
decklist: {
|
||||
preferredCurrency: "usd",
|
||||
showCardNamesAsHyperlinks: true,
|
||||
showCardPreviews: true,
|
||||
showBuylist: true,
|
||||
hidePrices: false,
|
||||
},
|
||||
};
|
||||
test("handles multiple CSVs", async () => {
|
||||
const contents = [EXAMPLE_CSV_1, EXAMPLE_CSV_2];
|
||||
|
||||
const mapping = await createCardCountsMapping(contents, settings);
|
||||
|
||||
expect(mapping).toEqual({
|
||||
"delver of secrets": 9,
|
||||
"otawara, soaring city": 10,
|
||||
"rona's vortex": 5,
|
||||
"ledger shredder": 5,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
test("handles multiple CSVs", () => {
|
||||
const contents = [EXAMPLE_CSV_1, EXAMPLE_CSV_2];
|
||||
const mapping = createCardCountsMapping(contents, settings);
|
||||
expect(mapping).toEqual({
|
||||
"delver of secrets": 9,
|
||||
"otawara, soaring city": 10,
|
||||
"rona's vortex": 5,
|
||||
"ledger shredder": 5,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -5,68 +5,65 @@ import { ObsidianPluginMtgSettings } from "./settings";
|
|||
import { EXAMPLE_DECKLIST_CARD_DATA } from "../jest/fixtures/scryfall-data";
|
||||
import { CardData } from "./scryfall";
|
||||
import {
|
||||
EXAMPLE_COLLECTION,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_DECK_1_HTML,
|
||||
EXAMPLE_DECK_1_HTML_WITHOUT_PRICES,
|
||||
EXAMPLE_COLLECTION,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_DECK_1_HTML,
|
||||
EXAMPLE_DECK_1_HTML_WITHOUT_PRICES,
|
||||
} from "../jest/fixtures/content";
|
||||
|
||||
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
|
||||
const doc = dom.window.document;
|
||||
|
||||
const fakeFetcher = (
|
||||
distinctCardNames: string[]
|
||||
_distinctCardNames: string[]
|
||||
): Promise<Record<string, CardData>> =>
|
||||
new Promise((resolve, reject) => {
|
||||
resolve(EXAMPLE_DECKLIST_CARD_DATA as Record<string, CardData>);
|
||||
});
|
||||
Promise.resolve(EXAMPLE_DECKLIST_CARD_DATA as Record<string, CardData>);
|
||||
|
||||
describe("Renderer", () => {
|
||||
const settings: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
fileExtension: "mtg.collection.csv",
|
||||
nameColumn: "Name",
|
||||
countColumn: "Count",
|
||||
syncIntervalMs: 10,
|
||||
},
|
||||
decklist: {
|
||||
preferredCurrency: "usd",
|
||||
showCardNamesAsHyperlinks: true,
|
||||
showCardPreviews: true,
|
||||
showBuylist: true,
|
||||
hidePrices: false,
|
||||
},
|
||||
};
|
||||
const settings: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
fileExtension: "mtg.collection.csv",
|
||||
nameColumn: "Name",
|
||||
countColumn: "Count",
|
||||
syncIntervalMs: 10,
|
||||
},
|
||||
decklist: {
|
||||
preferredCurrency: "usd",
|
||||
showCardNamesAsHyperlinks: true,
|
||||
showCardPreviews: true,
|
||||
showBuylist: true,
|
||||
hidePrices: false,
|
||||
},
|
||||
};
|
||||
|
||||
describe("#renderDecklist", () => {
|
||||
test("with prices", async () => {
|
||||
const el = await renderDecklist(
|
||||
doc.body,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_COLLECTION,
|
||||
settings,
|
||||
fakeFetcher
|
||||
);
|
||||
expect(el.innerHTML.trim()).toEqual(EXAMPLE_DECK_1_HTML.trim());
|
||||
});
|
||||
|
||||
test("witout prices", async () => {
|
||||
const el = await renderDecklist(
|
||||
doc.body,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_COLLECTION,
|
||||
{
|
||||
...settings,
|
||||
decklist: {
|
||||
...settings.decklist,
|
||||
hidePrices: true,
|
||||
},
|
||||
},
|
||||
fakeFetcher
|
||||
);
|
||||
expect(el.innerHTML.trim()).toEqual(
|
||||
EXAMPLE_DECK_1_HTML_WITHOUT_PRICES.trim()
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("#renderDecklist", () => {
|
||||
test("with prices", async () => {
|
||||
const el = await renderDecklist(
|
||||
doc.body,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_COLLECTION,
|
||||
settings,
|
||||
fakeFetcher
|
||||
);
|
||||
expect(el.innerHTML.trim()).toEqual(EXAMPLE_DECK_1_HTML.trim());
|
||||
});
|
||||
test("without prices", async () => {
|
||||
const el = await renderDecklist(
|
||||
doc.body,
|
||||
EXAMPLE_DECK_1,
|
||||
EXAMPLE_COLLECTION,
|
||||
{
|
||||
...settings,
|
||||
decklist: {
|
||||
...settings.decklist,
|
||||
hidePrices: true,
|
||||
},
|
||||
},
|
||||
fakeFetcher
|
||||
);
|
||||
expect(el.innerHTML.trim()).toEqual(
|
||||
EXAMPLE_DECK_1_HTML_WITHOUT_PRICES.trim()
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue