Skip to content

Commit

Permalink
style(biome): run linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Sep 22, 2024
1 parent 6fb1133 commit b63d63b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 27 deletions.
4 changes: 3 additions & 1 deletion src/GitHub/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class GithubBranch extends FilesManagement {
(branch: { name: string }) => branch.name === prop.branch
);
if (!mainBranch) {
throw new Error(`No main branch found for ${prop.repo}, please check the branch name in the settings`);
throw new Error(
`No main branch found for ${prop.repo}, please check the branch name in the settings`
);
}
try {
const shaMainBranch = mainBranch!.commit.sha;
Expand Down
9 changes: 7 additions & 2 deletions src/GitHub/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
frontmatterFromFile,
frontmatterSettingsRepository,
getFrontmatterSettings,
getProperties, mergeFrontmatter,
getProperties,
mergeFrontmatter,
} from "src/utils/parse_frontmatter";
import { ShareStatusBar } from "src/utils/status_bar";
import merge from "ts-deepmerge";
Expand Down Expand Up @@ -173,7 +174,11 @@ export default class Publisher {
const shareFiles = new FilesManagement(this.octokit, this.plugin);
let frontmatter = frontmatterFromFile(file, this.plugin, null);
if (!isShared(frontmatter, this.settings, file, repo.repository)) return false;
frontmatter = mergeFrontmatter(frontmatter, sourceFrontmatter, this.settings.plugin.shareKey);
frontmatter = mergeFrontmatter(
frontmatter,
sourceFrontmatter,
this.settings.plugin.shareKey
);
const prop = getProperties(this.plugin, repo.repository, frontmatter);
const isNotEmpty = await checkEmptyConfiguration(prop, this.plugin);
repo.frontmatter = prop;
Expand Down
12 changes: 10 additions & 2 deletions src/commands/share/unique_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
checkRepositoryValidityWithProperties,
isShared,
} from "src/utils/data_validation_test";
import {frontmatterFromFile, getProperties, mergeFrontmatter} from "src/utils/parse_frontmatter";
import {
frontmatterFromFile,
getProperties,
mergeFrontmatter,
} from "src/utils/parse_frontmatter";

/**
* Command to upload the active file ; use checkCallback to check if the file is shared and if they are a active file
Expand Down Expand Up @@ -70,7 +74,11 @@ export async function shareOneNote(
const { settings, plugin } = PublisherManager;
const app = PublisherManager.plugin.app;
let frontmatter = frontmatterFromFile(file, PublisherManager.plugin, null);
frontmatter = mergeFrontmatter(frontmatter, sourceFrontmatter, PublisherManager.settings.plugin.shareKey);
frontmatter = mergeFrontmatter(
frontmatter,
sourceFrontmatter,
PublisherManager.settings.plugin.shareKey
);
try {
const prop = getProperties(plugin, repository, frontmatter);
let isValid: boolean;
Expand Down
10 changes: 5 additions & 5 deletions src/conversion/file_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function createRelativePath(
targetFile: LinkedNotes,
frontmatter: FrontMatterCache | null | undefined,
properties: MultiProperties
): Promise<{ link: string, unshared?: boolean }> {
): Promise<{ link: string; unshared?: boolean }> {
const settings = properties.plugin.settings;
const shortRepo = properties.repository;
const sourcePath = getReceiptFolder(
Expand Down Expand Up @@ -112,8 +112,8 @@ export async function createRelativePath(
if (targetFile.linked.path === sourceFile.path) {
return {
link: getReceiptFolder(targetFile.linked, shortRepo, properties.plugin, targetRepo)
.split("/")
.at(-1) as string
.split("/")
.at(-1) as string,
};
}

Expand Down Expand Up @@ -179,8 +179,8 @@ export async function createRelativePath(
//in case of errors
return {
link: getReceiptFolder(targetFile.linked, shortRepo, properties.plugin, targetRepo)
.split("/")
.at(-1) as string
.split("/")
.at(-1) as string,
};
}
return {link: relative};
Expand Down
10 changes: 8 additions & 2 deletions src/conversion/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export async function convertToInternalGithub(
linkedFile,
frontmatter,
properties
)
);
let pathInGithub = paths.link;
pathInGithub = pathInGithub.replace(".md", "");
let anchor = linkedFile.anchor ? linkedFile.anchor : "";
Expand All @@ -372,7 +372,13 @@ export async function convertToInternalGithub(
if (matchedLink) {
for (const link of matchedLink) {
if (frontmatterSettings.unlink && paths.unshared) {
fileContent = replaceText(fileContent, link, pathInGithub, properties.plugin, true);
fileContent = replaceText(
fileContent,
link,
pathInGithub,
properties.plugin,
true
);
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ export class EnveloppeSettingsTab extends PluginSettingTab {
this.settingsPage.createEl("h5", {
text: i18next.t("settings.conversion.links.title"),
});
this.settingsPage.append(sanitizeHTMLToDom(i18next.t("settings.conversion.links.desc"),));
this.settingsPage.append(
sanitizeHTMLToDom(i18next.t("settings.conversion.links.desc"))
);

const shareAll = this.settings.plugin.shareAll?.enable
? ` ${i18next.t("settings.conversion.links.internals.shareAll")}`
Expand Down Expand Up @@ -752,7 +754,7 @@ export class EnveloppeSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});

if (!textSettings.links.unshared) {
new Setting(this.settingsPage)
.setName(i18next.t("settings.conversion.links.unlink.title"))
Expand Down Expand Up @@ -1368,9 +1370,7 @@ export class EnveloppeSettingsTab extends PluginSettingTab {
.addToggle((toggle) =>
toggle.setValue(pluginSettings.saveTabId ?? true).onChange(async (value) => {
pluginSettings.saveTabId = value;
this.settings.tabsId = value
? ESettingsTabId.Plugin
: ESettingsTabId.Github;
this.settings.tabsId = value ? ESettingsTabId.Plugin : ESettingsTabId.Github;
await this.plugin.saveSettings();
})
);
Expand Down
6 changes: 4 additions & 2 deletions src/settings/modals/import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,12 @@ export class ImportLoadPreset extends FuzzySuggestModal<Preset> {
this.console.logs({}, "onChooseItem");
try {
const original = clone(this.plugin.settings);

// noinspection SuspiciousTypeOfGuard
if (!(presetSettings.upload.replaceTitle instanceof Array)) {
presetSettings.upload.replaceTitle = [presetSettings.upload.replaceTitle as RegexReplace];
presetSettings.upload.replaceTitle = [
presetSettings.upload.replaceTitle as RegexReplace,
];
}

for (const [key, value] of Object.entries(presetSettings)) {
Expand Down
17 changes: 14 additions & 3 deletions src/settings/modals/manage_repo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import {type EnveloppeSettings, GithubTiersVersion, type Repository} from "@interfaces";
import i18next from "i18next";
import {AbstractInputSuggest, type App, Modal, Notice, Setting, type TFile,} from "obsidian";
import {
AbstractInputSuggest,
type App,
Modal,
Notice,
Setting,
type TFile,
} from "obsidian";
import type Enveloppe from "src/main";
import {migrateToken} from "src/settings/migrate";
import {checkRepositoryValidity, verifyRateLimitAPI,} from "src/utils/data_validation_test";
import {
checkRepositoryValidity,
verifyRateLimitAPI,
} from "src/utils/data_validation_test";

class SetClassSuggester extends AbstractInputSuggest<TFile> {
plugin: Enveloppe;
Expand Down Expand Up @@ -482,7 +492,8 @@ class ModalEditingRepository extends Modal {
search.setValue(this.repository.set ?? "").setPlaceholder("path/to/file.md");
new SetClassSuggester(search.inputEl, this.plugin, (result) => {
this.repository.set = result.path;
this.plugin.repositoryFrontmatter[this.repository.smartKey] = this.plugin.app.metadataCache.getFileCache(result)?.frontmatter;
this.plugin.repositoryFrontmatter[this.repository.smartKey] =
this.plugin.app.metadataCache.getFileCache(result)?.frontmatter;
});
});

Expand Down
10 changes: 7 additions & 3 deletions src/utils/data_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import type Enveloppe from "src/main";
import {
frontmatterFromFile,
getLinkedFrontmatter,
getProperties, mergeFrontmatter,
getProperties,
mergeFrontmatter,
} from "src/utils/parse_frontmatter";
import { escapeRegex } from "../conversion/links";

Expand Down Expand Up @@ -82,7 +83,11 @@ export function getRepoSharedKey(
return defaultRepo(settings);
} else if (!frontmatter) return null;
const linkedFrontmatter = getLinkedFrontmatter(frontmatter, file, plugin);
frontmatter = mergeFrontmatter(frontmatter, linkedFrontmatter, settings.plugin.shareKey);
frontmatter = mergeFrontmatter(
frontmatter,
linkedFrontmatter,
settings.plugin.shareKey
);
return (
allOtherRepo.find((repo) => frontmatter?.[repo.shareKey]) ?? defaultRepo(settings)
);
Expand Down Expand Up @@ -549,7 +554,6 @@ export function forcePushAttachment(file: TFile, settings: EnveloppeSettings): b
);
});
return needToBeForPush.length !== 0;

}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/utils/parse_frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export function getProperties(
* @return {Properties[]}
*/

function parseMultipleRepo(frontmatter: FrontMatterCache, Properties: Properties): Properties[] {
function parseMultipleRepo(
frontmatter: FrontMatterCache,
Properties: Properties
): Properties[] {
const multipleRepo: Properties[] = [];
if (frontmatter.multipleRepo instanceof Array && frontmatter.multipleRepo.length > 0) {
for (const repo of frontmatter.multipleRepo) {
Expand Down Expand Up @@ -689,7 +692,11 @@ function settingAttachment(
return settingsConversion;
}

export function mergeFrontmatter(frontmatter: FrontMatterCache | null, sourceFrontmatter: FrontMatterCache | null | undefined, shareKey: string) {
export function mergeFrontmatter(
frontmatter: FrontMatterCache | null,
sourceFrontmatter: FrontMatterCache | null | undefined,
shareKey: string
) {
delete sourceFrontmatter?.[shareKey];
if (sourceFrontmatter && frontmatter)
frontmatter = merge.withOptions(
Expand Down

0 comments on commit b63d63b

Please sign in to comment.