Address eslint errors and warnings.

This commit is contained in:
Fabio Niephaus 2025-01-21 13:03:20 +01:00 committed by Fabio Niephaus
parent bc541ab008
commit af56e29ad9
15 changed files with 48 additions and 42 deletions

View File

@ -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)

View File

@ -35,7 +35,6 @@ describe('cleanup', () => {
ReturnType<typeof cache.saveCache>,
Parameters<typeof cache.saveCache>
>
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) => {

View File

@ -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
}

View File

@ -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}`)

View File

@ -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}`)
}

View File

@ -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'],

View File

@ -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)
}
})

View File

@ -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
}

View File

@ -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',

View File

@ -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",

View File

@ -46,7 +46,6 @@ async function saveCache(): Promise<void> {
* @returns Promise that will ignore error reported by the given promise
*/
async function ignoreErrors(promise: Promise<void>): Promise<unknown> {
/* eslint-disable github/no-then */
return new Promise(resolve => {
promise
.catch(error => {

View File

@ -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 (

View File

@ -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

View File

@ -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'

View File

@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declaration": false,
"declarationMap": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,