提交 c914203d 编写于 作者: T Tomas Vik

Merge branch 'refactor--reduce-eslint-warnings' into 'main'

refactor: reduce eslint warnings

See merge request gitlab-org/gitlab-vscode-extension!217
......@@ -51,7 +51,7 @@ export class DataProvider implements vscode.TreeDataProvider<ItemModel | vscode.
}
// eslint-disable-next-line class-methods-use-this
getParent() {
getParent(): null {
return null;
}
......@@ -61,7 +61,7 @@ export class DataProvider implements vscode.TreeDataProvider<ItemModel | vscode.
return item;
}
refresh() {
refresh(): void {
this.eventEmitter.fire();
}
}
export const prettyJson = (obj: Record<string, unknown>) => JSON.stringify(obj, null, 2);
export const stackToArray = (stack: string | undefined) => stack && stack.split('\n');
export const prettyJson = (obj: Record<string, unknown>): string => JSON.stringify(obj, null, 2);
export const stackToArray = (stack: string | undefined): string[] => (stack ?? '').split('\n');
export interface IDetailedError extends Error {
readonly details: string;
......
......@@ -33,7 +33,7 @@ export class GitService {
// If remote name isn't provided, the command returns default remote for the current branch
// if there's no default branch, the command fails but that's part of the normal flow and it can't throw
const getUrlForRemoteName = async (name: string) =>
this.fetch(`git ls-remote --get-url ${name}`).catch(e => null);
this.fetch(`git ls-remote --get-url ${name}`).catch(() => null);
const getFirstRemoteName = async () => {
const multilineRemotes = await this.fetch('git remote');
......
......@@ -127,7 +127,9 @@ export async function fetchCurrentProject(workspaceFolder: string): Promise<GitL
}
}
export async function fetchCurrentProjectSwallowError(workspaceFolder: string) {
export async function fetchCurrentProjectSwallowError(
workspaceFolder: string,
): Promise<GitLabProject | null> {
try {
return await fetchCurrentProject(workspaceFolder);
} catch (error) {
......@@ -136,7 +138,9 @@ export async function fetchCurrentProjectSwallowError(workspaceFolder: string) {
}
}
export async function fetchCurrentPipelineProject(workspaceFolder: string) {
export async function fetchCurrentPipelineProject(
workspaceFolder: string,
): Promise<GitLabProject | null> {
try {
const { pipelineGitRemoteName } = getExtensionConfiguration();
const remote = await createGitService(workspaceFolder).fetchGitRemote(pipelineGitRemoteName);
......@@ -524,7 +528,7 @@ export async function createSnippet(workspaceFolder: string, data: { id: string
return snippet;
}
export async function validateCIConfig(workspaceFolder: string, content: string) {
export async function validateCIConfig(workspaceFolder: string, content: string): Promise<boolean> {
let validCIConfig = null;
try {
......@@ -536,7 +540,7 @@ export async function validateCIConfig(workspaceFolder: string, content: string)
handleError(new UserFriendlyError('Failed to validate CI configuration.', e));
}
return validCIConfig;
return Boolean(validCIConfig);
}
interface Discussion {
notes: {
......
/* eslint-disable max-classes-per-file, @typescript-eslint/no-explicit-any */
import { API } from '../api/git';
const removeFromArray = (array: any[], element: any): any[] => {
return array.filter(el => el !== element);
};
......@@ -55,7 +57,7 @@ export class FakeGitExtension {
};
}
getAPI() {
return this.gitApi;
getAPI(): API {
return (this.gitApi as unknown) as API;
}
}
......@@ -53,11 +53,11 @@ export class Uri implements vscode.Uri {
return `${this.scheme}://${this.authority}${this.path}${this.query}#${this.fragment}`;
}
toJSON() {
toJSON(): string {
return JSON.stringify(this);
}
static parse(stringUri: string) {
static parse(stringUri: string): Uri {
const url = new URL(stringUri);
const [query, fragment] = url.search.split('#');
return new Uri({
......@@ -69,7 +69,7 @@ export class Uri implements vscode.Uri {
});
}
static file(filePath: string) {
static file(filePath: string): Uri {
return new Uri({
scheme: 'file',
authority: '',
......
import * as vscode from 'vscode';
import { SinonSandbox } from 'sinon';
export const createAndOpenFile = async (testFileUri: vscode.Uri) => {
export const createAndOpenFile = async (testFileUri: vscode.Uri): Promise<void> => {
const createFileEdit = new vscode.WorkspaceEdit();
createFileEdit.createFile(testFileUri);
await vscode.workspace.applyEdit(createFileEdit);
await vscode.window.showTextDocument(testFileUri);
};
export const closeAndDeleteFile = async (testFileUri: vscode.Uri) => {
export const closeAndDeleteFile = async (testFileUri: vscode.Uri): Promise<void> => {
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
const edit = new vscode.WorkspaceEdit();
edit.deleteFile(testFileUri);
await vscode.workspace.applyEdit(edit);
};
export const simulateQuickPickChoice = (sandbox: SinonSandbox, nthItem: number) => {
export const simulateQuickPickChoice = (sandbox: SinonSandbox, nthItem: number): void => {
sandbox.stub(vscode.window, 'showQuickPick').callsFake(async options => {
return (await options)[nthItem];
});
};
export const getWorkspaceFolder = () => {
export const getWorkspaceFolder = (): string | undefined => {
const folders = vscode.workspace.workspaceFolders;
return folders && folders[0]?.uri.fsPath;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册