Skip to content
Open
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
5 changes: 3 additions & 2 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"style": "off" // Idiomatic and consistent style rules
},
"rules": {
"unicorn/require-post-message-target-origin": "allow", // false-positive
"eslint/curly": "error",
"import-js/order": [
"error",
{
Expand Down Expand Up @@ -56,8 +58,7 @@
"variables": "suggestion"
}
}
],
"unicorn/require-post-message-target-origin": "allow" // false-positive
]
},
"overrides": [
{
Expand Down
38 changes: 28 additions & 10 deletions src/avatarManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export class AvatarManager {
this.avatarStorageFolder = this.extensionState.getAvatarStoragePath();
this.avatars = this.extensionState.getAvatarCache();
this.queue = new AvatarRequestQueue(() => {
if (this.interval !== null) return;
if (this.interval !== null) {
return;
}
this.interval = setInterval(() => {
// Fetch avatars every 10 seconds
this.fetchAvatarsInterval();
Expand Down Expand Up @@ -82,7 +84,9 @@ export class AvatarManager {
private async fetchAvatarsInterval() {
if (this.queue.hasItems()) {
let avatarRequest = this.queue.takeItem();
if (avatarRequest === null) return; // No avatar can be checked at the current time
if (avatarRequest === null) {
return;
} // No avatar can be checked at the current time

let remoteSource = await this.getRemoteSource(avatarRequest); // Fetch the remote source of the avatar
switch (remoteSource.type) {
Expand Down Expand Up @@ -173,7 +177,9 @@ export class AvatarManager {
avatarRequest.email,
commit.author.avatar_url + "&size=54"
);
if (img !== null) this.saveAvatar(avatarRequest.email, img, false);
if (img !== null) {
this.saveAvatar(avatarRequest.email, img, false);
}
return;
}
} else if (res.statusCode === 403) {
Expand Down Expand Up @@ -239,7 +245,9 @@ export class AvatarManager {
if (users.length > 0 && users[0].avatar_url) {
// Avatar url found
let img = await this.downloadAvatarImage(avatarRequest.email, users[0].avatar_url);
if (img !== null) this.saveAvatar(avatarRequest.email, img, false);
if (img !== null) {
this.saveAvatar(avatarRequest.email, img, false);
}
return;
}
} else if (res.statusCode === 429) {
Expand Down Expand Up @@ -277,7 +285,9 @@ export class AvatarManager {
);
identicon = true;
}
if (img !== null) this.saveAvatar(avatarRequest.email, img, identicon);
if (img !== null) {
this.saveAvatar(avatarRequest.email, img, identicon);
}
}

private async downloadAvatarImage(email: string, imageUrl: string): Promise<string | null> {
Expand Down Expand Up @@ -394,7 +404,9 @@ class AvatarRequestQueue {
// Add an existing avatar request item, setting the next time the request should be checked and registering if the current attempt failed
public addItem(item: AvatarRequestItem, checkAfter: number, failedAttempt: boolean) {
item.checkAfter = checkAfter;
if (failedAttempt) item.attempts++;
if (failedAttempt) {
item.attempts++;
}
this.insertItem(item);
}

Expand All @@ -405,8 +417,9 @@ class AvatarRequestQueue {

// Takes an item from the queue if possible, respecting the value set for checkAfter
public takeItem() {
if (this.queue.length > 0 && this.queue[0].checkAfter < new Date().getTime())
if (this.queue.length > 0 && this.queue[0].checkAfter < new Date().getTime()) {
return this.queue.shift()!;
}
return null;
}

Expand All @@ -418,11 +431,16 @@ class AvatarRequestQueue {
prevLength = this.queue.length;
while (l <= r) {
c = (l + r) >> 1;
if (this.queue[c].checkAfter <= item.checkAfter) l = c + 1;
else r = c - 1;
if (this.queue[c].checkAfter <= item.checkAfter) {
l = c + 1;
} else {
r = c - 1;
}
}
this.queue.splice(l, 0, item);
if (prevLength === 0) this.itemsAvailableCallback();
if (prevLength === 0) {
this.itemsAvailableCallback();
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/backend/actions/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export async function cherrypickCommit(
input: ActionPayload<"cherrypickCommit">
): Promise<void> {
const args = ["cherry-pick"];
if (input.parentIndex > 0) args.push("-m", String(input.parentIndex));
if (input.parentIndex > 0) {
args.push("-m", String(input.parentIndex));
}
args.push(input.commitHash);
await git.raw(args);
}
Expand All @@ -24,7 +26,9 @@ export async function revertCommit(
input: ActionPayload<"revertCommit">
): Promise<void> {
const args = ["revert", "--no-edit"];
if (input.parentIndex > 0) args.push("-m", String(input.parentIndex));
if (input.parentIndex > 0) {
args.push("-m", String(input.parentIndex));
}
args.push(input.commitHash);
await git.raw(args);
}
Expand Down
12 changes: 9 additions & 3 deletions src/backend/queries/commitDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ async function fetchCommitInfo(
const stdout = await git.raw(["show", "--quiet", commitHash, `--format=${format}`]);
const lines = stdout.split(eolRegex);
let lastLine = lines.length - 1;
while (lastLine >= 0 && lines[lastLine] === "") lastLine--;
while (lastLine >= 0 && lines[lastLine] === "") {
lastLine--;
}
const commitInfo = lines[0].split(gitLogSeparator);
return {
hash: commitInfo[0],
Expand Down Expand Up @@ -80,7 +82,9 @@ export async function commitDetails(
const fileLookup: { [file: string]: number } = {};
for (let i = 1; i < nameStatusLines.length - 1; i++) {
const line = nameStatusLines[i].split("\t");
if (line.length < 2) break;
if (line.length < 2) {
break;
}
const oldFilePath = toPath(line[1]);
const newFilePath = toPath(line[line.length - 1]);
fileLookup[newFilePath] = details.fileChanges.length;
Expand All @@ -95,7 +99,9 @@ export async function commitDetails(

for (let i = 1; i < numStatLines.length - 1; i++) {
const line = numStatLines[i].split("\t");
if (line.length !== 3) break;
if (line.length !== 3) {
break;
}
const fileName = line[2].replace(/(.*){.* => (.*)}/, "$1$2").replace(/.* => (.*)/, "$1");
if (typeof fileLookup[fileName] === "number") {
details.fileChanges[fileLookup[fileName]].additions = parseInt(line[0]);
Expand Down
24 changes: 18 additions & 6 deletions src/backend/queries/loadCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ type LoadCommitsInput = {
async function getRefs(git: SimpleGit, showRemoteBranches: boolean): Promise<GitRefData> {
try {
const args = ["show-ref"];
if (!showRemoteBranches) args.push("--heads", "--tags");
if (!showRemoteBranches) {
args.push("--heads", "--tags");
}
args.push("-d", "--head");
const stdout = await git.raw(args);
const refData: GitRefData = { head: null, refs: [] };
const lines = stdout.split(eolRegex);
for (let i = 0; i < lines.length - 1; i++) {
const parts = lines[i].split(" ");
if (parts.length < 2) continue;
if (parts.length < 2) {
continue;
}
const hash = parts.shift()!;
const ref = parts.join(" ");
if (ref.startsWith("refs/heads/")) {
Expand Down Expand Up @@ -67,15 +71,19 @@ async function getLog(
args.push(branch);
} else {
args.push("--branches", "--tags");
if (showRemoteBranches) args.push("--remotes");
if (showRemoteBranches) {
args.push("--remotes");
}
}
try {
const stdout = await git.raw(args);
const lines = stdout.split(eolRegex);
const commits: GitLogEntry[] = [];
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i].split(gitLogSeparator);
if (line.length !== 6) break;
if (line.length !== 6) {
break;
}
commits.push({
hash: line[0],
parentHashes: line[1].split(" "),
Expand All @@ -94,7 +102,9 @@ async function getLog(
async function getUnsavedChanges(git: SimpleGit) {
try {
const status = await git.status();
if (status.files.length === 0) return null;
if (status.files.length === 0) {
return null;
}
return { branch: status.current ?? "HEAD", changes: status.files.length };
} catch {
return null;
Expand All @@ -115,7 +125,9 @@ export async function loadCommits(

let commits = rawCommits;
const moreCommitsAvailable = commits.length === maxCommits + 1;
if (moreCommitsAvailable) commits = commits.slice(0, -1);
if (moreCommitsAvailable) {
commits = commits.slice(0, -1);
}

if (refData.head !== null) {
for (let i = 0; i < commits.length; i++) {
Expand Down
11 changes: 8 additions & 3 deletions src/backend/utils/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ export function evalPromises<X, Y>(
if (!rejected) {
results[cur] = result;
completed++;
if (nextPromise < data.length) startNext();
else if (completed === data.length) resolve(results);
if (nextPromise < data.length) {
startNext();
} else if (completed === data.length) {
resolve(results);
}
}
})
.catch(() => {
reject();
rejected = true;
});
}
for (let i = 0; i < maxParallel && i < data.length; i++) startNext();
for (let i = 0; i < maxParallel && i < data.length; i++) {
startNext();
}
}
});
}
4 changes: 3 additions & 1 deletion src/diffDocProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class DiffDocProvider implements vscode.TextDocumentContentProvider {

public provideTextDocumentContent(uri: vscode.Uri): string | Thenable<string> {
let document = this.docs.get(uri.toString());
if (document) return document.value;
if (document) {
return document.value;
}

let request = decodeDiffDocUri(uri);
return this.gitClient()
Expand Down
8 changes: 6 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export function activate(context: vscode.ExtensionContext) {

void (async () => {
repoManager.removeReposNotInWorkspace();
if (!(await repoManager.checkReposExist())) repoManager.sendRepos();
if (!(await repoManager.checkReposExist())) {
repoManager.sendRepos();
}
await repoSearch.searchWorkspaceForRepos();
repoWatcher.startWatching();
})();
Expand All @@ -58,7 +60,9 @@ export function activate(context: vscode.ExtensionContext) {
);
let bridge!: WebviewBridge;
const repoFileWatcher = new RepoFileWatcher(() => {
if (panel.visible) bridge.post({ command: "refresh" });
if (panel.visible) {
bridge.post({ command: "refresh" });
}
});
bridge = webviewBridgeFactory(panel.webview, repoFileWatcher);
avatarManager.registerBridge(bridge.post.bind(bridge));
Expand Down
4 changes: 3 additions & 1 deletion src/extension/messageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export function registerMessageHandlers(
// --- Infrastructure handlers ---

bridge.onMessage("selectRepo", (msg) => {
if (msg.repo === currentRepo) return;
if (msg.repo === currentRepo) {
return;
}
currentRepo = msg.repo;
gitClient.setRepo(msg.repo);
extensionState.setLastActiveRepo(msg.repo);
Expand Down
15 changes: 11 additions & 4 deletions src/extension/repoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function createRepoManager(
const sorted = getRepos();
const numRepos = Object.keys(sorted).length;
statusBarItem.setNumRepos(numRepos);
if (viewCallback !== null) viewCallback(sorted, numRepos);
if (viewCallback !== null) {
viewCallback(sorted, numRepos);
}
}

function removeRepo(repo: string) {
Expand All @@ -52,7 +54,9 @@ export function createRepoManager(
function isDirectoryWithinRepos(path: string) {
const repoPaths = Object.keys(repos);
for (let i = 0; i < repoPaths.length; i++) {
if (path === repoPaths[i] || path.startsWith(repoPaths[i] + "/")) return true;
if (path === repoPaths[i] || path.startsWith(repoPaths[i] + "/")) {
return true;
}
}
return false;
}
Expand Down Expand Up @@ -96,8 +100,9 @@ export function createRepoManager(
if (
rootsExact.indexOf(repoPaths[i]) === -1 &&
!rootsFolder.find((x) => repoPaths[i].startsWith(x))
)
) {
removeRepo(repoPaths[i]);
}
}
}

Expand All @@ -113,7 +118,9 @@ export function createRepoManager(
changes = true;
}
}
if (changes) sendRepos();
if (changes) {
sendRepos();
}
resolve(changes);
}
);
Expand Down
4 changes: 3 additions & 1 deletion src/extension/webviewBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export function webviewBridgeFactory(webview: vscode.Webview, repoFileWatcher: R

webview.onDidReceiveMessage(async (msg: RequestMessage) => {
const handler = handlers.get(msg.command);
if (!handler) return;
if (!handler) {
return;
}
repoFileWatcher.mute();
await handler(msg);
repoFileWatcher.unmute();
Expand Down
8 changes: 6 additions & 2 deletions src/extension/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export function createWebviewPanel(opts: {
repoManager.deregisterViewCallback();
while (disposables.length) {
const x = disposables.pop();
if (x) x.dispose();
if (x) {
x.dispose();
}
}
}

Expand All @@ -91,7 +93,9 @@ export function createWebviewPanel(opts: {
);

repoManager.registerViewCallback((repos: GitRepoSet, numRepos: number) => {
if (!panel.visible) return;
if (!panel.visible) {
return;
}
if ((numRepos === 0 && isGraphViewLoaded) || (numRepos > 0 && !isGraphViewLoaded)) {
update();
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/extension/workspaceSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ export function createRepoSearch(repoManager: RepoManager, config: Config) {
if (typeof rootFolders !== "undefined") {
for (let i = 0; i < rootFolders.length; i++) {
const path = getPathFromUri(rootFolders[i].uri);
if (await searchDirectoryForRepos(path, maxDepthOfRepoSearch)) changes = true;
if (await searchDirectoryForRepos(path, maxDepthOfRepoSearch)) {
changes = true;
}
}
}
if (changes) repoManager.sendRepos();
if (changes) {
repoManager.sendRepos();
}
}

return {
Expand Down
Loading
Loading