From ed3e1da142f55d152a3a773754dcd33418331839 Mon Sep 17 00:00:00 2001 From: islishude Date: Mon, 18 Sep 2023 21:05:08 +0800 Subject: [PATCH] Fix eslint script and related code --- .eslintrc.json | 6 ++++-- dist/index.js | 26 +++++++++++++------------- package.json | 2 +- src/git-auth-helper.ts | 8 ++++---- src/git-source-provider.ts | 2 +- src/github-api-helper.ts | 8 ++++---- src/input-helper.ts | 4 ++-- src/main.ts | 4 ++-- src/ref-helper.ts | 4 ++-- src/state-helper.ts | 8 ++++---- src/url-helper.ts | 4 ++-- src/workflow-context-helper.ts | 2 +- 12 files changed, 40 insertions(+), 38 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 14c084e..6c374af 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,7 +21,7 @@ "@typescript-eslint/func-call-spacing": ["error", "never"], "@typescript-eslint/no-array-constructor": "error", "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-extraneous-class": "error", "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-for-in-array": "error", @@ -43,7 +43,9 @@ "semi": "off", "@typescript-eslint/semi": ["error", "never"], "@typescript-eslint/type-annotation-spacing": "error", - "@typescript-eslint/unbound-method": "error" + "@typescript-eslint/unbound-method": "error", + "i18n-text/no-en": "off", + "github/no-then": "off" }, "env": { "node": true, diff --git a/dist/index.js b/dist/index.js index 67752ae..b46077e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -305,7 +305,7 @@ class GitAuthHelper { this.sshKeyPath = path.join(runnerTemp, uniqueId); stateHelper.setSshKeyPath(this.sshKeyPath); yield fs.promises.mkdir(runnerTemp, { recursive: true }); - yield fs.promises.writeFile(this.sshKeyPath, this.settings.sshKey.trim() + '\n', { mode: 0o600 }); + yield fs.promises.writeFile(this.sshKeyPath, `${this.settings.sshKey.trim()}\n`, { mode: 0o600 }); // Remove inherited permissions on Windows if (IS_WINDOWS) { const icacls = yield io.which('icacls.exe'); @@ -371,7 +371,7 @@ class GitAuthHelper { let content = (yield fs.promises.readFile(configPath)).toString(); const placeholderIndex = content.indexOf(this.tokenPlaceholderConfigValue); if (placeholderIndex < 0 || - placeholderIndex != content.lastIndexOf(this.tokenPlaceholderConfigValue)) { + placeholderIndex !== content.lastIndexOf(this.tokenPlaceholderConfigValue)) { throw new Error(`Unable to replace auth placeholder in ${configPath}`); } assert.ok(this.tokenConfigValue, 'tokenConfigValue is not defined'); @@ -1326,7 +1326,7 @@ function getSource(settings) { yield authHelper.removeAuth(); core.endGroup(); } - authHelper.removeGlobalConfig(); + yield authHelper.removeGlobalConfig(); } } }); @@ -1514,8 +1514,8 @@ const io = __importStar(__nccwpck_require__(7436)); const path = __importStar(__nccwpck_require__(1017)); const retryHelper = __importStar(__nccwpck_require__(2155)); const toolCache = __importStar(__nccwpck_require__(7784)); -const v4_1 = __importDefault(__nccwpck_require__(824)); const url_helper_1 = __nccwpck_require__(9437); +const v4_1 = __importDefault(__nccwpck_require__(824)); const IS_WINDOWS = process.platform === 'win32'; function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) { return __awaiter(this, void 0, void 0, function* () { @@ -1549,7 +1549,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, // Determine the path of the repository content. The archive contains // a top-level folder and the repository content is inside. const archiveFileNames = yield fs.promises.readdir(extractPath); - assert.ok(archiveFileNames.length == 1, 'Expected exactly one directory inside archive'); + assert.ok(archiveFileNames.length === 1, 'Expected exactly one directory inside archive'); const archiveVersion = archiveFileNames[0]; // The top-level folder name includes the short SHA core.info(`Resolved version ${archiveVersion}`); const tempRepositoryPath = path.join(extractPath, archiveVersion); @@ -1617,8 +1617,8 @@ function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) { ? octokit.rest.repos.downloadZipballArchive : octokit.rest.repos.downloadTarballArchive; const response = yield download({ - owner: owner, - repo: repo, + owner, + repo, ref: commit || ref }); return Buffer.from(response.data); // response.data is ArrayBuffer @@ -1753,11 +1753,11 @@ function getInputs() { result.submodules = false; result.nestedSubmodules = false; const submodulesString = (core.getInput('submodules') || '').toUpperCase(); - if (submodulesString == 'RECURSIVE') { + if (submodulesString === 'RECURSIVE') { result.submodules = true; result.nestedSubmodules = true; } - else if (submodulesString == 'TRUE') { + else if (submodulesString === 'TRUE') { result.submodules = true; } core.debug(`submodules = ${result.submodules}`); @@ -1862,11 +1862,11 @@ function cleanup() { } // Main if (!stateHelper.IsPost) { - run(); + void run(); } // Post else { - cleanup(); + void cleanup(); } @@ -2096,7 +2096,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref } // Expected message? const expectedMessage = `Merge ${expectedHeadSha} into ${expectedBaseSha}`; - if (commitInfo.indexOf(expectedMessage) >= 0) { + if (commitInfo.includes(expectedMessage)) { return; } // Extract details from message @@ -2378,7 +2378,7 @@ function getFetchUrl(settings) { } exports.getFetchUrl = getFetchUrl; function getServerUrl(url) { - let urlValue = url && url.trim().length > 0 + const urlValue = url && url.trim().length > 0 ? url : process.env['GITHUB_SERVER_URL'] || 'https://github.com'; return new url_1.URL(urlValue); diff --git a/package.json b/package.json index 84d6430..d8b6355 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "tsc && ncc build && node lib/misc/generate-docs.js", "format": "prettier --write '**/*.ts'", "format-check": "prettier --check '**/*.ts'", - "lint": "eslint src/**/*.ts", + "lint": "eslint 'src/**/*.ts'", "test": "jest", "licensed-check": "src/misc/licensed-check.sh", "licensed-generate": "src/misc/licensed-generate.sh" diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index 364a04e..40763ec 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -8,9 +8,9 @@ import * as path from 'path' import * as regexpHelper from './regexp-helper' import * as stateHelper from './state-helper' import * as urlHelper from './url-helper' -import {default as uuid} from 'uuid/v4' import {IGitCommandManager} from './git-command-manager' import {IGitSourceSettings} from './git-source-settings' +import {default as uuid} from 'uuid/v4' const IS_WINDOWS = process.platform === 'win32' const SSH_COMMAND_KEY = 'core.sshCommand' @@ -215,7 +215,7 @@ class GitAuthHelper { await fs.promises.mkdir(runnerTemp, {recursive: true}) await fs.promises.writeFile( this.sshKeyPath, - this.settings.sshKey.trim() + '\n', + `${this.settings.sshKey.trim()}\n`, {mode: 0o600} ) @@ -306,7 +306,7 @@ class GitAuthHelper { const placeholderIndex = content.indexOf(this.tokenPlaceholderConfigValue) if ( placeholderIndex < 0 || - placeholderIndex != content.lastIndexOf(this.tokenPlaceholderConfigValue) + placeholderIndex !== content.lastIndexOf(this.tokenPlaceholderConfigValue) ) { throw new Error(`Unable to replace auth placeholder in ${configPath}`) } @@ -352,7 +352,7 @@ class GitAuthHelper { private async removeGitConfig( configKey: string, - submoduleOnly: boolean = false + submoduleOnly = false ): Promise { if (!submoduleOnly) { if ( diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index c1360b8..a59ed96 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -266,7 +266,7 @@ export async function getSource(settings: IGitSourceSettings): Promise { await authHelper.removeAuth() core.endGroup() } - authHelper.removeGlobalConfig() + await authHelper.removeGlobalConfig() } } } diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index b6bfc13..17baa69 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -6,8 +6,8 @@ import * as io from '@actions/io' import * as path from 'path' import * as retryHelper from './retry-helper' import * as toolCache from '@actions/tool-cache' -import {default as uuid} from 'uuid/v4' import {getServerApiUrl} from './url-helper' +import {default as uuid} from 'uuid/v4' const IS_WINDOWS = process.platform === 'win32' @@ -54,7 +54,7 @@ export async function downloadRepository( // a top-level folder and the repository content is inside. const archiveFileNames = await fs.promises.readdir(extractPath) assert.ok( - archiveFileNames.length == 1, + archiveFileNames.length === 1, 'Expected exactly one directory inside archive' ) const archiveVersion = archiveFileNames[0] // The top-level folder name includes the short SHA @@ -135,8 +135,8 @@ async function downloadArchive( ? octokit.rest.repos.downloadZipballArchive : octokit.rest.repos.downloadTarballArchive const response = await download({ - owner: owner, - repo: repo, + owner, + repo, ref: commit || ref }) return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer diff --git a/src/input-helper.ts b/src/input-helper.ts index be9cecd..fe63f26 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -118,10 +118,10 @@ export async function getInputs(): Promise { result.submodules = false result.nestedSubmodules = false const submodulesString = (core.getInput('submodules') || '').toUpperCase() - if (submodulesString == 'RECURSIVE') { + if (submodulesString === 'RECURSIVE') { result.submodules = true result.nestedSubmodules = true - } else if (submodulesString == 'TRUE') { + } else if (submodulesString === 'TRUE') { result.submodules = true } core.debug(`submodules = ${result.submodules}`) diff --git a/src/main.ts b/src/main.ts index 97a27af..9c479d0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,9 +38,9 @@ async function cleanup(): Promise { // Main if (!stateHelper.IsPost) { - run() + void run() } // Post else { - cleanup() + void cleanup() } diff --git a/src/ref-helper.ts b/src/ref-helper.ts index 1c25049..106994e 100644 --- a/src/ref-helper.ts +++ b/src/ref-helper.ts @@ -1,7 +1,7 @@ -import {IGitCommandManager} from './git-command-manager' import * as core from '@actions/core' import * as github from '@actions/github' import {getServerApiUrl, isGhes} from './url-helper' +import {IGitCommandManager} from './git-command-manager' export const tagsRefSpec = '+refs/tags/*:refs/tags/*' @@ -227,7 +227,7 @@ export async function checkCommitInfo( // Expected message? const expectedMessage = `Merge ${expectedHeadSha} into ${expectedBaseSha}` - if (commitInfo.indexOf(expectedMessage) >= 0) { + if (commitInfo.includes(expectedMessage)) { return } diff --git a/src/state-helper.ts b/src/state-helper.ts index aa3eecc..b81397b 100644 --- a/src/state-helper.ts +++ b/src/state-helper.ts @@ -28,28 +28,28 @@ export const SshKnownHostsPath = core.getState('sshKnownHostsPath') /** * Save the repository path so the POST action can retrieve the value. */ -export function setRepositoryPath(repositoryPath: string) { +export function setRepositoryPath(repositoryPath: string): void { core.saveState('repositoryPath', repositoryPath) } /** * Save the SSH key path so the POST action can retrieve the value. */ -export function setSshKeyPath(sshKeyPath: string) { +export function setSshKeyPath(sshKeyPath: string): void { core.saveState('sshKeyPath', sshKeyPath) } /** * Save the SSH known hosts path so the POST action can retrieve the value. */ -export function setSshKnownHostsPath(sshKnownHostsPath: string) { +export function setSshKnownHostsPath(sshKnownHostsPath: string): void { core.saveState('sshKnownHostsPath', sshKnownHostsPath) } /** * Save the set-safe-directory input so the POST action can retrieve the value. */ -export function setSafeDirectory() { +export function setSafeDirectory(): void { core.saveState('setSafeDirectory', 'true') } diff --git a/src/url-helper.ts b/src/url-helper.ts index 6807b7f..7bcb8cf 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' -import {URL} from 'url' import {IGitSourceSettings} from './git-source-settings' +import {URL} from 'url' export function getFetchUrl(settings: IGitSourceSettings): string { assert.ok( @@ -20,7 +20,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string { } export function getServerUrl(url?: string): URL { - let urlValue = + const urlValue = url && url.trim().length > 0 ? url : process.env['GITHUB_SERVER_URL'] || 'https://github.com' diff --git a/src/workflow-context-helper.ts b/src/workflow-context-helper.ts index c7d7918..c55303f 100644 --- a/src/workflow-context-helper.ts +++ b/src/workflow-context-helper.ts @@ -20,7 +20,7 @@ export async function getOrganizationId(): Promise { return } - return id as number + return id } catch (err) { core.debug( `Unable to load organization ID from GITHUB_EVENT_PATH: ${(err as any)