Skip to content

Commit

Permalink
Address eslint errors and warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jan 21, 2025
1 parent 61fd4fc commit 6cf8f98
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 42 deletions.
4 changes: 2 additions & 2 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions __tests__/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('cleanup', () => {
ReturnType<typeof cache.saveCache>,
Parameters<typeof cache.saveCache>
>
let spyJobStatusSuccess: jest.SpyInstance

beforeEach(() => {
spyWarning = jest.spyOn(core, 'warning')
Expand All @@ -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.'
Expand All @@ -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) => {
Expand Down
22 changes: 11 additions & 11 deletions __tests__/graalvm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -78,25 +78,25 @@ 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')
try {
await findLatestEABuildDownloadUrl('8-ea')
} catch (err) {
if (!(err instanceof Error)) {
fail(`Unexpected non-Error: ${err}`)
throw new Error(`Unexpected non-Error: ${err}`)
}
error = err
}
Expand Down
12 changes: 7 additions & 5 deletions __tests__/liberica.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`)
Expand Down
12 changes: 6 additions & 6 deletions __tests__/mandrel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]) {
Expand All @@ -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
}
Expand All @@ -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']
]) {
Expand All @@ -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
}
Expand All @@ -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']
]) {
Expand All @@ -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}`)
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/msvc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
Expand Down
7 changes: 5 additions & 2 deletions __tests__/sbom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
7 changes: 3 additions & 4 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/graalvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 6 additions & 2 deletions src/mandrel.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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(
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/msvc.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declaration": false,
"declarationMap": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit 6cf8f98

Please sign in to comment.