Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Mar 27, 2023
1 parent 0502bd7 commit 6a42f41
Show file tree
Hide file tree
Showing 48 changed files with 160 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/MacrosManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IMacro } from "./types/macros/IMacro";
import type { App } from "obsidian";
import {
App,
ButtonComponent,
Modal,
Setting,
Expand Down Expand Up @@ -223,7 +223,7 @@ export class MacrosManager extends Modal {
this.macroContainer.scrollHeight
);
} catch (error) {
log.logError(error);
log.logError(error as string);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/choiceExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ChoiceExecutor implements IChoiceExecutor {
}
case ChoiceType.Multi: {
const multiChoice: IMultiChoice = choice as IMultiChoice;
await this.onChooseMultiType(multiChoice);
this.onChooseMultiType(multiChoice);
break;
}
default:
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ChoiceExecutor implements IChoiceExecutor {
}

private async onChooseMacroType(macroChoice: IMacroChoice) {
const macroEngine = await new MacroChoiceEngine(
const macroEngine = new MacroChoiceEngine(
this.app,
this.plugin,
macroChoice,
Expand All @@ -81,7 +81,7 @@ export class ChoiceExecutor implements IChoiceExecutor {
});
}

private async onChooseMultiType(multiChoice: IMultiChoice) {
private onChooseMultiType(multiChoice: IMultiChoice) {
ChoiceSuggester.Open(this.plugin, multiChoice.choices, this);
}
}
2 changes: 1 addition & 1 deletion src/engine/CaptureChoiceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
filePath: string,
content: string
): Promise<{ file: TFile; content: string }> {
const file: TFile = await this.getFileByPath(filePath);
const file: TFile = this.getFileByPath(filePath);
if (!file) throw new Error("File not found");

// First format pass...
Expand Down
14 changes: 9 additions & 5 deletions src/engine/MacroChoiceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {
protected async executeCommands(commands: ICommand[]) {
for (const command of commands) {
if (command?.type === CommandType.Obsidian)
await this.executeObsidianCommand(command as IObsidianCommand);
this.executeObsidianCommand(command as IObsidianCommand);
if (command?.type === CommandType.UserScript)
await this.executeUserScript(command as IUserScript);
if (command?.type === CommandType.Choice)
Expand Down Expand Up @@ -125,7 +125,7 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {
await this.userScriptDelegator(userScript);
} catch (error) {
log.logError(
`failed to run user script ${command.name}. Error:\n\n${error.message}`
`failed to run user script ${command.name}. Error:\n\n${(error as {message: string}).message}`
);
}

Expand Down Expand Up @@ -168,14 +168,17 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {
case "function":
if (this.userScriptCommand) {
await this.runScriptWithSettings(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
userScript,
this.userScriptCommand
);
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
await this.onExportIsFunction(userScript);
}
break;
case "object":
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
await this.onExportIsObject(userScript);
break;
case "bigint":
Expand Down Expand Up @@ -231,12 +234,13 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {

await this.userScriptDelegator(obj[selected]);
} catch (e) {
log.logMessage(e);
log.logMessage(e as string);
}
}

protected executeObsidianCommand(command: IObsidianCommand) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.app.commands.executeCommandById(command.commandId);
}

Expand Down Expand Up @@ -274,10 +278,10 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {
await PasteCommand.run(this.app);
break;
case EditorCommandType.SelectActiveLine:
await SelectActiveLineCommand.run(this.app);
SelectActiveLineCommand.run(this.app);
break;
case EditorCommandType.SelectLinkOnActiveLine:
await SelectLinkOnActiveLineCommand.run(this.app);
SelectLinkOnActiveLineCommand.run(this.app);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/QuickAddEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export abstract class QuickAddEngine {
return await this.app.vault.adapter.exists(filePath);
}

protected async getFileByPath(filePath: string): Promise<TFile> {
const file = await this.app.vault.getAbstractFileByPath(filePath);
protected getFileByPath(filePath: string): TFile {
const file = this.app.vault.getAbstractFileByPath(filePath);

if (!file) {
log.logError(`${filePath} not found`);
Expand Down
3 changes: 3 additions & 0 deletions src/engine/SingleInlineScriptEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export class SingleInlineScriptEngine extends MacroChoiceEngine {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async runAndGetOutput(code: string): Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const AsyncFunction = Object.getPrototypeOf(
async function () {}
).constructor;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const userCode = new AsyncFunction(code);

// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
return await userCode.bind(this.params, this).call();
}
}
3 changes: 3 additions & 0 deletions src/engine/SingleMacroEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ export class SingleMacroEngine extends MacroChoiceEngine {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected override async onExportIsObject(obj: any): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (!this.memberAccess) return await super.onExportIsObject(obj);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
let newObj = obj;
this.memberAccess.forEach((key) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
newObj = newObj[key];
});

Expand Down
3 changes: 2 additions & 1 deletion src/engine/StartupMacroEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export class StartupMacroEngine extends MacroChoiceEngine {
super(app, plugin, null, macros, choiceExecutor, null);
}

// eslint-disable-next-line @typescript-eslint/require-await
async run(): Promise<void> {
this.macros.forEach((macro) => {
if (macro.runOnStartup) {
this.executeCommands(macro.commands);
void this.executeCommands(macro.commands);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/TemplateChoiceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class TemplateChoiceEngine extends TemplateEngine {
});
}
} catch (error) {
log.logError(error);
log.logError(error as string);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/engine/TemplateEngine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QuickAddEngine } from "./QuickAddEngine";
import { CompleteFormatter } from "../formatters/completeFormatter";
import { App, TFile } from "obsidian";
import type { App } from "obsidian";
import { TFile } from "obsidian";
import type QuickAdd from "../main";
import {
getTemplater,
Expand Down Expand Up @@ -109,7 +110,7 @@ export abstract class TemplateEngine extends QuickAddEngine {
return createdFile;
} catch (e) {
log.logError(
`Could not create file with template: \n\n${e.message}`
`Could not create file with template: \n\n${(e as {message: string}).message}`
);
return null;
}
Expand All @@ -132,7 +133,7 @@ export abstract class TemplateEngine extends QuickAddEngine {

return file;
} catch (e) {
log.logError(e);
log.logError(e as string);
return null;
}
}
Expand Down Expand Up @@ -160,7 +161,7 @@ export abstract class TemplateEngine extends QuickAddEngine {

return file;
} catch (e) {
log.logError(e);
log.logError(e as string);
return null;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/formatters/completeFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { Formatter } from "./formatter";
import type { App } from "obsidian";
import { getNaturalLanguageDates } from "../utilityObsidian";
Expand Down Expand Up @@ -113,6 +116,7 @@ export class CompleteFormatter extends Formatter {

for (const file of this.app.vault.getMarkdownFiles()) {
const cache = this.app.metadataCache.getFileCache(file);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value = cache?.frontmatter?.[variableName];
if (!value || typeof value == "object") continue;

Expand Down Expand Up @@ -167,6 +171,7 @@ export class CompleteFormatter extends Formatter {
).run();
}

// eslint-disable-next-line @typescript-eslint/require-await
protected async getSelectedText(): Promise<string> {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!activeView) return "";
Expand Down
1 change: 1 addition & 0 deletions src/formatters/fileNameDisplayFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/require-await */
import { Formatter } from "./formatter";
import type { App } from "obsidian";
import { getNaturalLanguageDates } from "../utilityObsidian";
Expand Down
1 change: 1 addition & 0 deletions src/formatters/formatDisplayFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class FormatDisplayFormatter extends Formatter {
}
}

// eslint-disable-next-line @typescript-eslint/require-await
protected async getSelectedText(): Promise<string> {
return "_selected_";
}
Expand Down
5 changes: 5 additions & 0 deletions src/formatters/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import {
DATE_REGEX,
DATE_REGEX_FORMATTED,
Expand Down Expand Up @@ -84,6 +86,7 @@ export abstract class Formatter {
return output;
}

// eslint-disable-next-line @typescript-eslint/require-await
protected async replaceLinkToCurrentFileInString(
input: string
): Promise<string> {
Expand Down Expand Up @@ -213,6 +216,7 @@ export abstract class Formatter {
suggestedValues: string[]
): Promise<string> | string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected abstract suggestForField(variableName: string): any;

protected async replaceDateVariableInString(input: string) {
Expand All @@ -232,6 +236,7 @@ export abstract class Formatter {
await this.promptForVariable(variableName)
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const nld = this.getNaturalLanguageDates();
if (
!nld ||
Expand Down
4 changes: 3 additions & 1 deletion src/gui/ChoiceBuilder/choiceBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, Modal, Setting } from "obsidian";
import type { App, Setting } from "obsidian";
import { Modal } from "obsidian";
import type IChoice from "../../types/choices/IChoice";
import type { SvelteComponent } from "svelte";
import GenericInputPrompt from "../GenericInputPrompt/GenericInputPrompt";
Expand Down Expand Up @@ -63,6 +64,7 @@ export abstract class ChoiceBuilder extends Modal {
});
headerEl.setText(choice.name);

// eslint-disable-next-line @typescript-eslint/no-misused-promises
headerEl.addEventListener("click", async (ev) => {
try {
const newName: string = await GenericInputPrompt.Prompt(
Expand Down
9 changes: 5 additions & 4 deletions src/gui/ChoiceBuilder/macroChoiceBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ChoiceBuilder } from "./choiceBuilder";
import type IMacroChoice from "../../types/choices/IMacroChoice";
import { App, ButtonComponent } from "obsidian";
import type { App } from "obsidian";
import { ButtonComponent } from "obsidian";
import { DropdownComponent } from "obsidian";
import type { IMacro } from "../../types/macros/IMacro";
import { MacroBuilder } from "../MacroGUIs/MacroBuilder";
import QuickAdd from "src/main";
import { settingsStore } from "src/settingsStore";
import IChoice from "src/types/choices/IChoice";
import type IChoice from "src/types/choices/IChoice";
import { log } from "src/logger/logManager";

export class MacroChoiceBuilder extends ChoiceBuilder {
Expand Down Expand Up @@ -71,13 +72,13 @@ export class MacroChoiceBuilder extends ChoiceBuilder {
.setIcon("plus")
.setCta()
.setTooltip("Create Macro")
.onClick(async () => {
.onClick(() => {
try {
const macro = settingsStore.createMacro(this.choice.name);
this.choice.macroId = macro.id;
this.reload();
} catch (error) {
log.logError(error);
log.logError(error as string);
}
});
}
Expand Down
8 changes: 5 additions & 3 deletions src/gui/ChoiceBuilder/templateChoiceBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChoiceBuilder } from "./choiceBuilder";
import type { App } from "obsidian";
import {
App,
ButtonComponent,
Setting,
TextComponent,
Expand All @@ -17,10 +17,10 @@ import type { FileViewMode } from "../../types/fileViewMode";
import { GenericTextSuggester } from "../suggesters/genericTextSuggester";
import { FormatSyntaxSuggester } from "../suggesters/formatSyntaxSuggester";
import { ExclusiveSuggester } from "../suggesters/exclusiveSuggester";
import type { fileExistsChoices } from "src/constants";
import {
fileExistsAppendToBottom,
fileExistsAppendToTop,
fileExistsChoices,
fileExistsDoNothing,
fileExistsIncrement,
fileExistsOverwriteFile,
Expand Down Expand Up @@ -86,7 +86,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
const formatDisplay: HTMLSpanElement = this.contentEl.createEl("span");
const displayFormatter: FileNameDisplayFormatter =
new FileNameDisplayFormatter(this.app);
(async () =>
void (async () =>
(formatDisplay.textContent = await displayFormatter.format(
this.choice.fileNameFormat.format
)))();
Expand Down Expand Up @@ -208,6 +208,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
deleteFolder: (folder: string) => {
this.choice.folder.folders =
this.choice.folder.folders.filter((f) => f !== folder);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
folderListEl.updateFolders(this.choice.folder.folders);
suggester.updateCurrentItems(this.choice.folder.folders);
},
Expand Down Expand Up @@ -240,6 +241,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
}

this.choice.folder.folders.push(input);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
folderListEl.updateFolders(this.choice.folder.folders);
folderInput.inputEl.value = "";

Expand Down
3 changes: 2 additions & 1 deletion src/gui/GenericCheckboxPrompt/genericCheckboxPrompt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, ButtonComponent, Modal, ToggleComponent } from "obsidian";
import type { App } from "obsidian";
import { ButtonComponent, Modal, ToggleComponent } from "obsidian";

export default class GenericCheckboxPrompt extends Modal {
private resolvePromise: (value: string[]) => void;
Expand Down
Loading

1 comment on commit 6a42f41

@vercel
Copy link

@vercel vercel bot commented on 6a42f41 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quickadd – ./

quickadd.obsidian.guide
quickadd-git-master-chrisbbh.vercel.app
quickadd-chrisbbh.vercel.app

Please sign in to comment.