Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams committed Feb 25, 2023
1 parent 4570ffd commit e33d881
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 98 deletions.
20 changes: 4 additions & 16 deletions src/fileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ export class AnkiFS implements vscode.FileSystemProvider {
throw vscode.FileSystemError.FileNotFound();
}

writeFile(
uri: vscode.Uri,
content: Uint8Array,
options: { create: boolean; overwrite: boolean }
): void {
writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean; overwrite: boolean }): void {
const basename = path.posix.basename(uri.path);
const parent = this._lookupParentDirectory(uri);
let entry = parent.entries.get(basename);
Expand All @@ -105,11 +101,7 @@ export class AnkiFS implements vscode.FileSystemProvider {
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
}

rename(
oldUri: vscode.Uri,
newUri: vscode.Uri,
options: { overwrite: boolean }
): void {}
rename(oldUri: vscode.Uri, newUri: vscode.Uri, options: { overwrite: boolean }): void {}

delete(uri: vscode.Uri): void {}

Expand All @@ -123,10 +115,7 @@ export class AnkiFS implements vscode.FileSystemProvider {
parent.mtime = Date.now();
parent.size += 1;

this._fireSoon(
{ type: vscode.FileChangeType.Changed, uri: dirname },
{ type: vscode.FileChangeType.Created, uri }
);
this._fireSoon({ type: vscode.FileChangeType.Changed, uri: dirname }, { type: vscode.FileChangeType.Created, uri });
}

private _lookup(uri: vscode.Uri, silent: false): Entry;
Expand Down Expand Up @@ -181,8 +170,7 @@ export class AnkiFS implements vscode.FileSystemProvider {
private _bufferedEvents: vscode.FileChangeEvent[] = [];
private _fireSoonHandle?: NodeJS.Timeout;

readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> =
this._emitter.event;
readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = this._emitter.event;

watch(_resource: vscode.Uri): vscode.Disposable {
// ignore, fires for all changes...
Expand Down
13 changes: 4 additions & 9 deletions src/initialSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ export async function initialSetup(ctx: IContext) {

// get dark-mode override
// The selectors in here are more specific so will kick in when darkMode is turned on
const vscodeAnkiPlugin = readFileSync(
path.join(ctx.context.extensionPath, "out", "extension.css"),
{
encoding: "base64",
}
);
const vscodeAnkiPlugin = readFileSync(path.join(ctx.context.extensionPath, "out", "extension.css"), {
encoding: "base64",
});

const resources = [
{
Expand All @@ -36,9 +33,7 @@ export async function initialSetup(ctx: IContext) {
result = await ctx.ankiService.storeMultipleFiles(resources);
disposable.dispose();
} catch (e: any) {
getLogger().error(
`installation attempt failed (Anki most likely not running): ${e}`
);
getLogger().error(`installation attempt failed (Anki most likely not running): ${e}`);
// If any of the above failed we don't want to update the version, meaning it will try again next time the extension has started
return;
}
Expand Down
9 changes: 1 addition & 8 deletions src/markdown/__tests__/Latex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ describe("Latex", () => {
});
it("Should keep the content of 'Latex block' unchanged.", async () => {
// linesToHtml always return a newline at the end of string
const latexs = [
"a=\\%1",
"b=\\#1",
"\\before{align}",
"c=\\{1,2\\} \\\\",
"d=\\$2",
"\\end{align}",
];
const latexs = ["a=\\%1", "b=\\#1", "\\before{align}", "c=\\{1,2\\} \\\\", "d=\\$2", "\\end{align}"];
const input = [
`extra stuff before the latex`,
`$$${latexs[0]} ${latexs[1]}$$`, // one line latex block
Expand Down
40 changes: 8 additions & 32 deletions src/markdown/__tests__/Serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ describe("Serializer", () => {
it("should strip out any front matter before getting the title", () => {
// Arrange
const deckName = "Test Title";
const input = [
`Some Random Front Matter\r\n# ${deckName}\r\n`,
"## Some Card\r\nCard text",
];
const serializer = new Serializer(
new MarkdownFile(null),
DeckNameStrategy.ParseTitle
);
const input = [`Some Random Front Matter\r\n# ${deckName}\r\n`, "## Some Card\r\nCard text"];
const serializer = new Serializer(new MarkdownFile(null), DeckNameStrategy.ParseTitle);
// Act
const result = serializer.deckName(input);
// Assert
Expand All @@ -39,14 +33,8 @@ describe("Serializer", () => {
it("should only receive the title from the line of the h1 accounting for CRLF line endings", () => {
// Arrange
const deckName = "Test Title";
const input = [
`# ${deckName}\r\n\r\nextra stuff before the card`,
"## Some Card\r\nCard text",
];
const serializer = new Serializer(
new MarkdownFile(null),
DeckNameStrategy.ParseTitle
);
const input = [`# ${deckName}\r\n\r\nextra stuff before the card`, "## Some Card\r\nCard text"];
const serializer = new Serializer(new MarkdownFile(null), DeckNameStrategy.ParseTitle);
// Act
const result = serializer.deckName(input);
// Assert
Expand All @@ -55,14 +43,8 @@ describe("Serializer", () => {
it("should only receive the title from the line of the h1 accounting for LF line endings", () => {
// Arrange
const deckName = "Test Title";
const input = [
`# ${deckName}\n\nextra stuff before the card`,
"## Some Card\nCard text",
];
const serializer = new Serializer(
new MarkdownFile(null),
DeckNameStrategy.ParseTitle
);
const input = [`# ${deckName}\n\nextra stuff before the card`, "## Some Card\nCard text"];
const serializer = new Serializer(new MarkdownFile(null), DeckNameStrategy.ParseTitle);
// Act
const result = serializer.deckName(input);
// Assert
Expand All @@ -71,14 +53,8 @@ describe("Serializer", () => {
it("should only receive the title from the line of the h1 accounting for weird mac line endings", () => {
// Arrange
const deckName = "Test Title";
const input = [
`# ${deckName}\r\rextra stuff before the card`,
"## Some Card\rCard text",
];
const serializer = new Serializer(
new MarkdownFile(null),
DeckNameStrategy.ParseTitle
);
const input = [`# ${deckName}\r\rextra stuff before the card`, "## Some Card\rCard text"];
const serializer = new Serializer(new MarkdownFile(null), DeckNameStrategy.ParseTitle);
// Act
const result = serializer.deckName(input);
// Assert
Expand Down
12 changes: 3 additions & 9 deletions src/models/Deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ export class Deck {
}

private orderZeroFieldValue(card: Card): string | null {
const field: any = Object.values(card.fields).find(
(field: any) => field.order === 0
);
const field: any = Object.values(card.fields).find((field: any) => field.order === 0);
if (field) {
return field.value;
} else {
Expand Down Expand Up @@ -102,9 +100,7 @@ export class Deck {
}

private async deleteCards(cards: Card[]) {
const nIds: number[] = cards
.filter((card) => card.noteId)
.map((card) => card.noteId!);
const nIds: number[] = cards.filter((card) => card.noteId).map((card) => card.noteId!);
await this.ankiService?.deleteNotes(nIds);
}

Expand All @@ -127,9 +123,7 @@ export class Deck {
const id = await this.ankiService.createDeck(this.name);
this.id = id;
} else {
throw new Error(
"Deck cannot be created because it either has an ID or can't use Service"
);
throw new Error("Deck cannot be created because it either has an ID or can't use Service");
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/models/MarkdownFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ export class MarkdownFile {
public async updateMeta(cards: Card[], autoSend: boolean) {
this.autoSend = autoSend;
const ids = cards.map((c) => c.noteId ?? 0);
const metaBody = `[auto-send]: # (${
this.autoSend ? "yes" : "no"
})${EOL}[note-ids]: # (${ids.join(", ")})`;
const metaBody = `[auto-send]: # (${this.autoSend ? "yes" : "no"})${EOL}[note-ids]: # (${ids.join(", ")})`;
const meta = `${EOL}${EOL}${EOL}${this.metaStart}${EOL}${metaBody}${EOL}${this.metaEnd}${EOL}`;
const content = this.cachedContent + meta;
if (this.isFromActiveEditor) {
Expand Down
20 changes: 4 additions & 16 deletions src/models/SendDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@ export class SendDiff {

public static combine(diffs: SendDiff[]): SendDiff {
const diff = new SendDiff();
diff.cardsAdded = diffs.reduce(
(acc: Card[], diff) => acc.concat(diff.cardsAdded),
[]
);
diff.cardsUnchanged = diffs.reduce(
(acc: Card[], diff) => acc.concat(diff.cardsUnchanged),
[]
);
diff.cardsDeleted = diffs.reduce(
(acc: Card[], diff) => acc.concat(diff.cardsDeleted),
[]
);
diff.notesDeleted = diffs.reduce(
(acc: Number[], diff) => acc.concat(diff.notesDeleted),
[]
);
diff.cardsAdded = diffs.reduce((acc: Card[], diff) => acc.concat(diff.cardsAdded), []);
diff.cardsUnchanged = diffs.reduce((acc: Card[], diff) => acc.concat(diff.cardsUnchanged), []);
diff.cardsDeleted = diffs.reduce((acc: Card[], diff) => acc.concat(diff.cardsDeleted), []);
diff.notesDeleted = diffs.reduce((acc: Number[], diff) => acc.concat(diff.notesDeleted), []);
return diff;
}
}
6 changes: 1 addition & 5 deletions src/models/Template.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const {
question: defaultQuestion,
answer: defaultAnswer,
css: defaultCss,
} = require("../configs").template.formats;
const { question: defaultQuestion, answer: defaultAnswer, css: defaultCss } = require("../configs").template.formats;

class Template {
private questionFormat: string;
Expand Down

0 comments on commit e33d881

Please sign in to comment.