From af56e29ad9e7ddab2b35ce1a5ad28bfa3bfd8a58 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 21 Jan 2025 13:03:20 +0100 Subject: [PATCH] Address eslint errors and warnings. --- __tests__/cache.test.ts | 4 ++-- __tests__/cleanup.test.ts | 5 ++--- __tests__/graalvm.test.ts | 22 +++++++++++----------- __tests__/liberica.test.ts | 12 +++++++----- __tests__/mandrel.test.ts | 12 ++++++------ __tests__/msvc.test.ts | 4 ++-- __tests__/sbom.test.ts | 7 +++++-- __tests__/utils.test.ts | 7 +++---- eslint.config.mjs | 1 + package.json | 2 +- src/cleanup.ts | 1 - src/graalvm.ts | 2 +- src/mandrel.ts | 8 ++++++-- src/msvc.ts | 1 - tsconfig.base.json | 2 +- 15 files changed, 48 insertions(+), 42 deletions(-) diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index cc73bf5..0efb29d 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -94,7 +94,7 @@ describe('dependency cache', () => { beforeEach(() => { spyCacheRestore = jest .spyOn(cache, 'restoreCache') - .mockImplementation((paths: string[], primaryKey: string) => + .mockImplementation((_paths: string[], _primaryKey: string) => Promise.resolve(undefined) ) spyWarning.mockImplementation(() => null) @@ -184,7 +184,7 @@ describe('dependency cache', () => { beforeEach(() => { spyCacheSave = jest .spyOn(cache, 'saveCache') - .mockImplementation((paths: string[], key: string) => + .mockImplementation((_paths: string[], _key: string) => Promise.resolve(0) ) spyWarning.mockImplementation(() => null) diff --git a/__tests__/cleanup.test.ts b/__tests__/cleanup.test.ts index 9a70f2a..c3d1260 100644 --- a/__tests__/cleanup.test.ts +++ b/__tests__/cleanup.test.ts @@ -35,7 +35,6 @@ describe('cleanup', () => { ReturnType, Parameters > - let spyJobStatusSuccess: jest.SpyInstance beforeEach(() => { spyWarning = jest.spyOn(core, 'warning') @@ -50,7 +49,7 @@ describe('cleanup', () => { }) it('does not fail nor warn even when the save process throws a ReserveCacheError', async () => { - spyCacheSave.mockImplementation((paths: string[], key: string) => + spyCacheSave.mockImplementation((_paths: string[], _key: string) => Promise.reject( new cache.ReserveCacheError( 'Unable to reserve cache with key, another job may be creating this cache.' @@ -66,7 +65,7 @@ describe('cleanup', () => { }) it('does not fail even though the save process throws error', async () => { - spyCacheSave.mockImplementation((paths: string[], key: string) => + spyCacheSave.mockImplementation((_paths: string[], _key: string) => Promise.reject(new Error('Unexpected error')) ) jest.spyOn(core, 'getInput').mockImplementation((name: string) => { diff --git a/__tests__/graalvm.test.ts b/__tests__/graalvm.test.ts index 29edaa7..9bc70a0 100644 --- a/__tests__/graalvm.test.ts +++ b/__tests__/graalvm.test.ts @@ -13,7 +13,7 @@ process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE') process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP') test('request invalid version/javaVersion', async () => { - for (var combination of [ + for (const combination of [ ['22.3.0', '7'], ['22.3', '17'], ['22.3', '7'] @@ -23,7 +23,7 @@ test('request invalid version/javaVersion', async () => { await graalvm.setUpGraalVMRelease('', combination[0], combination[1]) } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } @@ -36,17 +36,17 @@ test('request invalid version/javaVersion', async () => { test('find version/javaVersion', async () => { // Make sure the action can find the latest Java version for known major versions - for (var majorJavaVersion of ['17', '20']) { + for (const majorJavaVersion of ['17', '20']) { await graalvm.findLatestGraalVMJDKCEJavaVersion(majorJavaVersion) } let error = new Error('unexpected') try { await graalvm.findLatestGraalVMJDKCEJavaVersion('11') - fail('Should not find Java version for 11') + throw new Error('Should not find Java version for 11') } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } @@ -68,7 +68,7 @@ test('find version/javaVersion', async () => { findGraalVMVersion(invalidRelease) } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } @@ -78,17 +78,17 @@ test('find version/javaVersion', async () => { findHighestJavaVersion(latestRelease, 'invalid') } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } expect(error.message).toContain('Could not find highest Java version.') }) -test('find version/javaVersion', async () => { - let url22EA = await findLatestEABuildDownloadUrl('22-ea') +test('find EA version/javaVersion', async () => { + const url22EA = await findLatestEABuildDownloadUrl('22-ea') expect(url22EA).not.toBe('') - let urlLatestEA = await findLatestEABuildDownloadUrl('latest-ea') + const urlLatestEA = await findLatestEABuildDownloadUrl('latest-ea') expect(urlLatestEA).not.toBe('') let error = new Error('unexpected') @@ -96,7 +96,7 @@ test('find version/javaVersion', async () => { await findLatestEABuildDownloadUrl('8-ea') } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } diff --git a/__tests__/liberica.test.ts b/__tests__/liberica.test.ts index 55d23fb..92bbee9 100644 --- a/__tests__/liberica.test.ts +++ b/__tests__/liberica.test.ts @@ -7,6 +7,8 @@ import {expect, test} from '@jest/globals' process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE') process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP') +/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectLatestToBe", "expectURL"] }] */ + test('find latest JDK version', async () => { // Make sure the action can find the latest Java version for known major versions await expectLatestToBe('11', atLeast('11.0.22+12')) @@ -61,8 +63,8 @@ function atLeast(expectedMinVersion: string): verifier { return function ( version: string, major: number, - minor: number, - patch: number + _minor: number, + _patch: number ) { expect(major).toBe(expectedMajor) if (semver.compareBuild(version, expectedMinVersion) < 0) { @@ -90,9 +92,9 @@ function upToBuild(expectedMinVersion: string): verifier { function exactly(expectedVersion: string): verifier { return function ( version: string, - major: number, - minor: number, - patch: number + _major: number, + _minor: number, + _patch: number ) { if (semver.compareBuild(version, expectedVersion) != 0) { throw new Error(`Expected version ${expectedVersion} but got ${version}`) diff --git a/__tests__/mandrel.test.ts b/__tests__/mandrel.test.ts index efa78ce..4eb1c27 100644 --- a/__tests__/mandrel.test.ts +++ b/__tests__/mandrel.test.ts @@ -7,7 +7,7 @@ process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE') process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP') test('request invalid version/javaVersion combination', async () => { - for (var combination of [ + for (const combination of [ ['mandrel-23.1.1.0-Final', '17'], ['mandrel-23.0.2.1-Final', '21'] ]) { @@ -16,7 +16,7 @@ test('request invalid version/javaVersion combination', async () => { await mandrel.setUpMandrel(combination[0], combination[1]) } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } @@ -27,7 +27,7 @@ test('request invalid version/javaVersion combination', async () => { } }) test('request invalid version', async () => { - for (var combination of [ + for (const combination of [ ['mandrel-23.1.1.0', '21'], ['mandrel-23.0.2.1', '17'] ]) { @@ -36,7 +36,7 @@ test('request invalid version', async () => { await mandrel.setUpMandrel(combination[0], combination[1]) } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } @@ -56,7 +56,7 @@ test('find latest', async () => { test('get known latest Mandrel for specific JDK', async () => { // Test deprecated versions that won't get updates anymore - for (var combination of [ + for (const combination of [ ['11', '22.2.0.0-Final'], ['20', '23.0.1.2-Final'] ]) { @@ -68,7 +68,7 @@ test('get known latest Mandrel for specific JDK', async () => { test('get latest Mandrel for specific JDK', async () => { // Test supported versions - for (var javaVersion of ['17', '21']) { + for (const javaVersion of ['17', '21']) { const latest = await mandrel.getLatestMandrelReleaseUrl(javaVersion) expect(latest).toContain(`mandrel-java${javaVersion}`) } diff --git a/__tests__/msvc.test.ts b/__tests__/msvc.test.ts index 871244d..eb83c0e 100644 --- a/__tests__/msvc.test.ts +++ b/__tests__/msvc.test.ts @@ -7,7 +7,7 @@ process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE') process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP') test('decide whether Window env must be set up for GraalVM for JDK', async () => { - for (var javaVersion of [ + for (const javaVersion of [ '17', '17.0.8', '17.0', @@ -22,7 +22,7 @@ test('decide whether Window env must be set up for GraalVM for JDK', async () => }) test('decide whether Window env must be set up for legacy GraalVM', async () => { - for (var combination of [ + for (const combination of [ ['7', '22.3.0'], ['17', '22.3'], ['7', '22.3'], diff --git a/__tests__/sbom.test.ts b/__tests__/sbom.test.ts index f0fabf6..02c47b3 100644 --- a/__tests__/sbom.test.ts +++ b/__tests__/sbom.test.ts @@ -248,10 +248,13 @@ describe('sbom feature', () => { const invalidSBOM = { 'out-of-spec-field': {} } + let error try { await setUpAndProcessSBOM(invalidSBOM) - fail('Expected an error since invalid JSON was passed') - } catch (error) { + throw new Error('Expected an error since invalid JSON was passed') + } catch (e) { + error = e + } finally { expect(error).toBeInstanceOf(Error) } }) diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index b35791f..b73098a 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -1,9 +1,8 @@ -import * as path from 'path' import {expect, test} from '@jest/globals' import {toSemVer} from '../src/utils' test('convert version', async () => { - for (var inputAndExpectedOutput of [ + for (const inputAndExpectedOutput of [ ['22', '22.0.0'], ['22.0', '22.0.0'], ['22.0.0', '22.0.0'], @@ -17,13 +16,13 @@ test('convert version', async () => { }) test('convert invalid version', async () => { - for (var input of ['dev', 'abc', 'a.b.c']) { + for (const input of ['dev', 'abc', 'a.b.c']) { let error = new Error('unexpected') try { toSemVer(input) } catch (err) { if (!(err instanceof Error)) { - fail(`Unexpected non-Error: ${err}`) + throw new Error(`Unexpected non-Error: ${err}`) } error = err } diff --git a/eslint.config.mjs b/eslint.config.mjs index de18a7e..9147a87 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -70,6 +70,7 @@ export default [ camelcase: 'off', 'eslint-comments/no-use': 'off', 'eslint-comments/no-unused-disable': 'off', + '@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}], 'i18n-text/no-en': 'off', 'import/no-namespace': 'off', 'no-console': 'off', diff --git a/package.json b/package.json index 6546975..312fed8 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint": "npx eslint .", "package": "ncc build -o dist/main src/main.ts && ncc build -o dist/cleanup src/cleanup.ts", "test": "npx jest", - "all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package" + "all": "npm run format:write && npm run lint && npm run test && npm run package" }, "repository": { "type": "git", diff --git a/src/cleanup.ts b/src/cleanup.ts index 4ebd75a..30a89ce 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -46,7 +46,6 @@ async function saveCache(): Promise { * @returns Promise that will ignore error reported by the given promise */ async function ignoreErrors(promise: Promise): Promise { - /* eslint-disable github/no-then */ return new Promise(resolve => { promise .catch(error => { diff --git a/src/graalvm.ts b/src/graalvm.ts index b39391f..f939bba 100644 --- a/src/graalvm.ts +++ b/src/graalvm.ts @@ -89,7 +89,7 @@ export async function findLatestEABuildDownloadUrl( response = await getContents(ORACLE_GRAALVM_REPO_EA_BUILDS, filePath) } catch (error) { throw new Error( - `Unable to resolve download URL for '${javaEaVersion}'. Please make sure the java-version is set correctly. ${c.ERROR_HINT}` + `Unable to resolve download URL for '${javaEaVersion}' (reason: ${error}). Please make sure the java-version is set correctly. ${c.ERROR_HINT}` ) } if ( diff --git a/src/mandrel.ts b/src/mandrel.ts index ae79413..cb766ff 100644 --- a/src/mandrel.ts +++ b/src/mandrel.ts @@ -1,6 +1,6 @@ import * as c from './constants' import * as httpClient from '@actions/http-client' -import {downloadExtractAndCacheJDK, getLatestRelease} from './utils' +import {downloadExtractAndCacheJDK} from './utils' import {downloadTool} from '@actions/tool-cache' import {basename} from 'path' @@ -11,7 +11,9 @@ const DISCO_API_BASE = 'https://api.foojay.io/disco/v3.0/packages/jdks' interface JdkData { message: string + /* eslint-disable @typescript-eslint/no-explicit-any */ result: any + /* eslint-enable @typescript-eslint/no-explicit-any */ } export async function setUpMandrel( @@ -22,7 +24,9 @@ export async function setUpMandrel( let mandrelHome switch (version) { case '': - // fetch latest if no version is specified + // fetch latest if no version is specified + mandrelHome = await setUpMandrelLatest(javaVersion) + break case 'latest': mandrelHome = await setUpMandrelLatest(javaVersion) break diff --git a/src/msvc.ts b/src/msvc.ts index 5e5658c..3899659 100644 --- a/src/msvc.ts +++ b/src/msvc.ts @@ -1,5 +1,4 @@ import * as core from '@actions/core' -import * as semver from 'semver' import {execSync} from 'child_process' import {existsSync} from 'fs' import {VERSION_DEV} from './constants' diff --git a/tsconfig.base.json b/tsconfig.base.json index 9af953f..cd9f88b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -2,7 +2,7 @@ "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "allowSyntheticDefaultImports": true, - "declaration": true, + "declaration": false, "declarationMap": false, "esModuleInterop": true, "forceConsistentCasingInFileNames": true,