🔨 refactor: #61 Resolve simple sonar code smells

This commit is contained in:
Nathan Smith 2024-03-28 15:59:24 -04:00
parent 98ec93d05d
commit ee0d0ced7f
8 changed files with 13 additions and 13 deletions

View file

@ -96,7 +96,7 @@ async function getIssue(org: string, repo: string, issue: number, token?: string
return result.json as IssueResponse;
}
async function listIssuesForToken(params: IssueListParams = {}, token: string): Promise<IssueListResponse> {
async function listIssuesForToken(params: IssueListParams, token: string): Promise<IssueListResponse> {
const url = addParams(`${baseApi}/issues`, params as Record<string, unknown>);
const result = await queueRequest({ url }, token);
return result.json as IssueListResponse;

View file

@ -44,7 +44,7 @@ export class Cache {
public readonly orgs: Record<string, OrgCache> = {};
public readonly queries = new QueryCache();
getGeneric(url: string): unknown | null {
getGeneric(url: string): unknown {
return this.getCacheValue(this.generic[url] ?? null);
}

View file

@ -20,6 +20,7 @@ import type { GithubAccount } from "src/settings";
import { PluginSettings } from "src/plugin";
const cache = new Cache();
const tokenMatchRegex = /repo:(.+)\//;
function getAccount(org?: string): GithubAccount | undefined {
const account =
@ -33,9 +34,9 @@ function getToken(org?: string, query?: string): string | undefined {
// Try and parse org from the query
if (!org && query) {
const match = query.match(/repo:(.+)\//);
if (match && match[0] !== null) {
_org = match[1];
const match = tokenMatchRegex.exec(query);
if (match?.[0] !== null) {
_org = match?.[1];
}
}

View file

@ -63,7 +63,6 @@ export function createTag(href: string) {
}
});
}
// TODO: add support for other stuff here
}
return container;

View file

@ -34,7 +34,7 @@ export function createInlineViewPlugin(_plugin: GithubLinkPlugin) {
class InlineViewPluginValue implements PluginValue {
public readonly view: EditorView;
private readonly match = new MatchDecorator({
regexp: /(https:\/\/)?github\.com[\S]+/g,
regexp: /(https:\/\/)?github\.com\S+/g,
decorate: (add, from, to, match, view) => {
const shouldRender = this.shouldRender(view, from, to, match);
if (shouldRender) {
@ -79,6 +79,7 @@ export function createInlineViewPlugin(_plugin: GithubLinkPlugin) {
const input = match.input ?? "";
const index = match.index ?? 0;
const matchValue = match[0];
// eslint-disable-next-line unused-imports/no-unused-vars
const endIndex = index + matchValue.length;
if (input[index - 1] === "(" && matchValue.endsWith(")")) {
return false;

View file

@ -57,8 +57,7 @@ export async function renderTable<T extends { items: unknown[] } | unknown[]>(
const cell = tr.createEl("td");
const renderer = ALL_COLUMNS[params.queryType][col];
if (renderer) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
renderer.cell(row as any, cell);
renderer.cell(row, cell);
} else {
const cellVal = getProp(row, col);
if (cellVal !== null) {

View file

@ -140,7 +140,7 @@ export class GithubLinkPluginSettingsTab extends PluginSettingTab {
button.setTooltip("Save account");
button.setIcon("save");
button.onClick(async () => {
if (!this.newAccount || !this.newAccount.name || !this.newAccount.token) {
if (!this.newAccount?.name || !this.newAccount.token) {
return;
}
PluginSettings.accounts.unshift(this.newAccount);

View file

@ -64,7 +64,7 @@ export function sanitizeObject<T>(params: T, usableFieldMap: Record<keyof T, boo
/**
* Attempts to handle getting a nested property using a string of js object notation
*/
export function getProp<T extends { [key: string]: unknown }>(value: T, prop: string): unknown | null {
export function getProp<T extends { [key: string]: unknown }>(value: T, prop: string): unknown {
if (!prop.includes(".")) {
return value[prop] ?? null;
}
@ -96,7 +96,7 @@ export function safeJSONParse<T>(value: string, props: Record<keyof T, boolean>)
const result: any = {};
for (const [_prop, include] of Object.entries(props)) {
const prop = _prop as keyof T;
if (include && parsed[prop as keyof T]) {
if (include && parsed[prop]) {
result[prop] = parsed[prop];
}
}
@ -143,7 +143,7 @@ export function promiseWithResolvers<T>() {
export class RequestError implements Error {
name: string;
message: string;
stack?: string | undefined;
stack?: string;
headers: Record<string, string>;
status: number;
constructor(public readonly originalError: Error) {