From 7121d3a0ed861975938ebc2015582e1609835aa8 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Tue, 7 Mar 2023 14:38:02 +0100 Subject: [PATCH] fix: lint errors - add field to formatters & fix types --- src/formatters/completeFormatter.ts | 45 ++++++++++++--------- src/formatters/fileNameDisplayFormatter.ts | 9 +++++ src/formatters/formatDisplayFormatter.ts | 9 +++++ src/migrations/useQuickAddTemplateFolder.ts | 11 ++++- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/formatters/completeFormatter.ts b/src/formatters/completeFormatter.ts index 468e5a1..1a7b613 100644 --- a/src/formatters/completeFormatter.ts +++ b/src/formatters/completeFormatter.ts @@ -7,10 +7,11 @@ import { SingleMacroEngine } from "../engine/SingleMacroEngine"; import { SingleTemplateEngine } from "../engine/SingleTemplateEngine"; import { MarkdownView } from "obsidian"; import type { IChoiceExecutor } from "../IChoiceExecutor"; -import { FIELD_VAR_REGEX, INLINE_JAVASCRIPT_REGEX } from "../constants"; +import { INLINE_JAVASCRIPT_REGEX } from "../constants"; import { SingleInlineScriptEngine } from "../engine/SingleInlineScriptEngine"; import { MathModal } from "../gui/MathModal"; import InputPrompt from "../gui/InputPrompt"; +import GenericInputPrompt from "src/gui/GenericInputPrompt/GenericInputPrompt"; export class CompleteFormatter extends Formatter { private valueHeader: string; @@ -36,7 +37,7 @@ export class CompleteFormatter extends Formatter { output = await this.replaceValueInString(output); output = await this.replaceDateVariableInString(output); output = await this.replaceVariableInString(output); - output = await this.replaceFieldVarInString(output); + output = await this.replaceFieldVarInString(output); output = await this.replaceMathValueInString(output); return output; @@ -89,7 +90,9 @@ export class CompleteFormatter extends Formatter { } protected async promptForVariable(header?: string): Promise { - return await new InputPrompt().factory().Prompt(this.app, header as string); + return await new InputPrompt() + .factory() + .Prompt(this.app, header as string); } protected async promptForMathValue(): Promise { @@ -104,25 +107,29 @@ export class CompleteFormatter extends Formatter { ); } - protected async suggestForField(variableName: string) { - const suggestedValues: string[] = []; - for (const file of this.app.vault.getMarkdownFiles()) { - const cache = this.app.metadataCache.getFileCache(file); - const value = cache?.frontmatter?.[variableName]; - if(!value || typeof value == 'object') continue; - suggestedValues.push(value); - } - + protected async suggestForField(variableName: string) { + const suggestedValues: string[] = []; + for (const file of this.app.vault.getMarkdownFiles()) { + const cache = this.app.metadataCache.getFileCache(file); + const value = cache?.frontmatter?.[variableName]; + if (!value || typeof value == "object") continue; + suggestedValues.push(value); + } + if (suggestedValues.length === 0) { - return await GenericInputPrompt.Prompt(app, `Enter value for ${variableName}`, `No existing values were found in your vault.`); + return await GenericInputPrompt.Prompt( + app, + `Enter value for ${variableName}`, + `No existing values were found in your vault.` + ); } - return await GenericSuggester.Suggest( - this.app, - suggestedValues, - suggestedValues - ) - } + return await GenericSuggester.Suggest( + this.app, + suggestedValues, + suggestedValues + ); + } protected async getMacroValue(macroName: string): Promise { const macroEngine: SingleMacroEngine = new SingleMacroEngine( diff --git a/src/formatters/fileNameDisplayFormatter.ts b/src/formatters/fileNameDisplayFormatter.ts index f6611b4..a85a588 100644 --- a/src/formatters/fileNameDisplayFormatter.ts +++ b/src/formatters/fileNameDisplayFormatter.ts @@ -15,6 +15,7 @@ export class FileNameDisplayFormatter extends Formatter { output = await this.replaceValueInString(output); output = await this.replaceDateVariableInString(output); output = await this.replaceVariableInString(output); + output = await this.replaceFieldVarInString(output); return `File Name: ${output}`; } @@ -57,4 +58,12 @@ export class FileNameDisplayFormatter extends Formatter { protected async getSelectedText(): Promise { return "_selected_"; } + + protected async suggestForField(variableName: string) { + return Promise.resolve(``); + } + + protected async replaceFieldVarInString(input: string): Promise { + return Promise.resolve(`_field_`); + } } diff --git a/src/formatters/formatDisplayFormatter.ts b/src/formatters/formatDisplayFormatter.ts index 93a2493..eca359e 100644 --- a/src/formatters/formatDisplayFormatter.ts +++ b/src/formatters/formatDisplayFormatter.ts @@ -19,6 +19,7 @@ export class FormatDisplayFormatter extends Formatter { output = await this.replaceLinkToCurrentFileInString(output); output = await this.replaceMacrosInString(output); output = await this.replaceTemplateInString(output); + output = await this.replaceFieldVarInString(output); output = this.replaceLinebreakInString(output); return output; @@ -71,4 +72,12 @@ export class FormatDisplayFormatter extends Formatter { protected async getSelectedText(): Promise { return "_selected_"; } + + protected async suggestForField(variableName: string) { + return Promise.resolve(``); + } + + protected async replaceFieldVarInString(input: string): Promise { + return Promise.resolve(`_field_`); + } } diff --git a/src/migrations/useQuickAddTemplateFolder.ts b/src/migrations/useQuickAddTemplateFolder.ts index 0f06678..1a5b1c6 100644 --- a/src/migrations/useQuickAddTemplateFolder.ts +++ b/src/migrations/useQuickAddTemplateFolder.ts @@ -18,22 +18,29 @@ export default { if (obsidianTemplatesPlugin) { const obsidianTemplatesSettings = + //@ts-ignore obsidianTemplatesPlugin.instance.options; if (obsidianTemplatesSettings["folder"]) { plugin.settings.templateFolderPath = obsidianTemplatesSettings["folder"]; - log.logMessage("Migrated template folder path to Obsidian Templates' setting."); + log.logMessage( + "Migrated template folder path to Obsidian Templates' setting." + ); } } if (templaterPlugin) { const templaterSettings = templaterPlugin.settings; + //@ts-ignore if (templaterSettings["template_folder"]) { plugin.settings.templateFolderPath = + //@ts-ignore templaterSettings["template_folder"]; - log.logMessage("Migrated template folder path to Templaters setting."); + log.logMessage( + "Migrated template folder path to Templaters setting." + ); } } } catch (error) {