From bc6d18984856b4c81c5dbba19f39a264376346e5 Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 22 May 2024 11:10:35 +0200 Subject: [PATCH 1/4] use biome --- biome.json | 13 ++++ src/@types/i18next.d.ts | 2 +- src/GitHub/branch.ts | 18 ++--- src/GitHub/delete.ts | 20 ++--- src/GitHub/files.ts | 16 ++-- src/GitHub/upload.ts | 12 +-- src/commands/create_link.ts | 6 +- src/commands/file_menu/file.ts | 6 +- src/commands/file_menu/folder.ts | 6 +- src/commands/purge.ts | 8 +- src/commands/repository_validity.ts | 6 +- src/commands/set.ts | 4 +- src/commands/share/all_notes.ts | 8 +- src/commands/share/edited_notes.ts | 8 +- src/commands/share/new_notes.ts | 8 +- src/commands/share/unique_note.ts | 8 +- .../suggest_other_repo_commands_modal.ts | 12 ++- src/conversion/compiler/dataview.ts | 12 +-- src/conversion/compiler/embeds.ts | 22 +++--- src/conversion/compiler/excalidraw.ts | 2 +- src/conversion/file_path.ts | 38 ++++++---- src/conversion/find_and_replace_text.ts | 2 +- src/conversion/index.ts | 10 +-- src/conversion/links.ts | 8 +- src/i18n/i18next.ts | 12 +-- src/interfaces/constant.ts | 6 +- src/interfaces/enum.ts | 26 +++---- src/interfaces/index.ts | 8 +- src/interfaces/main.ts | 10 ++- src/interfaces/properties.ts | 6 +- src/interfaces/settings.ts | 4 +- src/main.ts | 29 ++++--- src/settings.ts | 76 +++++++++---------- src/settings/help.ts | 6 +- src/settings/migrate.ts | 28 +++---- src/settings/modals/import_export.ts | 16 ++-- src/settings/modals/list_changed.ts | 4 +- src/settings/modals/manage_repo.ts | 29 ++++--- src/settings/modals/popup.ts | 4 +- src/settings/modals/regex_edition.ts | 30 ++++---- src/settings/modals/token_path.ts | 4 +- src/settings/style.ts | 24 +++--- src/utils/data_validation_test.ts | 28 ++++--- src/utils/index.ts | 20 ++--- src/utils/parse_frontmatter.ts | 16 ++-- src/utils/status_bar.ts | 4 +- 46 files changed, 350 insertions(+), 295 deletions(-) diff --git a/biome.json b/biome.json index e7b4311e..871f3a1e 100644 --- a/biome.json +++ b/biome.json @@ -13,6 +13,19 @@ "noUselessCatch": "error", "noWith": "error" }, + "style": { + "noVar": "error", + "useFilenamingConvention": "error", + "useImportType": "error", + "useNamingConvention": { + "level": "warn", + "options": { + "strictCase": false + } + }, + "useTemplate": "warn", + "useConst": "error" + }, "correctness": { "noConstAssign": "error", "noConstantCondition": "error", diff --git a/src/@types/i18next.d.ts b/src/@types/i18next.d.ts index 1969a058..142e494f 100644 --- a/src/@types/i18next.d.ts +++ b/src/@types/i18next.d.ts @@ -1,4 +1,4 @@ -import { resources } from "src/i18n/i18next"; +import type { resources } from "src/i18n/i18next"; declare module "i18next" { interface CustomTypeOptions { diff --git a/src/GitHub/branch.ts b/src/GitHub/branch.ts index bbf3c8aa..18003b52 100644 --- a/src/GitHub/branch.ts +++ b/src/GitHub/branch.ts @@ -1,9 +1,9 @@ -import { Properties } from "@interfaces/main"; -import { Octokit } from "@octokit/core"; +import type { Properties } from "@interfaces/main"; +import type { Octokit } from "@octokit/core"; import i18next from "i18next"; import { Notice } from "obsidian"; import { FilesManagement } from "src/GitHub/files"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { logs, notif } from "src/utils"; export class GithubBranch extends FilesManagement { @@ -90,7 +90,7 @@ export class GithubBranch extends FilesManagement { async pullRequestOnRepo(prop: Properties): Promise { try { - const PR = await this.octokit.request("POST /repos/{owner}/{repo}/pulls", { + const pr = await this.octokit.request("POST /repos/{owner}/{repo}/pulls", { owner: prop.owner, repo: prop.repo, title: i18next.t("publish.branch.prMessage", { branchName: this.branchName }), @@ -98,17 +98,17 @@ export class GithubBranch extends FilesManagement { head: this.branchName, base: prop.branch, }); - return PR.data.number; + return pr.data.number; } catch (e) { logs({ settings: this.settings, e: true }, e); //trying to get the last open PR number try { - const PR = await this.octokit.request("GET /repos/{owner}/{repo}/pulls", { + const pr = await this.octokit.request("GET /repos/{owner}/{repo}/pulls", { owner: prop.owner, repo: prop.repo, state: "open", }); - return PR.data[0]?.number || 0; + return pr.data[0]?.number || 0; } catch (e) { // there is no open PR and impossible to create a new one notif( @@ -203,8 +203,8 @@ export class GithubBranch extends FilesManagement { try { const pullRequest = await this.pullRequestOnRepo(prop); if (prop.automaticallyMergePR && pullRequest !== 0) { - const PRSuccess = await this.mergePullRequestOnRepo(pullRequest, prop); - if (PRSuccess) { + const prSuccess = await this.mergePullRequestOnRepo(pullRequest, prop); + if (prSuccess) { await this.deleteBranchOnRepo(prop); return true; } diff --git a/src/GitHub/delete.ts b/src/GitHub/delete.ts index fc9bcef9..9156b3f8 100644 --- a/src/GitHub/delete.ts +++ b/src/GitHub/delete.ts @@ -1,26 +1,26 @@ import { - Deleted, + type Deleted, FIND_REGEX, FolderSettings, - GitHubPublisherSettings, - GithubRepo, - MonoRepoProperties, - Properties, + type GitHubPublisherSettings, + type GithubRepo, + type MonoRepoProperties, + type Properties, } from "@interfaces"; -import { Octokit } from "@octokit/core"; +import type { Octokit } from "@octokit/core"; import i18next from "i18next"; import { Base64 } from "js-base64"; import { - MetadataCache, + type MetadataCache, normalizePath, Notice, parseYaml, - TAbstractFile, + type TAbstractFile, TFile, TFolder, Vault, } from "obsidian"; -import { FilesManagement } from "src/GitHub/files"; +import type { FilesManagement } from "src/GitHub/files"; import { logs, notif, trimObject } from "src/utils"; import { isAttachment, verifyRateLimitAPI } from "src/utils/data_validation_test"; import { frontmatterSettingsRepository } from "src/utils/parse_frontmatter"; @@ -218,7 +218,7 @@ export async function filterGithubFile( isAttachment(file.file, settings.embed.unHandledObsidianExt); if ( (file.file.includes(defaultName) || - (behavior === FolderSettings.yaml && file.file.includes(root)) || + (behavior === FolderSettings.Yaml && file.file.includes(root)) || (attachmentFolder.length > 0 && file.file.includes(attachmentFolder))) && !excludedFileFromDelete(file.file, settings) && (enabledAttachments || file.file.match("md$")) diff --git a/src/GitHub/files.ts b/src/GitHub/files.ts index 1c951415..6572c284 100644 --- a/src/GitHub/files.ts +++ b/src/GitHub/files.ts @@ -1,4 +1,4 @@ -import { +import type { ConvertedLink, GithubRepo, LinkedNotes, @@ -6,12 +6,12 @@ import { PropertiesConversion, Repository, } from "@interfaces/main"; -import { Octokit } from "@octokit/core"; -import { EmbedCache, LinkCache, TFile, TFolder } from "obsidian"; -import { getAPI, Link } from "obsidian-dataview"; +import type { Octokit } from "@octokit/core"; +import { type EmbedCache, type LinkCache, TFile, TFolder } from "obsidian"; +import { getAPI, type Link } from "obsidian-dataview"; import { getImagePath, getReceiptFolder } from "src/conversion/file_path"; import Publisher from "src/GitHub/upload"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { logs } from "src/utils"; import { isAttachment, isShared } from "src/utils/data_validation_test"; import { @@ -37,18 +37,18 @@ export class FilesManagement extends Publisher { getSharedFiles(repo: Repository | null): TFile[] { const files = this.vault.getMarkdownFiles(); - const shared_File: TFile[] = []; + const sharedFile: TFile[] = []; for (const file of files) { try { const frontMatter = this.metadataCache.getCache(file.path)?.frontmatter; if (isShared(frontMatter, this.settings, file, repo)) { - shared_File.push(file); + sharedFile.push(file); } } catch (e) { logs({ settings: this.settings, e: true }, e); } } - return shared_File; + return sharedFile; } /** diff --git a/src/GitHub/upload.ts b/src/GitHub/upload.ts index e4c55a57..e5854739 100644 --- a/src/GitHub/upload.ts +++ b/src/GitHub/upload.ts @@ -1,4 +1,4 @@ -import { +import type { Deleted, GitHubPublisherSettings, MetadataExtractor, @@ -10,25 +10,25 @@ import { UploadedFiles, } from "@interfaces"; import { LOADING_ICON } from "@interfaces/icons"; -import { Octokit } from "@octokit/core"; +import type { Octokit } from "@octokit/core"; import i18next from "i18next"; import { Base64 } from "js-base64"; import { arrayBufferToBase64, - FrontMatterCache, - MetadataCache, + type FrontMatterCache, + type MetadataCache, normalizePath, Notice, TFile, TFolder, - Vault, + type Vault, } from "obsidian"; import { mainConverting } from "src/conversion"; import { convertToHTMLSVG } from "src/conversion/compiler/excalidraw"; import { getImagePath, getReceiptFolder } from "src/conversion/file_path"; import { deleteFromGithub } from "src/GitHub/delete"; import { FilesManagement } from "src/GitHub/files"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { logs, noticeMobile, notif, notifError } from "src/utils"; import { checkEmptyConfiguration, diff --git a/src/commands/create_link.ts b/src/commands/create_link.ts index f7fd1d7e..8ef984a8 100644 --- a/src/commands/create_link.ts +++ b/src/commands/create_link.ts @@ -1,7 +1,7 @@ -import { MultiRepoProperties, Repository } from "@interfaces"; +import type { MultiRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, Notice } from "obsidian"; -import GithubPublisher from "src/main"; +import { type Command, Notice } from "obsidian"; +import type GithubPublisher from "src/main"; import { createLink } from "src/utils"; import { isShared } from "src/utils/data_validation_test"; import { frontmatterFromFile, getProperties } from "src/utils/parse_frontmatter"; diff --git a/src/commands/file_menu/file.ts b/src/commands/file_menu/file.ts index ae26e633..ecdf54dd 100644 --- a/src/commands/file_menu/file.ts +++ b/src/commands/file_menu/file.ts @@ -1,9 +1,9 @@ -import { Repository } from "@interfaces"; +import type { Repository } from "@interfaces"; import i18next from "i18next"; -import { Menu, MenuItem, Platform, TFile } from "obsidian"; +import { type Menu, type MenuItem, Platform, type TFile } from "obsidian"; import { shareOneNote } from "src/commands"; import { ChooseRepoToRun } from "src/commands/suggest_other_repo_commands_modal"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { defaultRepo, getRepoSharedKey, diff --git a/src/commands/file_menu/folder.ts b/src/commands/file_menu/folder.ts index 362cef31..da31441a 100644 --- a/src/commands/file_menu/folder.ts +++ b/src/commands/file_menu/folder.ts @@ -1,9 +1,9 @@ -import { MonoRepoProperties, Repository } from "@interfaces"; +import type { MonoRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Menu, MenuItem, Platform, TFolder } from "obsidian"; +import { type Menu, type MenuItem, Platform, type TFolder } from "obsidian"; import { shareAllMarkedNotes } from "src/commands"; import { ChooseRepoToRun } from "src/commands/suggest_other_repo_commands_modal"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { defaultRepo, getRepoSharedKey, diff --git a/src/commands/purge.ts b/src/commands/purge.ts index 730e01d8..25e8f5b5 100644 --- a/src/commands/purge.ts +++ b/src/commands/purge.ts @@ -1,9 +1,9 @@ -import { MonoRepoProperties, Repository } from "@interfaces"; +import type { MonoRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, Notice } from "obsidian"; -import { GithubBranch } from "src/GitHub/branch"; +import { type Command, Notice } from "obsidian"; +import type { GithubBranch } from "src/GitHub/branch"; import { deleteFromGithub } from "src/GitHub/delete"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { ListChangedFiles } from "src/settings/modals/list_changed"; import { notif } from "src/utils"; import { checkRepositoryValidityWithProperties } from "src/utils/data_validation_test"; diff --git a/src/commands/repository_validity.ts b/src/commands/repository_validity.ts index f5d99cdb..108da9ed 100644 --- a/src/commands/repository_validity.ts +++ b/src/commands/repository_validity.ts @@ -1,7 +1,7 @@ -import { Repository } from "@interfaces"; +import type { Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, Notice } from "obsidian"; -import GithubPublisher from "src/main"; +import { type Command, Notice } from "obsidian"; +import type GithubPublisher from "src/main"; import { checkRepositoryValidity } from "src/utils/data_validation_test"; /** diff --git a/src/commands/set.ts b/src/commands/set.ts index 6a36fbb7..42c6d613 100644 --- a/src/commands/set.ts +++ b/src/commands/set.ts @@ -1,6 +1,6 @@ import i18next from "i18next"; -import { Command, TFile } from "obsidian"; -import GithubPublisher from "src/main"; +import { type Command, TFile } from "obsidian"; +import type GithubPublisher from "src/main"; export function refreshOpenedSet(plugin: GithubPublisher) { const findRepo = (file: TFile | null) => { diff --git a/src/commands/share/all_notes.ts b/src/commands/share/all_notes.ts index 6a64c919..9f74f4f9 100644 --- a/src/commands/share/all_notes.ts +++ b/src/commands/share/all_notes.ts @@ -1,10 +1,10 @@ -import { MonoRepoProperties, Repository, UploadedFiles } from "@interfaces"; +import type { MonoRepoProperties, Repository, UploadedFiles } from "@interfaces"; import { ERROR_ICONS } from "@interfaces/icons"; import i18next from "i18next"; -import { Command, FrontMatterCache, Notice, Platform, TFile } from "obsidian"; -import { GithubBranch } from "src/GitHub/branch"; +import { type Command, type FrontMatterCache, Notice, Platform, type TFile } from "obsidian"; +import type { GithubBranch } from "src/GitHub/branch"; import { deleteFromGithub } from "src/GitHub/delete"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { ListChangedFiles } from "src/settings/modals/list_changed"; import { createListEdited, diff --git a/src/commands/share/edited_notes.ts b/src/commands/share/edited_notes.ts index 4b3948a6..7e409bf8 100644 --- a/src/commands/share/edited_notes.ts +++ b/src/commands/share/edited_notes.ts @@ -1,8 +1,8 @@ -import { MonoRepoProperties, Repository } from "@interfaces"; +import type { MonoRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, Notice, TFile } from "obsidian"; -import { GithubBranch } from "src/GitHub/branch"; -import GithubPublisher from "src/main"; +import { type Command, Notice, type TFile } from "obsidian"; +import type { GithubBranch } from "src/GitHub/branch"; +import type GithubPublisher from "src/main"; import { checkRepositoryValidityWithProperties } from "src/utils/data_validation_test"; import { frontmatterSettingsRepository, diff --git a/src/commands/share/new_notes.ts b/src/commands/share/new_notes.ts index e069e533..009acbc2 100644 --- a/src/commands/share/new_notes.ts +++ b/src/commands/share/new_notes.ts @@ -1,9 +1,9 @@ -import { MonoRepoProperties, Repository } from "@interfaces"; +import type { MonoRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, Notice } from "obsidian"; +import { type Command, Notice } from "obsidian"; import { shareAllMarkedNotes } from "src/commands"; -import { GithubBranch } from "src/GitHub/branch"; -import GithubPublisher from "src/main"; +import type { GithubBranch } from "src/GitHub/branch"; +import type GithubPublisher from "src/main"; import { checkRepositoryValidityWithProperties } from "src/utils/data_validation_test"; import { frontmatterSettingsRepository, diff --git a/src/commands/share/unique_note.ts b/src/commands/share/unique_note.ts index fec49513..52c8307f 100644 --- a/src/commands/share/unique_note.ts +++ b/src/commands/share/unique_note.ts @@ -1,8 +1,8 @@ -import { MultiRepoProperties, Repository } from "@interfaces"; +import type { MultiRepoProperties, Repository } from "@interfaces"; import i18next from "i18next"; -import { Command, FrontMatterCache, Notice, Platform, TFile } from "obsidian"; -import { GithubBranch } from "src/GitHub/branch"; -import GithubPublisher from "src/main"; +import { type Command, type FrontMatterCache, Notice, Platform, type TFile } from "obsidian"; +import type { GithubBranch } from "src/GitHub/branch"; +import type GithubPublisher from "src/main"; import { ListChangedFiles } from "src/settings/modals/list_changed"; import { createLink, diff --git a/src/commands/suggest_other_repo_commands_modal.ts b/src/commands/suggest_other_repo_commands_modal.ts index ca295c15..3546d9a1 100644 --- a/src/commands/suggest_other_repo_commands_modal.ts +++ b/src/commands/suggest_other_repo_commands_modal.ts @@ -1,6 +1,10 @@ -import { FolderSettings, GitHubPublisherSettings, Repository } from "@interfaces"; +import { + FolderSettings, + type GitHubPublisherSettings, + type Repository, +} from "@interfaces"; import i18next from "i18next"; -import { App, FuzzySuggestModal } from "obsidian"; +import { type App, FuzzySuggestModal } from "obsidian"; import { createLinkOnActiveFile, deleteCommands, @@ -11,7 +15,7 @@ import { uploadAllNotes, uploadNewNotes, } from "src/commands"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { defaultRepo } from "src/utils/data_validation_test"; interface GithubPublisherCommands { @@ -180,7 +184,7 @@ export class SuggestOtherRepoCommandsModal extends FuzzySuggestModal { if (settings.embed.bake?.textAfter) { - let textAfter = await changeURL( + let textAfter = await changeUrl( settings.embed.bake?.textAfter, properties, linked, @@ -200,7 +200,7 @@ export async function bakeEmbeds( replacement = `${replacement}${newLine}${textAfter}`; } if (settings.embed.bake?.textBefore) { - let textBefore = await changeURL( + let textBefore = await changeUrl( settings.embed.bake?.textBefore, properties, linked, @@ -241,7 +241,7 @@ export async function bakeEmbeds( * @param linkedNotes {LinkedNotes[]} The linked notes embedded in the file * @returns {Promise} */ -async function changeURL( +async function changeUrl( textToAdd: string, properties: MultiProperties, linked: TFile, diff --git a/src/conversion/compiler/excalidraw.ts b/src/conversion/compiler/excalidraw.ts index 81bfe703..ee187fcf 100644 --- a/src/conversion/compiler/excalidraw.ts +++ b/src/conversion/compiler/excalidraw.ts @@ -1,4 +1,4 @@ -import { App, TFile } from "obsidian"; +import type { App, TFile } from "obsidian"; export async function convertToHTMLSVG(file: TFile, app: App) { try { diff --git a/src/conversion/file_path.ts b/src/conversion/file_path.ts index 8dd1a544..fdcebb90 100644 --- a/src/conversion/file_path.ts +++ b/src/conversion/file_path.ts @@ -1,16 +1,22 @@ import { FIND_REGEX, FolderSettings, - GitHubPublisherSettings, - LinkedNotes, - MultiProperties, - Properties, - PropertiesConversion, - Repository, + type GitHubPublisherSettings, + type LinkedNotes, + type MultiProperties, + type Properties, + type PropertiesConversion, + type Repository, } from "@interfaces"; -import { FrontMatterCache, normalizePath, TFile, TFolder, Vault } from "obsidian"; +import { + type FrontMatterCache, + normalizePath, + type TFile, + TFolder, + type Vault, +} from "obsidian"; import { createRegexFromText } from "src/conversion/find_and_replace_text"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { logs } from "src/utils"; import { checkIfRepoIsInAnother, @@ -183,7 +189,7 @@ export async function createRelativePath( * @return {string} original file name or index.md */ -function folderNoteIndexOBS( +function folderNoteIndexObs( file: TFile, vault: Vault, settings: GitHubPublisherSettings, @@ -218,7 +224,7 @@ function createObsidianPath( fileName: string, prop?: Properties ): string { - fileName = folderNoteIndexOBS(file, vault, settings, fileName); + fileName = folderNoteIndexObs(file, vault, settings, fileName); const defaultFolder = prop?.path?.defaultName && prop.path.defaultName.length > 0 @@ -244,7 +250,7 @@ function createObsidianPath( * @returns {string} renamed file name or original file name */ -function folderNoteIndexYAML( +function folderNoteIndexYaml( fileName: string, frontmatter: FrontMatterCache | undefined | null, settings: GitHubPublisherSettings, @@ -279,7 +285,7 @@ function createFrontmatterPath( const uploadSettings = settings.upload; const folderCategory = getCategory(frontmatter, settings, prop?.path); const path = prop?.path; - const folderNote = folderNoteIndexYAML(fileName, frontmatter, settings, prop); + const folderNote = folderNoteIndexYaml(fileName, frontmatter, settings, prop); const root = path?.rootFolder && path.rootFolder.length > 0 ? path.rootFolder @@ -336,7 +342,7 @@ export function regexOnFileName( export function regexOnPath(path: string, settings: GitHubPublisherSettings): string { const uploadSettings = settings.upload; if ( - uploadSettings.behavior === FolderSettings.fixed || + uploadSettings.behavior === FolderSettings.Fixed || uploadSettings.replacePath.length === 0 ) return path; @@ -410,11 +416,11 @@ export function getReceiptFolder( return normalizePath(editedFileName); } return normalizePath(`${frontmatterPath}/${editedFileName}`); - } else if (targetRepo.path?.type === FolderSettings.yaml) { + } else if (targetRepo.path?.type === FolderSettings.Yaml) { return normalizePath( createFrontmatterPath(settings, frontmatter, fileName, targetRepo) ); - } else if (targetRepo.path?.type === FolderSettings.obsidian) { + } else if (targetRepo.path?.type === FolderSettings.Obsidian) { return normalizePath( createObsidianPath(file, settings, vault, fileName, targetRepo) ); @@ -489,7 +495,7 @@ function createImagePath( return result; } if (settings.embed.useObsidianFolder) { - if (behavior === FolderSettings.yaml) { + if (behavior === FolderSettings.Yaml) { result.path = rootFolder.length > 0 ? normalizePath(`${rootFolder}/${filePath}`) : filePath; } else { diff --git a/src/conversion/find_and_replace_text.ts b/src/conversion/find_and_replace_text.ts index 889e6ea2..faebbfb4 100644 --- a/src/conversion/find_and_replace_text.ts +++ b/src/conversion/find_and_replace_text.ts @@ -1,4 +1,4 @@ -import { FIND_REGEX, GitHubPublisherSettings } from "@interfaces"; +import { FIND_REGEX, type GitHubPublisherSettings } from "@interfaces"; import { escapeRegex } from "src/conversion/links"; import { logs } from "src/utils"; diff --git a/src/conversion/index.ts b/src/conversion/index.ts index 1ca83633..ae80e39b 100644 --- a/src/conversion/index.ts +++ b/src/conversion/index.ts @@ -1,4 +1,4 @@ -import { +import type { GitHubPublisherSettings, LinkedNotes, MultiProperties, @@ -6,19 +6,19 @@ import { } from "@interfaces"; import i18next from "i18next"; import { - FrontMatterCache, + type FrontMatterCache, getFrontMatterInfo, - MetadataCache, + type MetadataCache, Notice, parseFrontMatterTags, parseYaml, stringifyYaml, - TFile, + type TFile, } from "obsidian"; import { convertDataviewQueries } from "src/conversion/compiler/dataview"; import { bakeEmbeds, convertInlineDataview } from "src/conversion/compiler/embeds"; import { convertToInternalGithub, convertWikilinks } from "src/conversion/links"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { notif } from "src/utils"; import { isFolderNote } from "src/utils/data_validation_test"; diff --git a/src/conversion/links.ts b/src/conversion/links.ts index fe02cad1..1ba69052 100644 --- a/src/conversion/links.ts +++ b/src/conversion/links.ts @@ -1,10 +1,10 @@ -import { +import type { GitHubPublisherSettings, LinkedNotes, MultiProperties, PropertiesConversion, } from "@interfaces"; -import { FrontMatterCache, TFile } from "obsidian"; +import type { FrontMatterCache, TFile } from "obsidian"; import slugify from "slugify"; import { createRelativePath, @@ -273,9 +273,9 @@ function createMarkdownLinks( : `${fileName.replace(/#.*/, "").trim()}.md`; const anchorMatch = fileName.match(/(#.*)/); let anchor = anchorMatch ? anchorMatch[0] : null; - const encodedURI = encodeURI(markdownName); + const encodedUri = encodeURI(markdownName); anchor = slugifyAnchor(anchor, settings); - return `${isEmbed}[${altLink}](${encodedURI}${anchor})`; + return `${isEmbed}[${altLink}](${encodedUri}${anchor})`; } /** diff --git a/src/i18n/i18next.ts b/src/i18n/i18next.ts index cd1ee573..25bf810f 100644 --- a/src/i18n/i18next.ts +++ b/src/i18n/i18next.ts @@ -18,7 +18,7 @@ import nl from "src/i18n/locales/nl.json"; import no from "src/i18n/locales/no.json"; import pl from "src/i18n/locales/pl.json"; import pt from "src/i18n/locales/pt.json"; -import ptBR from "src/i18n/locales/pt-BR.json"; +import ptBr from "src/i18n/locales/pt-BR.json"; import ro from "src/i18n/locales/ro.json"; import ru from "src/i18n/locales/ru.json"; import sr from "src/i18n/locales/sr.json"; @@ -26,8 +26,8 @@ import sv from "src/i18n/locales/sv.json"; import tr from "src/i18n/locales/tr.json"; import uk from "src/i18n/locales/uk.json"; import vi from "src/i18n/locales/vi.json"; -import zhCN from "src/i18n/locales/zh-CN.json"; -import zhTW from "src/i18n/locales/zh-TW.json"; +import zhCn from "src/i18n/locales/zh-CN.json"; +import zhTw from "src/i18n/locales/zh-TW.json"; export const resources = { en: { translation: en }, @@ -49,7 +49,7 @@ export const resources = { no: { translation: no }, pl: { translation: pl }, pt: { translation: pt }, - "pt-BR": { translation: ptBR }, + "pt-BR": { translation: ptBr }, ru: { translation: ru }, ro: { translation: ro }, sr: { translation: sr }, @@ -57,8 +57,8 @@ export const resources = { tr: { translation: tr }, uk: { translation: uk }, vi: { translation: vi }, - "zh-TW": { translation: zhTW }, - "zh-CN": { translation: zhCN }, + "zh-TW": { translation: zhTw }, + "zh-CN": { translation: zhCn }, } as const; export const translationLanguage = Object.keys(resources).find( diff --git a/src/interfaces/constant.ts b/src/interfaces/constant.ts index 7d7cd314..cc3e0473 100644 --- a/src/interfaces/constant.ts +++ b/src/interfaces/constant.ts @@ -1,5 +1,5 @@ import { FolderSettings, GithubTiersVersion } from "src/interfaces/enum"; -import { GitHubPublisherSettings } from "src/interfaces/main"; +import type { GitHubPublisherSettings } from "src/interfaces/main"; /** Find a regex encapsuled in // */ export const FIND_REGEX = /^\/(.*)\/[igmsuy]*$/; @@ -22,7 +22,7 @@ export const DEFAULT_SETTINGS: Partial = { }, tokenPath: TOKEN_PATH, api: { - tiersForApi: GithubTiersVersion.free, + tiersForApi: GithubTiersVersion.Free, hostname: "", }, workflow: { @@ -34,7 +34,7 @@ export const DEFAULT_SETTINGS: Partial = { rateLimit: 0, }, upload: { - behavior: FolderSettings.fixed, + behavior: FolderSettings.Fixed, defaultName: "", rootFolder: "", yamlFolderKey: "", diff --git a/src/interfaces/enum.ts b/src/interfaces/enum.ts index 5ea8cb40..50ed4a7f 100644 --- a/src/interfaces/enum.ts +++ b/src/interfaces/enum.ts @@ -5,17 +5,17 @@ * - `title` : replace the title of the file */ export enum TypeOfEditRegex { - path = "path", - title = "title", + Path = "path", + Title = "title", } export enum EnumbSettingsTabId { - github = "github-configuration", - upload = "upload-configuration", - text = "text-conversion", - embed = "embed-configuration", - plugin = "plugin-settings", - help = "help", + Github = "github-configuration", + Upload = "upload-configuration", + Text = "text-conversion", + Embed = "embed-configuration", + Plugin = "plugin-settings", + Help = "help", } /** @@ -24,11 +24,11 @@ export enum EnumbSettingsTabId { */ export enum FolderSettings { /** Use YAML frontmatter for settings the path */ - yaml = "yaml", + Yaml = "yaml", /** Use the obsidian tree */ - obsidian = "obsidian", + Obsidian = "obsidian", /** Use a fixed folder and send all in it */ - fixed = "fixed", + Fixed = "fixed", } /** @@ -36,6 +36,6 @@ export enum FolderSettings { * @description Allow to set a value for the github tiers */ export enum GithubTiersVersion { - free = "Github Free/Pro/Team (default)", - entreprise = "Enterprise", + Free = "Github Free/Pro/Team (default)", + Entreprise = "Enterprise", } diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index ade2a38c..16e0ae13 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -7,12 +7,12 @@ import { GithubTiersVersion, TypeOfEditRegex, } from "src/interfaces/enum"; -import { +import type { Deleted, ListEditedFiles, UploadedFiles, } from "src/interfaces/list_edited_files"; -import { +import type { GitHubPublisherSettings, GithubRepo, LinkedNotes, @@ -25,13 +25,13 @@ import { SetRepositoryFrontmatter, TextCleaner, } from "src/interfaces/main"; -import { +import type { MonoProperties, MonoRepoProperties, MultiProperties, MultiRepoProperties, } from "src/interfaces/properties"; -import { MetadataExtractor } from "src/interfaces/settings"; +import type { MetadataExtractor } from "src/interfaces/settings"; import { ERROR_ICONS, FOUND_ATTACHMENTS, HOURGLASS_ICON, SUCCESS_ICON } from "./icons"; diff --git a/src/interfaces/main.ts b/src/interfaces/main.ts index 15c22a3a..6c947cb3 100644 --- a/src/interfaces/main.ts +++ b/src/interfaces/main.ts @@ -1,7 +1,7 @@ -import { FrontMatterCache, TFile } from "obsidian"; +import type { FrontMatterCache, TFile } from "obsidian"; -import { EnumbSettingsTabId, FolderSettings, TypeOfEditRegex } from "./enum"; -import { +import type { EnumbSettingsTabId, FolderSettings, TypeOfEditRegex } from "./enum"; +import type { Api, Conversion, CopyLink, @@ -47,6 +47,7 @@ export interface Repository { /** * If the PR should be automatically merged */ + automaticallyMergePR: boolean; /** * if the validity of the repository was checked and valide @@ -99,7 +100,7 @@ export interface GitHubPublisherSettings { /** * Save the tabs id when the settings was closed, pretty useful when quick tests are done */ - tabsID?: EnumbSettingsTabId; + tabsId?: EnumbSettingsTabId; /** * GitHub settings for the default repository */ @@ -266,6 +267,7 @@ export interface Properties { /** commitMsg if the default is not okay for this repo */ commitMsg: string; /** Automatically merge the PR */ + // biome-ignore lint/style/useNamingConvention: It's a type definition, not a variable automaticallyMergePR: boolean; /** If the repository was checked */ verifiedRepo?: boolean; diff --git a/src/interfaces/properties.ts b/src/interfaces/properties.ts index a799b565..b7ffa059 100644 --- a/src/interfaces/properties.ts +++ b/src/interfaces/properties.ts @@ -1,6 +1,6 @@ -import { FrontMatterCache } from "obsidian"; -import { Properties, PropertiesConversion, Repository } from "src/interfaces/main"; -import GithubPublisher from "src/main"; +import type { FrontMatterCache } from "obsidian"; +import type { Properties, PropertiesConversion, Repository } from "src/interfaces/main"; +import type GithubPublisher from "src/main"; /** * @interface MultiProperties diff --git a/src/interfaces/settings.ts b/src/interfaces/settings.ts index b2f05d3e..9fa3c286 100644 --- a/src/interfaces/settings.ts +++ b/src/interfaces/settings.ts @@ -1,5 +1,5 @@ -import { FolderSettings, GithubTiersVersion } from "src/interfaces/enum"; -import { +import type { FolderSettings, GithubTiersVersion } from "src/interfaces/enum"; +import type { OverrideAttachments, RegexReplace, Repository, diff --git a/src/main.ts b/src/main.ts index 7ce7fd86..088ecfa1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,14 +1,21 @@ import { DEFAULT_SETTINGS, - GitHubPublisherSettings, + type GitHubPublisherSettings, GithubTiersVersion, - Repository, - SetRepositoryFrontmatter, + type Repository, + type SetRepositoryFrontmatter, } from "@interfaces"; import { Octokit } from "@octokit/core"; import dedent from "dedent"; import i18next from "i18next"; -import { FrontMatterCache, Menu, Plugin, TAbstractFile, TFile, TFolder } from "obsidian"; +import { + type FrontMatterCache, + type Menu, + Plugin, + type TAbstractFile, + TFile, + TFolder, +} from "obsidian"; import { checkRepositoryValidityCallback, createLinkCallback, @@ -27,7 +34,7 @@ import { getTitleField, regexOnFileName } from "src/conversion/file_path"; import { GithubBranch } from "src/GitHub/branch"; import { resources, translationLanguage } from "src/i18n/i18next"; import { GithubPublisherSettingsTab } from "src/settings"; -import { migrateSettings, OldSettings } from "src/settings/migrate"; +import { migrateSettings, type OldSettings } from "src/settings/migrate"; import { createTokenPath, monkeyPatchConsole, notif } from "src/utils"; import { checkRepositoryValidity, @@ -80,11 +87,11 @@ export default class GithubPublisher extends Plugin { const allCommands = this.app.commands.listCommands(); for (const command of allCommands) { if (command.id.startsWith("obsidian-mkdocs-publisher")) { - const publisherCMDsName = command.id + const publisherCmDsName = command.id .replace("obsidian-mkdocs-publisher:", "") .split("-"); //repo will be the last element of the array - const repoCmd = publisherCMDsName[publisherCMDsName.length - 1]; + const repoCmd = publisherCmDsName[publisherCmDsName.length - 1]; if (repoCmd.startsWith("K") && repo.smartKey === repoCmd.replace("K", "")) { this.app.commands.removeCommand(command.id); } @@ -148,9 +155,9 @@ export default class GithubPublisher extends Plugin { try { const tokenFile = await this.app.vault.adapter.read(`${tokenPath}`); if (tokenPath.endsWith(".json")) { - const tokenJSON = JSON.parse(tokenFile); - const defaultToken = tokenJSON.GITHUB_PUBLISHER_TOKEN; - if (repo) return tokenJSON.GITHUB_PUBLISHER_REPOS?.[repo] ?? defaultToken; + const tokenJson = JSON.parse(tokenFile); + const defaultToken = tokenJson.GITHUB_PUBLISHER_TOKEN; + if (repo) return tokenJson.GITHUB_PUBLISHER_REPOS?.[repo] ?? defaultToken; return defaultToken; } if (tokenFile) { @@ -183,7 +190,7 @@ export default class GithubPublisher extends Plugin { const apiSettings = this.settings.github.api; const token = await this.loadToken(repo); const octokit = - apiSettings.tiersForApi === GithubTiersVersion.entreprise && + apiSettings.tiersForApi === GithubTiersVersion.Entreprise && apiSettings.hostname.length > 0 ? new Octokit({ baseUrl: `${apiSettings.hostname}/api/v3`, diff --git a/src/settings.ts b/src/settings.ts index cdd03639..37367849 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,13 +1,13 @@ import { EnumbSettingsTabId, FolderSettings, - GitHubPublisherSettings, + type GitHubPublisherSettings, GithubTiersVersion, - Repository, + type Repository, } from "@interfaces"; import i18next from "i18next"; -import { App, Notice, PluginSettingTab, setIcon, Setting } from "obsidian"; -import GithubPublisherPlugin from "src/main"; +import { type App, Notice, PluginSettingTab, setIcon, Setting } from "obsidian"; +import type GithubPublisherPlugin from "src/main"; import { help, KeyBasedOnSettings, @@ -57,16 +57,16 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { const { containerEl } = this; containerEl.empty(); containerEl.addClass("github-publisher"); - const defaultTabId = EnumbSettingsTabId.github; - let savedId = this.settings.tabsID ?? defaultTabId; + const defaultTabId = EnumbSettingsTabId.Github; + let savedId = this.settings.tabsId ?? defaultTabId; if (this.settings.plugin.saveTabId != undefined && !this.settings.plugin.saveTabId) { //real false - this.settings.tabsID = defaultTabId; + this.settings.tabsId = defaultTabId; savedId = defaultTabId; this.plugin.saveSettings(); } - const PUBLISHER_TABS = { + const publisherTabs = { "github-configuration": { name: i18next.t("settings.github.title"), icon: "cloud", @@ -125,7 +125,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { cls: "settings-tab-bar", }); - for (const [tabID, tabInfo] of Object.entries(PUBLISHER_TABS)) { + for (const [tabId, tabInfo] of Object.entries(publisherTabs)) { const tabEl = tabBar.createEl("div", { cls: "settings-tab", }); @@ -137,14 +137,14 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { cls: "settings-tab-name", text: tabInfo.name, }); - if (tabID === savedId) tabEl.addClass("settings-tab-active"); + if (tabId === savedId) tabEl.addClass("settings-tab-active"); tabEl.addEventListener("click", async () => { // @ts-ignore for (const tabEl of tabBar.children) tabEl.removeClass("settings-tab-active"); tabEl.addClass("settings-tab-active"); - this.renderSettingsPage(tabID); + this.renderSettingsPage(tabId); }); } this.settingsPage = containerEl.createEl("div", { @@ -159,7 +159,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { */ async renderSettingsPage(tabId: string | EnumbSettingsTabId) { if (this.settings.plugin.saveTabId || this.settings.plugin.saveTabId === undefined) { - this.settings.tabsID = tabId as EnumbSettingsTabId; + this.settings.tabsId = tabId as EnumbSettingsTabId; await this.plugin.saveSettings(); } this.settingsPage.empty(); @@ -196,21 +196,21 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .addDropdown((dropdown) => { dropdown .addOption( - GithubTiersVersion.free, + GithubTiersVersion.Free, i18next.t("settings.github.apiType.dropdown.free") ) .addOption( - GithubTiersVersion.entreprise, + GithubTiersVersion.Entreprise, i18next.t("settings.github.apiType.dropdown.enterprise") ) .setValue(githubSettings.api.tiersForApi) .onChange(async (value) => { githubSettings.api.tiersForApi = value as GithubTiersVersion; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.github); + this.renderSettingsPage(EnumbSettingsTabId.Github); }); }); - if (githubSettings.api.tiersForApi === GithubTiersVersion.entreprise) { + if (githubSettings.api.tiersForApi === GithubTiersVersion.Entreprise) { new Setting(this.settingsPage) .setName(i18next.t("settings.github.apiType.hostname.title")) .setDesc(i18next.t("settings.github.apiType.hostname.desc")) @@ -250,8 +250,8 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); - const desc_ghToken = document.createDocumentFragment(); - desc_ghToken.createEl("span", undefined, (span) => { + const descGhToken = document.createDocumentFragment(); + descGhToken.createEl("span", undefined, (span) => { span.innerText = i18next.t("settings.github.ghToken.desc"); span.createEl("a", undefined, (link) => { link.innerText = `${i18next.t("common.here")}.`; @@ -260,7 +260,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { }); const tokenSettings = new Setting(this.settingsPage) .setName(i18next.t("common.ghToken")) - .setDesc(desc_ghToken) + .setDesc(descGhToken) .addText(async (text) => { const decryptedToken: string = await this.plugin.loadToken(); text @@ -315,7 +315,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { toggle.setValue(githubSettings.dryRun.enable).onChange(async (value) => { githubSettings.dryRun.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.github); + this.renderSettingsPage(EnumbSettingsTabId.Github); }) ); @@ -438,12 +438,12 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { this.plugin ); await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); }); }); const defaultFolder = - uploadSettings.behavior === FolderSettings.yaml + uploadSettings.behavior === FolderSettings.Yaml ? { desc: i18next.t("settings.upload.defaultFolder.desc"), title: i18next.t("settings.upload.defaultFolder.title"), @@ -514,7 +514,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .onChange(async (value) => { uploadSettings.frontmatterTitle.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); }); }); if (uploadSettings.frontmatterTitle.enable) { @@ -530,7 +530,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { } const desc = - uploadSettings.behavior === FolderSettings.fixed + uploadSettings.behavior === FolderSettings.Fixed ? i18next.t("settings.upload.regexFilePathTitle.title.titleOnly") : i18next.t("settings.upload.regexFilePathTitle.title.FolderPathTitle"); @@ -540,7 +540,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .addButton((button) => { button.setIcon("pencil").onClick(async () => { let allRegex = uploadSettings.replaceTitle; - if (uploadSettings.behavior !== FolderSettings.fixed) { + if (uploadSettings.behavior !== FolderSettings.Fixed) { allRegex = allRegex.concat(uploadSettings.replacePath); } new ModalRegexFilePathName( @@ -567,7 +567,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { toggle.setValue(uploadSettings.folderNote.enable).onChange(async (value) => { uploadSettings.folderNote.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); }); }); @@ -589,7 +589,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .onChange(async (value) => { uploadSettings.folderNote.addTitle.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); }); }); if (uploadSettings.folderNote.addTitle.enable) { @@ -642,11 +642,11 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { ) new AutoCleanPopup(this.app, this.settings, (result) => { uploadSettings.autoclean.enable = result; - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); }).open(); else uploadSettings.autoclean.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.upload); + this.renderSettingsPage(EnumbSettingsTabId.Upload); this.plugin.cleanOldCommands(); await this.plugin.chargeAllCommands(null, this.plugin); }); @@ -893,7 +893,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { toggle.setValue(embedSettings.attachments).onChange(async (value) => { embedSettings.attachments = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.embed); + this.renderSettingsPage(EnumbSettingsTabId.Embed); }); }); @@ -907,7 +907,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .onChange(async (value) => { embedSettings.useObsidianFolder = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.embed); + this.renderSettingsPage(EnumbSettingsTabId.Embed); }); }); if (!embedSettings.useObsidianFolder) { @@ -1108,7 +1108,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { }; if (value) this.settings.conversion.links.internal = true; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.plugin); + this.renderSettingsPage(EnumbSettingsTabId.Plugin); }) ); if (!pluginSettings.shareAll || !pluginSettings.shareAll.enable) { @@ -1198,7 +1198,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { toggle.setValue(pluginSettings.copyLink.enable).onChange(async (value) => { pluginSettings.copyLink.enable = value; await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.plugin); + this.renderSettingsPage(EnumbSettingsTabId.Plugin); }) ); @@ -1275,7 +1275,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { replacement: "", }); await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.plugin); + this.renderSettingsPage(EnumbSettingsTabId.Plugin); }); }); @@ -1312,7 +1312,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { (item) => item !== apply ); await this.plugin.saveSettings(); - this.renderSettingsPage(EnumbSettingsTabId.plugin); + this.renderSettingsPage(EnumbSettingsTabId.Plugin); }); }); } @@ -1347,9 +1347,9 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { .addToggle((toggle) => toggle.setValue(pluginSettings.saveTabId ?? true).onChange(async (value) => { pluginSettings.saveTabId = value; - this.settings.tabsID = value - ? EnumbSettingsTabId.plugin - : EnumbSettingsTabId.github; + this.settings.tabsId = value + ? EnumbSettingsTabId.Plugin + : EnumbSettingsTabId.Github; await this.plugin.saveSettings(); }) ); diff --git a/src/settings/help.ts b/src/settings/help.ts index ea9895af..a7d0a5ef 100644 --- a/src/settings/help.ts +++ b/src/settings/help.ts @@ -1,4 +1,4 @@ -import { FolderSettings, GitHubPublisherSettings } from "@interfaces"; +import { FolderSettings, type GitHubPublisherSettings } from "@interfaces"; import i18next from "i18next"; import { normalizePath } from "obsidian"; import { regexOnPath } from "src/conversion/file_path"; @@ -29,7 +29,7 @@ function spanString(text: string, code: DocumentFragment): HTMLElement { } function spanCategory(settings: GitHubPublisherSettings, code: DocumentFragment) { - if (settings.upload.behavior === FolderSettings.yaml) { + if (settings.upload.behavior === FolderSettings.Yaml) { const defaultPath = settings.upload.defaultName.length > 0 ? `${settings.upload.defaultName}` : "/"; return { @@ -53,7 +53,7 @@ export function KeyBasedOnSettings(settings: GitHubPublisherSettings): DocumentF const defaultPath = settings.upload.defaultName.length > 0 ? `${settings.upload.defaultName}` : "/"; let path = - settings.upload.behavior === FolderSettings.yaml + settings.upload.behavior === FolderSettings.Yaml ? `${ settings.upload.rootFolder.length > 0 ? settings.upload.rootFolder : "" }/${defaultPath}/file.md` diff --git a/src/settings/migrate.ts b/src/settings/migrate.ts index 93bbd994..8127f52d 100644 --- a/src/settings/migrate.ts +++ b/src/settings/migrate.ts @@ -1,13 +1,13 @@ import { - FolderSettings, - GithubTiersVersion, - TextCleaner, + type FolderSettings, + type GithubTiersVersion, + type TextCleaner, TOKEN_PATH, TypeOfEditRegex, } from "@interfaces"; import i18next from "i18next"; import { normalizePath } from "obsidian"; -import GithubPublisher from "src/main"; +import type GithubPublisher from "src/main"; import { createTokenPath, logs } from "src/utils"; export interface OldSettings { @@ -101,7 +101,7 @@ async function migrateSubFolder(plugin: GithubPublisher) { //@ts-ignore regex: "/" + plugin.settings.upload.subFolder, replacement: "", - type: TypeOfEditRegex.path, + type: TypeOfEditRegex.Path, }); } //delete plugin.settings.upload.subFolder from settings; @@ -221,13 +221,13 @@ async function migrateOtherRepository(plugin: GithubPublisher) { const otherRepo = plugin.settings.github?.otherRepo ?? []; for (const repo of otherRepo) { const workflow = { - //@ts-ignore name: - plugin.settings.github.worflow?.workflowName ?? + //@ts-ignore + plugin.settings.github.workflow?.workflowName ?? plugin.settings.github.workflow.name, - //@ts-ignore commitMessage: - plugin.settings.github.worflow?.customCommitMsg ?? + //@ts-ignore + plugin.settings.github.workflow?.commitMessage ?? plugin.settings.github.workflow.commitMessage, }; if (!repo.workflow) { @@ -315,14 +315,14 @@ async function migrateOldSettings(plugin: GithubPublisher, old: OldSettings) { { regex: old.frontmatterTitleRegex, replacement: old.frontmatterTitleReplacement, - type: TypeOfEditRegex.title, + type: TypeOfEditRegex.Title, }, ], replacePath: [ { regex: old.subFolder, replacement: "", - type: TypeOfEditRegex.path, + type: TypeOfEditRegex.Path, }, ], autoclean: { @@ -391,8 +391,10 @@ async function migrateOldSettings(plugin: GithubPublisher, old: OldSettings) { //@ts-ignore const token = old.GhToken ? old.GhToken - : plugin.settings.github.token - ? plugin.settings.github.token + : //@ts-ignore + plugin.settings.github.token + ? //@ts-ignore + plugin.settings.github.token : undefined; await migrateToken(plugin, token); await plugin.saveSettings(); diff --git a/src/settings/modals/import_export.ts b/src/settings/modals/import_export.ts index 1e6352d8..0eeaf8bc 100644 --- a/src/settings/modals/import_export.ts +++ b/src/settings/modals/import_export.ts @@ -1,8 +1,8 @@ -import { GitHubPublisherSettings, Preset } from "@interfaces/main"; -import { Octokit } from "@octokit/core"; +import type { GitHubPublisherSettings, Preset } from "@interfaces/main"; +import type { Octokit } from "@octokit/core"; import i18next from "i18next"; import { - App, + type App, ButtonComponent, FuzzySuggestModal, Modal, @@ -11,9 +11,9 @@ import { Setting, TextAreaComponent, } from "obsidian"; -import GithubPublisher from "src/main"; -import { GithubPublisherSettingsTab } from "src/settings"; -import { migrateSettings, OldSettings } from "src/settings/migrate"; +import type GithubPublisher from "src/main"; +import type { GithubPublisherSettingsTab } from "src/settings"; +import { migrateSettings, type OldSettings } from "src/settings/migrate"; import { logs, notif } from "src/utils"; export type SettingValue = number | string | boolean | unknown; @@ -176,7 +176,7 @@ export class ImportModal extends Modal { this.settingsPage.empty(); // @ts-ignore let openedTab = - this.plugin.settings.tabsID ?? + this.plugin.settings.tabsId ?? document.querySelector(".settings-tab.settings-tab-active") ? document.querySelector(".settings-tab.settings-tab-active .settings-tab-name") .innerText @@ -376,7 +376,7 @@ export class ImportLoadPreset extends FuzzySuggestModal { this.settings.github.user = original.github.user; this.settings.github.otherRepo = original.github.otherRepo; this.settings.github.rateLimit = original.github.rateLimit; - this.settings.tabsID = original.tabsID; + this.settings.tabsId = original.tabsId; this.plugin.saveSettings(); this.page.renderSettingsPage("github-configuration"); diff --git a/src/settings/modals/list_changed.ts b/src/settings/modals/list_changed.ts index 42673929..cf85b641 100644 --- a/src/settings/modals/list_changed.ts +++ b/src/settings/modals/list_changed.ts @@ -1,6 +1,6 @@ -import { Deleted, ListEditedFiles } from "@interfaces"; +import type { Deleted, ListEditedFiles } from "@interfaces"; import i18next from "i18next"; -import { App, Modal } from "obsidian"; +import { type App, Modal } from "obsidian"; export class ListChangedFiles extends Modal { listChanged: ListEditedFiles | Deleted; diff --git a/src/settings/modals/manage_repo.ts b/src/settings/modals/manage_repo.ts index 5346dc46..416b0fb6 100644 --- a/src/settings/modals/manage_repo.ts +++ b/src/settings/modals/manage_repo.ts @@ -1,7 +1,18 @@ -import { GitHubPublisherSettings, GithubTiersVersion, Repository } from "@interfaces"; +import { + type GitHubPublisherSettings, + GithubTiersVersion, + type Repository, +} from "@interfaces"; import i18next from "i18next"; -import { AbstractInputSuggest, App, Modal, Notice, Setting, TFile } from "obsidian"; -import GithubPublisher from "src/main"; +import { + AbstractInputSuggest, + type App, + Modal, + Notice, + Setting, + type TFile, +} from "obsidian"; +import type GithubPublisher from "src/main"; import { migrateToken } from "src/settings/migrate"; import { checkRepositoryValidity, @@ -323,11 +334,11 @@ class ModalEditingRepository extends Modal { .addDropdown((dropdown) => { dropdown .addOption( - GithubTiersVersion.free, + GithubTiersVersion.Free, i18next.t("settings.github.apiType.dropdown.free") ) .addOption( - GithubTiersVersion.entreprise, + GithubTiersVersion.Entreprise, i18next.t("settings.github.apiType.dropdown.enterprise") ) .setValue(this.repository.api.tiersForApi) @@ -336,7 +347,7 @@ class ModalEditingRepository extends Modal { this.onOpen(); }); }); - if (this.repository.api.tiersForApi === GithubTiersVersion.entreprise) { + if (this.repository.api.tiersForApi === GithubTiersVersion.Entreprise) { new Setting(contentEl) .setName(i18next.t("settings.github.apiType.hostname.title")) .setDesc(i18next.t("settings.github.apiType.hostname.desc")) @@ -385,8 +396,8 @@ class ModalEditingRepository extends Modal { this.repository.branch = value.trim(); }) ); - const desc_ghToken = document.createDocumentFragment(); - desc_ghToken.createEl("span", undefined, (span) => { + const descGhToken = document.createDocumentFragment(); + descGhToken.createEl("span", undefined, (span) => { span.innerText = i18next.t("settings.github.ghToken.desc"); span.createEl("a", undefined, (link) => { link.innerText = `${i18next.t("common.here")}.`; @@ -395,7 +406,7 @@ class ModalEditingRepository extends Modal { }); new Setting(contentEl) .setName(i18next.t("common.ghToken")) - .setDesc(desc_ghToken) + .setDesc(descGhToken) .addText(async (text) => { const decryptedToken: string = await this.plugin.loadToken( this.repository.smartKey diff --git a/src/settings/modals/popup.ts b/src/settings/modals/popup.ts index e59099a0..b88cbca7 100644 --- a/src/settings/modals/popup.ts +++ b/src/settings/modals/popup.ts @@ -1,6 +1,6 @@ -import { GitHubPublisherSettings } from "@interfaces/main"; +import type { GitHubPublisherSettings } from "@interfaces/main"; import i18next from "i18next"; -import { App, Modal, Setting } from "obsidian"; +import { type App, Modal, Setting } from "obsidian"; export class AutoCleanPopup extends Modal { settings: GitHubPublisherSettings; diff --git a/src/settings/modals/regex_edition.ts b/src/settings/modals/regex_edition.ts index 1f29c11b..5245f06d 100644 --- a/src/settings/modals/regex_edition.ts +++ b/src/settings/modals/regex_edition.ts @@ -1,13 +1,13 @@ import { FolderSettings, - GitHubPublisherSettings, - OverrideAttachments, - RegexReplace, - TextCleaner, + type GitHubPublisherSettings, + type OverrideAttachments, + type RegexReplace, + type TextCleaner, TypeOfEditRegex, } from "@interfaces"; import i18next from "i18next"; -import { App, Modal, Notice, Setting } from "obsidian"; +import { type App, Modal, Notice, Setting } from "obsidian"; import { escapeRegex } from "src/conversion/links"; function isRegexValid(regexString: string) { @@ -188,10 +188,10 @@ export class ModalRegexFilePathName extends Modal { classValue(allRegex: RegexReplace[]) { this.settings.upload.replacePath = allRegex.filter((regex) => { - return regex.type === TypeOfEditRegex.path; + return regex.type === TypeOfEditRegex.Path; }); this.settings.upload.replaceTitle = allRegex.filter((regex) => { - return regex.type === TypeOfEditRegex.title; + return regex.type === TypeOfEditRegex.Title; }); } @@ -201,7 +201,7 @@ export class ModalRegexFilePathName extends Modal { ): { value: string; isForbidden: boolean } { const regexSpecialDontExclude = /\/(.*)(\\[dwstrnvfb0cxup])(.*)\//i; let onWhat = - type === TypeOfEditRegex.path + type === TypeOfEditRegex.Path ? i18next.t("common.path.folder") : i18next.t("common.path.file"); onWhat = onWhat.toLowerCase(); @@ -221,7 +221,7 @@ export class ModalRegexFilePathName extends Modal { isForbidden = true; } else if ( value.match(/[><:"|?*]|(\\\/)|(^\w+\/\w+)|(\\)/) && - type === TypeOfEditRegex.title && + type === TypeOfEditRegex.Title && !value.match(regexSpecialDontExclude) ) { new Notice( @@ -232,7 +232,7 @@ export class ModalRegexFilePathName extends Modal { ); value = ""; isForbidden = true; - } else if (type === TypeOfEditRegex.path) { + } else if (type === TypeOfEditRegex.Path) { if (value.match(/[\\><:"|?*]/) && !value.match(/^\/(.*)\/[gmisuvdy]*$/)) { new Notice( i18next.t("settings.regexReplacing.forbiddenValue", { @@ -259,7 +259,7 @@ export class ModalRegexFilePathName extends Modal { const { contentEl } = this; contentEl.empty(); contentEl.addClasses(["github-publisher", "modals", "regex", "file-path-name"]); - if (this.settings.upload.behavior === FolderSettings.fixed) { + if (this.settings.upload.behavior === FolderSettings.Fixed) { contentEl.createEl("h2", { text: i18next.t("settings.regexReplacing.modal.title.only"), }); @@ -275,12 +275,12 @@ export class ModalRegexFilePathName extends Modal { } this.settings.upload.replacePath.forEach((title) => { if (!title.type) { - title.type = TypeOfEditRegex.path; + title.type = TypeOfEditRegex.Path; } }); this.settings.upload.replaceTitle.forEach((title) => { if (!title.type) { - title.type = TypeOfEditRegex.title; + title.type = TypeOfEditRegex.Title; } }); @@ -307,7 +307,7 @@ export class ModalRegexFilePathName extends Modal { }); sett.controlEl.setAttribute("value", title.regex); sett.controlEl.setAttribute("replace", title.replacement); - if (this.settings.upload.behavior !== FolderSettings.fixed) { + if (this.settings.upload.behavior !== FolderSettings.Fixed) { sett.addDropdown((dropdown) => { dropdown .addOption("path", i18next.t("common.path.folder")) @@ -336,7 +336,7 @@ export class ModalRegexFilePathName extends Modal { this.allRegex.push({ regex: "", replacement: "", - type: TypeOfEditRegex.title, + type: TypeOfEditRegex.Title, }); this.onOpen(); }); diff --git a/src/settings/modals/token_path.ts b/src/settings/modals/token_path.ts index b484ebf7..4221854f 100644 --- a/src/settings/modals/token_path.ts +++ b/src/settings/modals/token_path.ts @@ -1,7 +1,7 @@ import { TOKEN_PATH } from "@interfaces"; import i18next from "i18next"; -import { App, Modal, Notice, Setting } from "obsidian"; -import GithubPublisher from "src/main"; +import { type App, Modal, Notice, Setting } from "obsidian"; +import type GithubPublisher from "src/main"; import { migrateToken } from "src/settings/migrate"; import { createTokenPath, logs } from "src/utils"; diff --git a/src/settings/style.ts b/src/settings/style.ts index 4b5e6517..28cb0449 100644 --- a/src/settings/style.ts +++ b/src/settings/style.ts @@ -1,8 +1,12 @@ -import { EnumbSettingsTabId, FolderSettings, GitHubPublisherSettings } from "@interfaces"; +import { + EnumbSettingsTabId, + FolderSettings, + type GitHubPublisherSettings, +} from "@interfaces"; import i18next from "i18next"; -import { Notice, Setting } from "obsidian"; -import GithubPublisher from "src/main"; -import { GithubPublisherSettingsTab } from "src/settings"; +import { Notice, type Setting } from "obsidian"; +import type GithubPublisher from "src/main"; +import type { GithubPublisherSettingsTab } from "src/settings"; /** * show a settings * @param {Setting} containerEl setting to show @@ -36,14 +40,14 @@ export function showHideBasedOnFolder( folderNoteSettings: Setting ) { const upload = settings.upload; - if (upload.behavior === FolderSettings.yaml) { + if (upload.behavior === FolderSettings.Yaml) { showSettings(frontmatterKeySettings); showSettings(rootFolderSettings); showSettings(folderNoteSettings); } else { hideSettings(frontmatterKeySettings); hideSettings(rootFolderSettings); - if (upload.behavior === FolderSettings.obsidian) { + if (upload.behavior === FolderSettings.Obsidian) { showSettings(folderNoteSettings); } else { hideSettings(folderNoteSettings); @@ -74,15 +78,15 @@ export async function autoCleanCondition( await plugin.saveSettings(); // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.remove("is-enabled"); - settingsTab.renderSettingsPage(EnumbSettingsTabId.upload); + settingsTab.renderSettingsPage(EnumbSettingsTabId.Upload); } - if (value.length === 0 && settings.behavior !== FolderSettings.yaml) { + if (value.length === 0 && settings.behavior !== FolderSettings.Yaml) { if (settings.autoclean.enable) new Notice(i18next.t("error.autoClean", { what: i18next.t("common.defaultName") })); settings.autoclean.enable = false; // @ts-ignore autoCleanSetting.components[0].toggleEl.classList.remove("is-enabled"); - settingsTab.renderSettingsPage(EnumbSettingsTabId.upload); + settingsTab.renderSettingsPage(EnumbSettingsTabId.Upload); } if (settings.autoclean.enable) { // @ts-ignore @@ -111,7 +115,7 @@ export async function folderHideShowSettings( plugin: GithubPublisher ) { const settings = plugin.settings.upload; - if (value === FolderSettings.yaml) { + if (value === FolderSettings.Yaml) { showSettings(frontmatterKeySettings); showSettings(rootFolderSettings); return; diff --git a/src/utils/data_validation_test.ts b/src/utils/data_validation_test.ts index 086b9d1f..dd19a643 100644 --- a/src/utils/data_validation_test.ts +++ b/src/utils/data_validation_test.ts @@ -1,18 +1,24 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { FIND_REGEX, - GitHubPublisherSettings, + type GitHubPublisherSettings, GithubTiersVersion, - MultiProperties, - Properties, - PropertiesConversion, - Repository, + type MultiProperties, + type Properties, + type PropertiesConversion, + type Repository, } from "@interfaces"; -import { Octokit } from "@octokit/core"; +import type { Octokit } from "@octokit/core"; import i18next from "i18next"; -import { FrontMatterCache, normalizePath, Notice, TFile, TFolder } from "obsidian"; -import { GithubBranch } from "src/GitHub/branch"; -import GithubPublisher from "src/main"; +import { + type FrontMatterCache, + normalizePath, + Notice, + type TFile, + type TFolder, +} from "obsidian"; +import type { GithubBranch } from "src/GitHub/branch"; +import type GithubPublisher from "src/main"; import { notif } from "src/utils"; import { frontmatterFromFile, @@ -445,7 +451,7 @@ export function defaultRepo(settings: GitHubPublisherSettings): Repository { user: settings.github.user, repo: settings.github.repo, branch: settings.github.branch, - automaticallyMergePR: settings.github.automaticallyMergePR, + automaticallyMergePr: settings.github.automaticallyMergePR, verifiedRepo: settings.github.verifiedRepo, rateLimit: settings.github.rateLimit, api: { @@ -519,7 +525,7 @@ export async function verifyRateLimitAPI( //if the error is 404 and user use enterprise, it's normal if ( (error as any).status === 404 && - settings.github.api.tiersForApi === GithubTiersVersion.entreprise && + settings.github.api.tiersForApi === GithubTiersVersion.Entreprise && (error as any).response.data.message === "Rate limiting is not enabled." && (error as any).name === "HttpError" ) diff --git a/src/utils/index.ts b/src/utils/index.ts index a1fbd89a..e38cc1fd 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,22 +1,22 @@ import { - Deleted, + type Deleted, FIND_REGEX, - GitHubPublisherSettings, - ListEditedFiles, - MetadataExtractor, - MultiRepoProperties, - Properties, + type GitHubPublisherSettings, + type ListEditedFiles, + type MetadataExtractor, + type MultiRepoProperties, + type Properties, TOKEN_PATH, - UploadedFiles, + type UploadedFiles, } from "@interfaces"; import { ERROR_ICONS, HOURGLASS_ICON, SUCCESS_ICON } from "@interfaces/icons"; import i18next from "i18next"; -import { App, normalizePath, Notice, Platform, TFile } from "obsidian"; +import { type App, normalizePath, Notice, Platform, TFile } from "obsidian"; import slugify from "slugify"; import { getReceiptFolder } from "src/conversion/file_path"; import { createRegexFromText } from "src/conversion/find_and_replace_text"; -import Publisher from "src/GitHub/upload"; -import GithubPublisher from "src/main"; +import type Publisher from "src/GitHub/upload"; +import type GithubPublisher from "src/main"; import { frontmatterFromFile } from "src/utils/parse_frontmatter"; type LogsParameters = { diff --git a/src/utils/parse_frontmatter.ts b/src/utils/parse_frontmatter.ts index 585570dc..157752f0 100644 --- a/src/utils/parse_frontmatter.ts +++ b/src/utils/parse_frontmatter.ts @@ -5,14 +5,14 @@ import { FolderSettings, - GitHubPublisherSettings, - Path, - Properties, - PropertiesConversion, - Repository, + type GitHubPublisherSettings, + type Path, + type Properties, + type PropertiesConversion, + type Repository, } from "@interfaces"; -import { FrontMatterCache, normalizePath, TFile } from "obsidian"; -import GithubPublisher from "src/main"; +import { type FrontMatterCache, normalizePath, TFile } from "obsidian"; +import type GithubPublisher from "src/main"; import merge from "ts-deepmerge"; export function frontmatterSettingsRepository( @@ -157,7 +157,7 @@ export function getProperties( autoclean: settings.upload.autoclean.enable && settings.github.dryRun.enable, }, }; - if (settings.upload.behavior === FolderSettings.fixed) { + if (settings.upload.behavior === FolderSettings.Fixed) { Properties.autoclean = false; } if ( diff --git a/src/utils/status_bar.ts b/src/utils/status_bar.ts index 65816557..e2721a65 100644 --- a/src/utils/status_bar.ts +++ b/src/utils/status_bar.ts @@ -2,11 +2,11 @@ import { ERROR_ICONS, FOUND_ATTACHMENTS, HOURGLASS_ICON, - Properties, + type Properties, SUCCESS_ICON, } from "@interfaces"; import i18next from "i18next"; -import { Notice } from "obsidian"; +import type { Notice } from "obsidian"; import { noticeMobile } from "src/utils"; // Credit : https://github.com/oleeskild/obsidian-digital-garden/ @oleeskild From dd106356c466f4b9a5a6d971894f3880205cfa83 Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 22 May 2024 11:25:03 +0200 Subject: [PATCH 2/4] lint: apply biome --- biome.json | 4 +++- src/GitHub/branch.ts | 7 +++++-- src/GitHub/files.ts | 1 + src/GitHub/upload.ts | 9 ++++++--- src/commands/suggest_other_repo_commands_modal.ts | 9 +++------ src/conversion/compiler/dataview.ts | 14 ++++++++------ src/conversion/index.ts | 2 +- src/interfaces/main.ts | 1 - src/main.ts | 14 ++++++++------ src/settings.ts | 2 +- src/settings/migrate.ts | 10 +++++++--- src/settings/modals/import_export.ts | 12 +++++------- src/settings/modals/manage_repo.ts | 2 +- src/utils/data_validation_test.ts | 2 +- src/utils/index.ts | 13 +++++-------- 15 files changed, 55 insertions(+), 47 deletions(-) diff --git a/biome.json b/biome.json index 871f3a1e..3f172825 100644 --- a/biome.json +++ b/biome.json @@ -83,7 +83,9 @@ }, "ignore": [ "**/npm node_modules", - "**/build" + "**/build", + "**/dist", + "**/src/i18n/locales" ] }, "overrides": [ diff --git a/src/GitHub/branch.ts b/src/GitHub/branch.ts index 18003b52..a6f93e02 100644 --- a/src/GitHub/branch.ts +++ b/src/GitHub/branch.ts @@ -53,7 +53,7 @@ export class GithubBranch extends FilesManagement { i18next.t("publish.branch.success", { branchStatus: branch.status, repo: prop }) ); return branch.status === 201; - } catch (e) { + } catch (_e) { // catch the old branch try { const allBranch = await this.octokit.request( @@ -130,7 +130,7 @@ export class GithubBranch extends FilesManagement { async deleteBranchOnRepo(prop: Properties): Promise { try { const branch = await this.octokit.request( - "DELETE" + " /repos/{owner}/{repo}/git/refs/heads/" + this.branchName, + `DELETE /repos/{owner}/{repo}/git/refs/heads/${this.branchName}`, { owner: prop.owner, repo: prop.repo, @@ -161,8 +161,11 @@ export class GithubBranch extends FilesManagement { { owner: prop.owner, repo: prop.repo, + // biome-ignore lint/style/useNamingConvention: hey, say that to github! pull_number: pullRequestNumber, + // biome-ignore lint/style/useNamingConvention: hey, say that to github! commit_title: commitMsg, + // biome-ignore lint/style/useNamingConvention: hey, say that to github! merge_method: "squash", } ); diff --git a/src/GitHub/files.ts b/src/GitHub/files.ts index 6572c284..d4fb9763 100644 --- a/src/GitHub/files.ts +++ b/src/GitHub/files.ts @@ -395,6 +395,7 @@ export class FilesManagement extends Publisher { { owner: repo.owner, repo: repo.repo, + // biome-ignore lint/style/useNamingConvention: github api tree_sha: branchToScan, recursive: "true", } diff --git a/src/GitHub/upload.ts b/src/GitHub/upload.ts index e5854739..3277be9e 100644 --- a/src/GitHub/upload.ts +++ b/src/GitHub/upload.ts @@ -527,8 +527,9 @@ export default class Publisher { for (const file of Object.values(metadataExtractor)) { if (file) { const contents = await this.vault.adapter.read(file); - const path = - this.settings.upload.metadataExtractorPath + "/" + file.split("/").pop(); + const path = `${this.settings.upload.metadataExtractorPath}/${file + .split("/") + .pop()}`; prop = Array.isArray(prop) ? prop : [prop]; for (const repo of prop) { await this.uploadText(contents, path, file.split("/").pop(), repo); @@ -556,11 +557,13 @@ export default class Publisher { { owner: prop.owner, repo: prop.repo, + // biome-ignore lint/style/useNamingConvention: GitHub API :( workflow_id: prop.workflowName, ref: prop.branch, } ); while (!finished) { + // biome-ignore lint/correctness/noUndeclaredVariables: directly build with obsidianAPI await sleep(10000); const workflowGet = await octokit.request( "GET /repos/{owner}/{repo}/actions/runs", @@ -652,7 +655,7 @@ export default class Publisher { ); } } - } catch (e) { + } catch (_e) { newLinkedFiles.push(file); } //pass non image file as they are updated basically by GitHub with checking the content (basic git behavior) diff --git a/src/commands/suggest_other_repo_commands_modal.ts b/src/commands/suggest_other_repo_commands_modal.ts index 3546d9a1..6106890e 100644 --- a/src/commands/suggest_other_repo_commands_modal.ts +++ b/src/commands/suggest_other_repo_commands_modal.ts @@ -49,8 +49,7 @@ export class ChooseWhichRepoToRun extends FuzzySuggestModal { getItemText(item: Repository): string { return item.smartKey; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - onChooseItem(item: Repository, evt: MouseEvent | KeyboardEvent): void { + onChooseItem(item: Repository, _evt: MouseEvent | KeyboardEvent): void { new SuggestOtherRepoCommandsModal( this.plugin.app, this.plugin, @@ -126,8 +125,7 @@ export class ChooseRepoToRun extends FuzzySuggestModal { getItemText(item: Repository): string { return item.smartKey; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - onChooseItem(item: Repository, evt: MouseEvent | KeyboardEvent): void { + onChooseItem(item: Repository, _evt: MouseEvent | KeyboardEvent): void { this.onSubmit(item); } } @@ -196,8 +194,7 @@ export class SuggestOtherRepoCommandsModal extends FuzzySuggestModal const div = createEl("div"); const component = new Component(); await this.dvApi.executeJs(query, div, component, this.path); @@ -148,6 +149,7 @@ class DataviewCompiler { const query = ${query}; dv.paragraph(query); `; + // biome-ignore lint/correctness/noUndeclaredVariables: const div = createEl("div"); const component = new Component(); await this.dvApi.executeJs(evaluateQuery, div, component, this.path); @@ -200,7 +202,7 @@ export async function convertDataviewQueries( for (const queryBlock of matches) { try { const block = queryBlock[0]; - const markdown = await compiler.DQLDataview(queryBlock[1]); + const markdown = await compiler.dataviewDQL(queryBlock[1]); replacedText = replacedText.replace(block, markdown); } catch (e) { logs({ settings, e: true }, e); @@ -212,7 +214,7 @@ export async function convertDataviewQueries( for (const queryBlock of dataviewJsMatches) { try { const block = queryBlock[0]; - const markdown = await compiler.DataviewJS(queryBlock[1]); + const markdown = await compiler.dataviewJS(queryBlock[1]); replacedText = replacedText.replace(block, markdown); } catch (e) { logs({ settings, e: true }, e); @@ -259,8 +261,8 @@ function removeDataviewQueries( dataviewMarkdown: Literal, frontmatterSettings: PropertiesConversion ): string { - const toString = dataviewMarkdown?.toString(); - return frontmatterSettings.dataview && dataviewMarkdown && toString ? toString : ""; + const toStr = dataviewMarkdown?.toString(); + return frontmatterSettings.dataview && dataviewMarkdown && toStr ? toStr : ""; } /** diff --git a/src/conversion/index.ts b/src/conversion/index.ts index ae80e39b..c70208c0 100644 --- a/src/conversion/index.ts +++ b/src/conversion/index.ts @@ -125,7 +125,7 @@ export function addToYaml( exists ? text.slice(contentStart) : text }`; } - } catch (e) { + } catch (_e) { new Notice(i18next.t("error.parseYaml")); return text; //not a valid yaml, skipping } diff --git a/src/interfaces/main.ts b/src/interfaces/main.ts index 6c947cb3..a0b6daa5 100644 --- a/src/interfaces/main.ts +++ b/src/interfaces/main.ts @@ -267,7 +267,6 @@ export interface Properties { /** commitMsg if the default is not okay for this repo */ commitMsg: string; /** Automatically merge the PR */ - // biome-ignore lint/style/useNamingConvention: It's a type definition, not a variable automaticallyMergePR: boolean; /** If the repository was checked */ verifiedRepo?: boolean; diff --git a/src/main.ts b/src/main.ts index 088ecfa1..5e9d220a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -223,10 +223,12 @@ export default class GithubPublisher extends Plugin { const oldSettings = this.settings; await migrateSettings(oldSettings as unknown as OldSettings, this); - this.branchName = - this.app.vault.getName().replaceAll(" ", "-").replaceAll(".", "-") + - "-" + - new Date().toLocaleDateString("en-US").replace(/\//g, "-"); + this.branchName = `${this.app.vault + .getName() + .replaceAll(" ", "-") + .replaceAll(".", "-")}-${new Date() + .toLocaleDateString("en-US") + .replace(/\//g, "-")}`; this.addSettingTab(new GithubPublisherSettingsTab(this.app, this, this.branchName)); // verify rate limit @@ -288,7 +290,7 @@ export default class GithubPublisher extends Plugin { ); this.registerEvent( - this.app.workspace.on("editor-menu", (menu, editor, view) => { + this.app.workspace.on("editor-menu", (menu, _editor, view) => { if (view.file) addMenuFile(this, view.file, this.branchName, menu); }) ); @@ -348,7 +350,7 @@ export default class GithubPublisher extends Plugin { DEFAULT_SETTINGS, loadedData ) as unknown as GitHubPublisherSettings; - } catch (e) { + } catch (_e) { console.warn( "[Github Publisher] Error while deep merging settings, using default loading method" ); diff --git a/src/settings.ts b/src/settings.ts index 37367849..f5b53adc 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1418,7 +1418,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { copy(object: any) { try { return JSON.parse(JSON.stringify(object)); - } catch (e) { + } catch (_e) { console.log("error with stringify for", object); } } diff --git a/src/settings/migrate.ts b/src/settings/migrate.ts index 8127f52d..ffc57c01 100644 --- a/src/settings/migrate.ts +++ b/src/settings/migrate.ts @@ -13,6 +13,7 @@ import { createTokenPath, logs } from "src/utils"; export interface OldSettings { githubRepo: string; githubName: string; + // biome-ignore lint/style/useNamingConvention: it's the migration from old settings, so we keep the old name with the typo GhToken: string; githubBranch: string; shareKey: string; @@ -87,10 +88,11 @@ async function migrateReplaceTitle(plugin: GithubPublisher) { } async function migrateSubFolder(plugin: GithubPublisher) { - //@ts-ignore if ( + //@ts-ignore plugin.settings.upload.subFolder && !plugin.settings.upload.replacePath.find( + //@ts-ignore (e) => e.regex === `/${plugin.settings.upload.subFolder}` ) ) { @@ -99,7 +101,7 @@ async function migrateSubFolder(plugin: GithubPublisher) { if (plugin.settings.upload.subFolder.length > 0) { plugin.settings.upload.replacePath.push({ //@ts-ignore - regex: "/" + plugin.settings.upload.subFolder, + regex: `/${plugin.settings.upload.subFolder}`, replacement: "", type: TypeOfEditRegex.Path, }); @@ -115,7 +117,7 @@ async function migrateCensor(plugin: GithubPublisher) { for (const censor of plugin.settings.conversion.censorText) { if (censor.flags) { //enclose regex in / / and add flags - censor.entry = "/" + censor.entry + "/" + censor.flags; + censor.entry = `/${censor.entry}/${censor.flags}`; delete censor.flags; await plugin.saveSettings(); } @@ -178,11 +180,13 @@ export async function migrateToken( if (tokenPath.endsWith(".json")) { const envToken = repo ? { + // biome-ignore lint/style/useNamingConvention: it's a constant GITHUB_PUBLISHER_REPOS: { [repo]: token, }, } : { + // biome-ignore lint/style/useNamingConvention: it's a constant GITHUB_PUBLISHER_TOKEN: token, }; if (!exists) { diff --git a/src/settings/modals/import_export.ts b/src/settings/modals/import_export.ts index 0eeaf8bc..cf1b4eec 100644 --- a/src/settings/modals/import_export.ts +++ b/src/settings/modals/import_export.ts @@ -69,7 +69,7 @@ export class ImportModal extends Modal { .setDesc(i18next.t("modals.import.desc")); new Setting(contentEl).then((setting) => { - // Build an error message container + // biome-ignore lint/correctness/noUndeclaredVariables: createSpan is a function builded with the plugin const errorSpan = createSpan({ cls: "github-publisher-import-error", text: i18next.t("modals.import.error.span"), @@ -174,13 +174,11 @@ export class ImportModal extends Modal { const { contentEl } = this; contentEl.empty(); this.settingsPage.empty(); - // @ts-ignore let openedTab = this.plugin.settings.tabsId ?? - document.querySelector(".settings-tab.settings-tab-active") - ? document.querySelector(".settings-tab.settings-tab-active .settings-tab-name") - .innerText - : i18next.t("settings.github.title"); + document.querySelector(".settings-tab.settings-tab-active .settings-tab-name") + ?.textContent ?? + i18next.t("settings.github.title"); openedTab = openedTab.trim(); switch (openedTab) { case i18next.t("settings.github.title"): @@ -351,7 +349,7 @@ export class ImportLoadPreset extends FuzzySuggestModal { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - onChooseItem(item: Preset, evt: MouseEvent | KeyboardEvent): void { + onChooseItem(item: Preset, _evt: MouseEvent | KeyboardEvent): void { const presetSettings = item.settings; logs({ settings: presetSettings }, "onChooseItem"); try { diff --git a/src/settings/modals/manage_repo.ts b/src/settings/modals/manage_repo.ts index 416b0fb6..99a470df 100644 --- a/src/settings/modals/manage_repo.ts +++ b/src/settings/modals/manage_repo.ts @@ -48,7 +48,7 @@ class SetClassSuggester extends AbstractInputSuggest { } //eslint-disable-next-line @typescript-eslint/no-unused-vars - selectSuggestion(value: TFile, evt: MouseEvent | KeyboardEvent): void { + selectSuggestion(value: TFile, _evt: MouseEvent | KeyboardEvent): void { this.onSubmit(value); this.inputEl.value = value.path; this.inputEl.focus(); diff --git a/src/utils/data_validation_test.ts b/src/utils/data_validation_test.ts index dd19a643..32e5ff73 100644 --- a/src/utils/data_validation_test.ts +++ b/src/utils/data_validation_test.ts @@ -451,7 +451,7 @@ export function defaultRepo(settings: GitHubPublisherSettings): Repository { user: settings.github.user, repo: settings.github.repo, branch: settings.github.branch, - automaticallyMergePr: settings.github.automaticallyMergePR, + automaticallyMergePR: settings.github.automaticallyMergePR, verifiedRepo: settings.github.verifiedRepo, rateLimit: settings.github.rateLimit, api: { diff --git a/src/utils/index.ts b/src/utils/index.ts index e38cc1fd..d6ffb82d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -235,17 +235,17 @@ export async function getSettingsOfMetadataExtractor( if (plugin.settings.allExceptMdFile.length > 0) { //get file from plugins folder in .obsidian folder //@ts-ignore - metadataExtractor.allExceptMdFile = path + "/" + plugin.settings.allExceptMdFile; + metadataExtractor.allExceptMdFile = `${path}/${plugin.settings.allExceptMdFile}`; } //@ts-ignore if (plugin.settings["metadataFile"].length > 0) { //@ts-ignore - metadataExtractor.metadataFile = path + "/" + plugin.settings.metadataFile; + metadataExtractor.metadataFile = `${path}/${plugin.settings.metadataFile}`; } //@ts-ignore if (plugin.settings.tagFile.length > 0) { //@ts-ignore - metadataExtractor.tagsFile = path + "/" + plugin.settings.tagFile; + metadataExtractor.tagsFile = `${path}/${plugin.settings.tagFile}`; } return metadataExtractor; } @@ -261,7 +261,7 @@ export async function getSettingsOfMetadataExtractor( function checkSlash(link: string): string { const slash = link.match(/\/*$/); if (slash && slash[0].length != 1) { - return link.replace(/\/*$/, "") + "/"; + return `${link.replace(/\/*$/, "")}/`; } return link; } @@ -454,12 +454,9 @@ async function publisherNotificationOneRepo( /** * Trim the object to remove the empty value - * @param {{[p: string]: string}} obj - * @return {any} */ - export function trimObject(obj: { [p: string]: string }) { - const trimmed = JSON.stringify(obj, (key, value) => { + const trimmed = JSON.stringify(obj, (_key, value) => { if (typeof value === "string") { return value.trim().toLowerCase(); } From 18dd6c1e66634306ad58f65e03c8f359933ec0e1 Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 22 May 2024 11:30:14 +0200 Subject: [PATCH 3/4] lint --- src/settings/modals/manage_repo.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/settings/modals/manage_repo.ts b/src/settings/modals/manage_repo.ts index 99a470df..be6b2e83 100644 --- a/src/settings/modals/manage_repo.ts +++ b/src/settings/modals/manage_repo.ts @@ -47,7 +47,6 @@ class SetClassSuggester extends AbstractInputSuggest { }); } - //eslint-disable-next-line @typescript-eslint/no-unused-vars selectSuggestion(value: TFile, _evt: MouseEvent | KeyboardEvent): void { this.onSubmit(value); this.inputEl.value = value.path; From accddf0b85c7a3f7ccb077aaa4f928825df31889 Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 22 May 2024 11:35:22 +0200 Subject: [PATCH 4/4] remove eslint exclude --- src/conversion/index.ts | 2 -- src/settings/modals/import_export.ts | 1 - src/utils/index.ts | 3 --- 3 files changed, 6 deletions(-) diff --git a/src/conversion/index.ts b/src/conversion/index.ts index c70208c0..4e50f43f 100644 --- a/src/conversion/index.ts +++ b/src/conversion/index.ts @@ -52,7 +52,6 @@ export function addHardLineBreak( } } -//eslint-disable-next-line @typescript-eslint/no-explicit-any function tagsToYaml(toAdd: string[], settings: GitHubPublisherSettings, yaml: any) { if (yaml.tag) { try { @@ -133,7 +132,6 @@ export function addToYaml( return text; } -//eslint-disable-next-line @typescript-eslint/no-explicit-any function titleToYaml(yaml: any, properties: MultiProperties, file: TFile) { const settings = properties.plugin.settings.upload.folderNote.addTitle; if (!settings) { diff --git a/src/settings/modals/import_export.ts b/src/settings/modals/import_export.ts index cf1b4eec..d05d8369 100644 --- a/src/settings/modals/import_export.ts +++ b/src/settings/modals/import_export.ts @@ -295,7 +295,6 @@ export class ExportModal extends Modal { output ); //open the file with default application - //eslint-disable-next-line (this.app as any).openWithDefaultApp( `${this.app.vault.configDir}/plugins/obsidian-mkdocs-publisher/._tempSettings.json` ); diff --git a/src/utils/index.ts b/src/utils/index.ts index d6ffb82d..6818748a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -27,10 +27,7 @@ type LogsParameters = { /** * Create a notice message for the log - * @param args {LogsParameters} the settings and the error type - * @param {unknown[]} messages the message to display */ -//eslint-disable-next-line @typescript-eslint/no-explicit-any export function notif(args: LogsParameters, ...messages: unknown[]) { const { settings, e } = args; if (settings.plugin?.noticeError) {