diff --git a/src/autofill.ts b/src/autofill.ts index 9ae6cbe2..d3c01a19 100644 --- a/src/autofill.ts +++ b/src/autofill.ts @@ -40,8 +40,8 @@ export async function makeAndFillCommitMsg(repository: Repository) { const newMsg = generateMsg(fileChanges, oldMsg); console.debug("New message: ", newMsg); - const commitMessageValue = await getCommitTemplateValue() - console.debug({ commitMessageValue }) + const commitMessageValue = await getCommitTemplateValue(); + console.debug({ commitMessageValue }); setCommitMsg(repository, newMsg); } diff --git a/src/extension.ts b/src/extension.ts index b05c7318..1ee8beff 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -71,4 +71,4 @@ export function activate(context: vscode.ExtensionContext) { } // eslint-disable-next-line @typescript-eslint/no-empty-function -export function deactivate() { } +export function deactivate() {} diff --git a/src/git/cli.ts b/src/git/cli.ts index bb5ade15..eed2c64e 100644 --- a/src/git/cli.ts +++ b/src/git/cli.ts @@ -13,7 +13,11 @@ const exec = util.promisify(childProcess.exec); /** * Run a `git` subcommand with options and return output. */ -export function execute(cwd: string, subcommand: string, options: string[] = []) { +export function execute( + cwd: string, + subcommand: string, + options: string[] = [] +) { const command = `git ${subcommand} ${options.join(" ")}`; const result = exec(command, { cwd }); @@ -45,12 +49,8 @@ async function _diffIndex(options: string[] = []): Promise> { "HEAD", ]; - const workspace = getWorkspaceFolder() - const { stdout, stderr } = await execute( - workspace, - cmd, - fullOptions - ); + const workspace = getWorkspaceFolder(); + const { stdout, stderr } = await execute(workspace, cmd, fullOptions); if (stderr) { console.debug(`stderr for 'git ${cmd}' command:`, stderr); diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index 83401a96..c1456b13 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -11,13 +11,13 @@ * * To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git. */ -import * as fs from 'fs'; -import * as path from 'path'; +import * as fs from "fs"; +import * as path from "path"; import { getWorkspaceFolder } from "../workspace"; import { execute } from "./cli"; -const CONFIG_SUBCOMMAND = "config" -const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template' +const CONFIG_SUBCOMMAND = "config"; +const COMMIT_TEMPLATE_IDENTIFIER = "commit.template"; /** * Get a value from the Git config. @@ -25,7 +25,7 @@ const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template' * The CLI will assume local (project) project by default. */ export async function _getConfigValue(options: string[]) { - const workspace = getWorkspaceFolder() + const workspace = getWorkspaceFolder(); const { stdout, stderr } = await execute( workspace, CONFIG_SUBCOMMAND, @@ -36,7 +36,7 @@ export async function _getConfigValue(options: string[]) { console.debug(`stderr for 'git ${CONFIG_SUBCOMMAND}' command:`, stderr); } - return stdout + return stdout; } /** @@ -46,10 +46,10 @@ export async function _getConfigValue(options: string[]) { */ async function _getCommitTemplatePath() { try { - const options = [COMMIT_TEMPLATE_IDENTIFIER] - return await _getConfigValue(options) + const options = [COMMIT_TEMPLATE_IDENTIFIER]; + return await _getConfigValue(options); } catch (_e) { - return null + return null; } } @@ -59,26 +59,26 @@ async function _getCommitTemplatePath() { * NB. Use current workspace as the base path. */ function _readFile(filePath: string) { - const workspace = getWorkspaceFolder() - const p = path.join(workspace, filePath) + const workspace = getWorkspaceFolder(); + const p = path.join(workspace, filePath); - let value + let value; try { - value = fs.readFileSync(p, "utf-8") + value = fs.readFileSync(p, "utf-8"); } catch (err) { - console.error(`Could not find template file: ${p}. ${err.toString()}`) + console.error(`Could not find template file: ${p}. ${err.toString()}`); - return null + return null; } if (!value) { - return null + return null; } - console.debug(`Read ${p} and found: ${value}`) + console.debug(`Read ${p} and found: ${value}`); - return value + return value; } /** @@ -87,12 +87,12 @@ function _readFile(filePath: string) { * Return null if file is not configured or file is missing, without aborting. */ export async function getCommitTemplateValue() { - const filePath = await _getCommitTemplatePath() + const filePath = await _getCommitTemplatePath(); if (!filePath) { - console.error(`Could not read missing file: ${filePath}`) - return null + console.error(`Could not read missing file: ${filePath}`); + return null; } - return _readFile(filePath) + return _readFile(filePath); } diff --git a/src/workspace.ts b/src/workspace.ts index d84e3576..b77f7516 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -2,7 +2,7 @@ import { workspace } from "vscode"; export function getWorkspaceFolder(): string { const { workspaceFolders } = workspace; - console.log({ workspaceFolders }) + console.log({ workspaceFolders }); return workspaceFolders ? workspaceFolders[0].uri.fsPath : ""; -}; +}