diff --git a/src/audit.ts b/src/audit.ts index dc77611..c03ea63 100644 --- a/src/audit.ts +++ b/src/audit.ts @@ -12,40 +12,36 @@ export class Audit { productionFlag: string, jsonFlag: string ): void { - try { - const auditOptions: Array = ['audit', '--audit-level', auditLevel] + const auditOptions: string[] = ['audit', '--audit-level', auditLevel] - const isWindowsEnvironment: boolean = process.platform == 'win32' - const cmd: string = isWindowsEnvironment ? 'npm.cmd' : 'npm' + const isWindowsEnvironment: boolean = process.platform === 'win32' + const cmd: string = isWindowsEnvironment ? 'npm.cmd' : 'npm' - if (productionFlag === 'true') { - auditOptions.push('--omit=dev') - } - - if (jsonFlag === 'true') { - auditOptions.push('--json') - } - - const result: SpawnSyncReturns = spawnSync(cmd, auditOptions, { - encoding: 'utf-8', - maxBuffer: SPAWN_PROCESS_BUFFER_SIZE - }) - - if (result.error) { - throw result.error - } - if (result.status === null) { - throw new Error('the subprocess terminated due to a signal.') - } - if (result.stderr && result.stderr.length > 0) { - throw new Error(result.stderr) - } - - this.status = result.status - this.stdout = result.stdout - } catch (error) { - throw error + if (productionFlag === 'true') { + auditOptions.push('--omit=dev') } + + if (jsonFlag === 'true') { + auditOptions.push('--json') + } + + const result: SpawnSyncReturns = spawnSync(cmd, auditOptions, { + encoding: 'utf-8', + maxBuffer: SPAWN_PROCESS_BUFFER_SIZE + }) + + if (result.error) { + throw result.error + } + if (result.status === null) { + throw new Error('the subprocess terminated due to a signal.') + } + if (result.stderr?.length > 0) { + throw new Error(result.stderr) + } + + this.status = result.status + this.stdout = result.stdout } public foundVulnerability(): boolean { diff --git a/src/issue.ts b/src/issue.ts index 598441d..d3e05a0 100644 --- a/src/issue.ts +++ b/src/issue.ts @@ -47,5 +47,5 @@ export async function getExistingIssueNumber( .filter(i => i.title === core.getInput('issue_title')) .shift() - return iss === undefined ? null : iss.number + return iss?.number ?? null } diff --git a/src/main.ts b/src/main.ts index 2cd14fe..c766f90 100644 --- a/src/main.ts +++ b/src/main.ts @@ -114,9 +114,7 @@ export async function run(): Promise { } } } catch (e: unknown) { - if (e instanceof Error) { - core.setFailed(e.message) - } + core.setFailed((e as Error)?.message ?? 'Unknown error occurred') } } diff --git a/src/pr.ts b/src/pr.ts index 772a7bc..05a5a8f 100644 --- a/src/pr.ts +++ b/src/pr.ts @@ -7,7 +7,7 @@ export async function createComment( prNumber: number, body: string ): Promise { - octokit.issues.createComment({ + await octokit.issues.createComment({ owner, repo, issue_number: prNumber, diff --git a/tsconfig.json b/tsconfig.json index 5a19263..52ffdbe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,16 @@ { "compilerOptions": { - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "outDir": "./lib", /* Redirect output structure to the directory. */ - "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020' or 'ESNEXT'. */ + "module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "outDir": "./lib", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ }, - "exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts"] + "exclude": [ + "node_modules", + "**/*.test.ts", + "vitest.config.ts" + ] }