Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: Use biome instead of eslint #347

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -70,7 +83,9 @@
},
"ignore": [
"**/npm node_modules",
"**/build"
"**/build",
"**/dist",
"**/src/i18n/locales"
]
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion src/@types/i18next.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resources } from "src/i18n/i18next";
import type { resources } from "src/i18n/i18next";

declare module "i18next" {
interface CustomTypeOptions {
Expand Down
25 changes: 14 additions & 11 deletions src/GitHub/branch.ts
Original file line number Diff line number Diff line change
@@ -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";
Copy link

Choose a reason for hiding this comment

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

Optimize the newBranchOnRepo method to handle exceptions more gracefully.

Consider adding error handling to manage potential exceptions during the branch creation process, which could improve the robustness of the function.


Ensure consistent error handling in the deleteBranchOnRepo method.

Standardize error handling across similar functions to maintain consistency and reliability in the application's behavior.


export class GithubBranch extends FilesManagement {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -90,25 +90,25 @@ export class GithubBranch extends FilesManagement {

async pullRequestOnRepo(prop: Properties): Promise<number> {
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 }),
body: "",
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(
Expand All @@ -130,7 +130,7 @@ export class GithubBranch extends FilesManagement {
async deleteBranchOnRepo(prop: Properties): Promise<boolean> {
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,
Expand Down Expand Up @@ -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",
}
);
Expand Down Expand Up @@ -203,8 +206,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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/GitHub/delete.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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$"))
Expand Down
17 changes: 9 additions & 8 deletions src/GitHub/files.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
import type {
ConvertedLink,
GithubRepo,
LinkedNotes,
Properties,
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 {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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",
}
Expand Down
21 changes: 12 additions & 9 deletions src/GitHub/upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
Deleted,
GitHubPublisherSettings,
MetadataExtractor,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/create_link.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 3 additions & 3 deletions src/commands/file_menu/file.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/file_menu/folder.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/purge.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 3 additions & 3 deletions src/commands/repository_validity.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down
4 changes: 2 additions & 2 deletions src/commands/set.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/commands/share/all_notes.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/share/edited_notes.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading
Loading