Skip to content

Commit 9ae481c

Browse files
Resolve errors highlighted by ESLint
1 parent 53dce19 commit 9ae481c

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

Diff for: __tests__/main.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const dataDir = path.join(__dirname, "testdata");
1010
const IS_WINDOWS = process.platform === "win32";
1111
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || "";
1212

13-
process.env["RUNNER_TEMP"] = tempDir;
14-
process.env["RUNNER_TOOL_CACHE"] = toolDir;
13+
process.env.RUNNER_TEMP = tempDir;
14+
process.env.RUNNER_TOOL_CACHE = toolDir;
1515
import * as installer from "../src/installer";
1616

1717
describe("filename tests", () => {
@@ -26,12 +26,12 @@ describe("filename tests", () => {
2626
["protoc-3.20.2-win64.zip", "win32", "x64"],
2727
["protoc-3.20.2-win32.zip", "win32", "x32"]
2828
];
29-
for (const [expected, plat, arch] of tests) {
30-
it(`downloads ${expected} correctly`, () => {
29+
it(`Downloads all expected versions correctly`, () => {
30+
for (const [expected, plat, arch] of tests) {
3131
const actual = installer.getFileName("3.20.2", plat, arch);
3232
expect(expected).toBe(actual);
33-
});
34-
}
33+
}
34+
});
3535
});
3636

3737
describe("installer tests", () => {

Diff for: jest.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*global module*/
2+
13
module.exports = {
24
clearMocks: true,
35
moduleFileExtensions: ['js', 'ts'],

Diff for: src/installer.ts

+27-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Load tempDirectory before it gets wiped by tool-cache
2-
let tempDirectory = process.env["RUNNER_TEMP"] || "";
2+
let tempDirectory = process.env.RUNNER_TEMP || "";
33

44
import * as os from "os";
55
import * as path from "path";
@@ -11,7 +11,7 @@ if (!tempDirectory) {
1111
let baseLocation;
1212
if (process.platform === "win32") {
1313
// On windows use the USERPROFILE env variable
14-
baseLocation = process.env["USERPROFILE"] || "C:\\";
14+
baseLocation = process.env.USERPROFILE || "C:\\";
1515
} else {
1616
if (process.platform === "darwin") {
1717
baseLocation = "/Users";
@@ -27,8 +27,8 @@ import * as tc from "@actions/tool-cache";
2727
import * as exc from "@actions/exec";
2828
import * as io from "@actions/io";
2929

30-
let osPlat: string = os.platform();
31-
let osArch: string = os.arch();
30+
const osPlat: string = os.platform();
31+
const osArch: string = os.arch();
3232

3333
interface IProtocRelease {
3434
tag_name: string;
@@ -73,7 +73,7 @@ export async function getProtoc(
7373
// Go is installed, add $GOPATH/bin to the $PATH because setup-go
7474
// doesn't do it for us.
7575
let stdOut = "";
76-
let options = {
76+
const options = {
7777
listeners: {
7878
stdout: (data: Buffer) => {
7979
stdOut += data.toString();
@@ -91,8 +91,8 @@ export async function getProtoc(
9191

9292
async function downloadRelease(version: string): Promise<string> {
9393
// Download
94-
let fileName: string = getFileName(version, osPlat, osArch);
95-
let downloadUrl: string = util.format(
94+
const fileName: string = getFileName(version, osPlat, osArch);
95+
const downloadUrl: string = util.format(
9696
"https://github.com/protocolbuffers/protobuf/releases/download/%s/%s",
9797
version,
9898
fileName
@@ -105,26 +105,28 @@ async function downloadRelease(version: string): Promise<string> {
105105
} catch (err) {
106106
if (err instanceof tc.HTTPError) {
107107
core.debug(err.message);
108-
throw `Failed to download version ${version}: ${err.name}, ${err.message} - ${err.httpStatusCode}`;
108+
throw new Error(
109+
`Failed to download version ${version}: ${err.name}, ${err.message} - ${err.httpStatusCode}`
110+
);
109111
}
110-
throw `Failed to download version ${version}: ${err}`;
112+
throw new Error(`Failed to download version ${version}: ${err}`);
111113
}
112114

113115
// Extract
114-
let extPath: string = await tc.extractZip(downloadPath);
116+
const extPath: string = await tc.extractZip(downloadPath);
115117

116118
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
117-
return await tc.cacheDir(extPath, "protoc", version);
119+
return tc.cacheDir(extPath, "protoc", version);
118120
}
119121

120122
/**
121123
*
122-
* @param osArch - A string identifying operating system CPU architecture for which the Node.js binary was compiled.
124+
* @param osArc - A string identifying operating system CPU architecture for which the Node.js binary was compiled.
123125
* See https://nodejs.org/api/os.html#osarch for possible values.
124126
* @returns Suffix for the protoc filename.
125127
*/
126-
function fileNameSuffix(osArch: string): string {
127-
switch (osArch) {
128+
function fileNameSuffix(osArc: string): string {
129+
switch (osArc) {
128130
case "x64": {
129131
return "x86_64";
130132
}
@@ -147,32 +149,32 @@ function fileNameSuffix(osArch: string): string {
147149
* Returns the filename of the protobuf compiler.
148150
*
149151
* @param version - The version to download
150-
* @param osPlat - The operating system platform for which the Node.js binary was compiled.
152+
* @param osPlatf - The operating system platform for which the Node.js binary was compiled.
151153
* See https://nodejs.org/api/os.html#osplatform for more.
152-
* @param osArch - The operating system CPU architecture for which the Node.js binary was compiled.
154+
* @param osArc - The operating system CPU architecture for which the Node.js binary was compiled.
153155
* See https://nodejs.org/api/os.html#osarch for more.
154156
* @returns The filename of the protocol buffer for the given release, platform and architecture.
155157
*
156158
*/
157159
export function getFileName(
158160
version: string,
159-
osPlat: string,
160-
osArch: string
161+
osPlatf: string,
162+
osArc: string
161163
): string {
162164
// to compose the file name, strip the leading `v` char
163165
if (version.startsWith("v")) {
164166
version = version.slice(1, version.length);
165167
}
166168

167169
// The name of the Windows package has a different naming pattern
168-
if (osPlat == "win32") {
169-
const arch: string = osArch == "x64" ? "64" : "32";
170+
if (osPlatf == "win32") {
171+
const arch: string = osArc == "x64" ? "64" : "32";
170172
return util.format("protoc-%s-win%s.zip", version, arch);
171173
}
172174

173-
const suffix = fileNameSuffix(osArch);
175+
const suffix = fileNameSuffix(osArc);
174176

175-
if (osPlat == "darwin") {
177+
if (osPlatf == "darwin") {
176178
return util.format("protoc-%s-osx-%s.zip", version, suffix);
177179
}
178180

@@ -195,11 +197,11 @@ async function fetchVersions(
195197

196198
let tags: IProtocRelease[] = [];
197199
for (let pageNum = 1, morePages = true; morePages; pageNum++) {
198-
let p = await rest.get<IProtocRelease[]>(
200+
const p = await rest.get<IProtocRelease[]>(
199201
"https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
200202
pageNum
201203
);
202-
let nextPage: IProtocRelease[] = p.result || [];
204+
const nextPage: IProtocRelease[] = p.result || [];
203205
if (nextPage.length > 0) {
204206
tags = tags.concat(nextPage);
205207
} else {
@@ -208,7 +210,7 @@ async function fetchVersions(
208210
}
209211

210212
return tags
211-
.filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g))
213+
.filter(tag => tag.tag_name.match(/v\d+\.[\w.]+/g))
212214
.filter(tag => includePrerelease(tag.prerelease, includePreReleases))
213215
.map(tag => tag.tag_name.replace("v", ""));
214216
}

Diff for: src/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as installer from "./installer";
33

44
async function run() {
55
try {
6-
let version = core.getInput("version");
7-
let includePreReleases = convertToBoolean(
6+
const version = core.getInput("version");
7+
const includePreReleases = convertToBoolean(
88
core.getInput("include-pre-releases")
99
);
10-
let repoToken = core.getInput("repo-token");
10+
const repoToken = core.getInput("repo-token");
1111
await installer.getProtoc(version, includePreReleases, repoToken);
1212
} catch (error) {
1313
core.setFailed(`${error}`);

0 commit comments

Comments
 (0)