From d7f2c75afc6ca81f51fc1512dbaba6cf6bbf8e33 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 12 Mar 2020 07:57:40 +0530 Subject: [PATCH] Improve code quality --- .eslintrc.json | 3 +-- __tests__/matchers.test.ts | 10 ---------- __tests__/utils.test.ts | 12 ++++++------ dist/index.js | 30 ++++++++++++++++-------------- jest.config.js | 2 +- src/config.ts | 1 + src/extensions.ts | 6 ++---- src/install.ts | 2 +- src/tools.ts | 15 ++++++++++----- src/utils.ts | 11 ++--------- 10 files changed, 40 insertions(+), 52 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9de7154d..6c5755ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,7 +17,6 @@ "camelcase": "off", "require-atomic-updates": "off", "@typescript-eslint/ban-ts-ignore": "off", - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/no-unused-vars": "off" + "@typescript-eslint/camelcase": "off" } } \ No newline at end of file diff --git a/__tests__/matchers.test.ts b/__tests__/matchers.test.ts index 25534c36..780ac2bb 100644 --- a/__tests__/matchers.test.ts +++ b/__tests__/matchers.test.ts @@ -1,16 +1,6 @@ import * as io from '@actions/io'; -import * as path from 'path'; -import * as fs from 'fs'; import * as matchers from '../src/matchers'; -async function cleanup(path: string): Promise { - fs.unlink(path, error => { - if (error) { - console.log(error); - } - }); -} - jest.mock('@actions/io'); describe('Matchers', () => { diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 874d5813..92e29b85 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -55,12 +55,12 @@ describe('Utils tests', () => { path.join(__dirname, '../src/scripts/win32.ps1'), 'utf8' ); - expect(await utils.readScript('darwin.sh', '7.4', 'darwin')).toBe(darwin); - expect(await utils.readScript('darwin.sh', '7.3', 'darwin')).toBe(darwin); - expect(await utils.readScript('linux.sh', '7.4', 'linux')).toBe(linux); - expect(await utils.readScript('linux.sh', '7.3', 'linux')).toBe(linux); - expect(await utils.readScript('win32.ps1', '7.4', 'win32')).toBe(win32); - expect(await utils.readScript('win32.ps1', '7.3', 'win32')).toBe(win32); + expect(await utils.readScript('darwin.sh')).toBe(darwin); + expect(await utils.readScript('darwin.sh')).toBe(darwin); + expect(await utils.readScript('linux.sh')).toBe(linux); + expect(await utils.readScript('linux.sh')).toBe(linux); + expect(await utils.readScript('win32.ps1')).toBe(win32); + expect(await utils.readScript('win32.ps1')).toBe(win32); }); it('checking writeScripts', async () => { diff --git a/dist/index.js b/dist/index.js index 1555f129..f97762af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1073,7 +1073,6 @@ exports.color = color; * @param message * @param os_version * @param log_type - * @param prefix */ function log(message, os_version, log_type) { return __awaiter(this, void 0, void 0, function* () { @@ -1117,6 +1116,7 @@ exports.stepLog = stepLog; * @param mark * @param subject * @param message + * @param os_version */ function addLog(mark, subject, message, os_version) { return __awaiter(this, void 0, void 0, function* () { @@ -1136,10 +1136,8 @@ exports.addLog = addLog; * Read the scripts * * @param filename - * @param version - * @param os_version */ -function readScript(filename, version, os_version) { +function readScript(filename) { return __awaiter(this, void 0, void 0, function* () { return fs.readFileSync(path.join(__dirname, '../src/scripts/' + filename), 'utf8'); }); @@ -1149,7 +1147,6 @@ exports.readScript = readScript; * Write final script which runs * * @param filename - * @param version * @param script */ function writeScript(filename, script) { @@ -1614,6 +1611,7 @@ const utils = __importStar(__webpack_require__(163)); * Function to get command to setup tools * * @param os_version + * @param suffix */ function getCommand(os_version, suffix) { return __awaiter(this, void 0, void 0, function* () { @@ -1676,6 +1674,8 @@ exports.parseTool = parseTool; /** * Function to get the url of tool with the given version * + * @param tool + * @param extension * @param version * @param prefix * @param version_prefix @@ -1766,7 +1766,7 @@ function getCodeceptionUri(version, php_version) { case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version): return codecept; default: - return yield codecept; + return codecept; } }); } @@ -1774,9 +1774,7 @@ exports.getCodeceptionUri = getCodeceptionUri; /** * Helper function to get script to setup phive * - * @param tool * @param version - * @param url * @param os_version */ function addPhive(version, os_version) { @@ -1799,6 +1797,9 @@ exports.addPhive = addPhive; /** * Function to get the phar url in domain/tool-version.phar format * + * @param domain + * @param tool + * @param prefix * @param version */ function getPharUrl(domain, tool, prefix, version) { @@ -1877,7 +1878,7 @@ exports.getWpCliUrl = getWpCliUrl; /** * Function to add/move composer in the tools list * - * @param tools + * @param tools_list */ function addComposer(tools_list) { return __awaiter(this, void 0, void 0, function* () { @@ -1970,7 +1971,8 @@ exports.addPackage = addPackage; /** * Setup tools * - * @param tool_csv + * @param tools_csv + * @param php_version * @param os_version */ function addTools(tools_csv, php_version, os_version) { @@ -2316,6 +2318,7 @@ exports.addINIValuesWindows = addINIValuesWindows; * * @param ini_values_csv * @param os_version + * @param no_step */ function addINIValues(ini_values_csv, os_version, no_step = false) { return __awaiter(this, void 0, void 0, function* () { @@ -2399,7 +2402,7 @@ function build(filename, version, os_version) { /.*-(\d+\.\d+\.\d+).*/.test(extension_csv)) { tools_csv = 'pecl, ' + tools_csv; } - let script = yield utils.readScript(filename, version, os_version); + let script = yield utils.readScript(filename); script += yield tools.addTools(tools_csv, version, os_version); if (extension_csv) { script += yield extensions.addExtension(extension_csv, version, os_version); @@ -2802,9 +2805,8 @@ exports.addExtensionDarwin = addExtensionDarwin; * * @param extension_csv * @param version - * @param pipe */ -function addExtensionWindows(extension_csv, version, pipe) { +function addExtensionWindows(extension_csv, version) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; @@ -2987,7 +2989,7 @@ function addExtension(extension_csv, version, os_version, no_step = false) { } switch (os_version) { case 'win32': - return script + (yield addExtensionWindows(extension_csv, version, pipe)); + return script + (yield addExtensionWindows(extension_csv, version)); case 'darwin': return script + (yield addExtensionDarwin(extension_csv, version, pipe)); case 'linux': diff --git a/jest.config.js b/jest.config.js index 4e16f4f4..f670531b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,4 +9,4 @@ module.exports = { }, verbose: true, collectCoverage: true -}; \ No newline at end of file +}; diff --git a/src/config.ts b/src/config.ts index 66c209ba..7fa26376 100644 --- a/src/config.ts +++ b/src/config.ts @@ -44,6 +44,7 @@ export async function addINIValuesWindows( * * @param ini_values_csv * @param os_version + * @param no_step */ export async function addINIValues( ini_values_csv: string, diff --git a/src/extensions.ts b/src/extensions.ts index c6d4ab72..943e5ba1 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -115,12 +115,10 @@ export async function addExtensionDarwin( * * @param extension_csv * @param version - * @param pipe */ export async function addExtensionWindows( extension_csv: string, - version: string, - pipe: string + version: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; @@ -313,7 +311,7 @@ export async function addExtension( switch (os_version) { case 'win32': - return script + (await addExtensionWindows(extension_csv, version, pipe)); + return script + (await addExtensionWindows(extension_csv, version)); case 'darwin': return script + (await addExtensionDarwin(extension_csv, version, pipe)); case 'linux': diff --git a/src/install.ts b/src/install.ts index 9f6a214a..1500859d 100644 --- a/src/install.ts +++ b/src/install.ts @@ -35,7 +35,7 @@ export async function build( tools_csv = 'pecl, ' + tools_csv; } - let script: string = await utils.readScript(filename, version, os_version); + let script: string = await utils.readScript(filename); script += await tools.addTools(tools_csv, version, os_version); if (extension_csv) { diff --git a/src/tools.ts b/src/tools.ts index 8445e881..9765065c 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -4,6 +4,7 @@ import * as utils from './utils'; * Function to get command to setup tools * * @param os_version + * @param suffix */ export async function getCommand( os_version: string, @@ -69,6 +70,8 @@ export async function parseTool( /** * Function to get the url of tool with the given version * + * @param tool + * @param extension * @param version * @param prefix * @param version_prefix @@ -167,16 +170,14 @@ export async function getCodeceptionUri( case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version): return codecept; default: - return await codecept; + return codecept; } } /** * Helper function to get script to setup phive * - * @param tool * @param version - * @param url * @param os_version */ export async function addPhive( @@ -204,6 +205,9 @@ export async function addPhive( /** * Function to get the phar url in domain/tool-version.phar format * + * @param domain + * @param tool + * @param prefix * @param version */ export async function getPharUrl( @@ -293,7 +297,7 @@ export async function getWpCliUrl(version: string): Promise { /** * Function to add/move composer in the tools list * - * @param tools + * @param tools_list */ export async function addComposer(tools_list: string[]): Promise { const regex = /^composer($|:.*)/; @@ -402,7 +406,8 @@ export async function addPackage( /** * Setup tools * - * @param tool_csv + * @param tools_csv + * @param php_version * @param os_version */ export async function addTools( diff --git a/src/utils.ts b/src/utils.ts index e5ba5d50..7fcf90a6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -65,7 +65,6 @@ export async function color(type: string): Promise { * @param message * @param os_version * @param log_type - * @param prefix */ export async function log( message: string, @@ -121,6 +120,7 @@ export async function stepLog( * @param mark * @param subject * @param message + * @param os_version */ export async function addLog( mark: string, @@ -147,14 +147,8 @@ export async function addLog( * Read the scripts * * @param filename - * @param version - * @param os_version */ -export async function readScript( - filename: string, - version: string, - os_version: string -): Promise { +export async function readScript(filename: string): Promise { return fs.readFileSync( path.join(__dirname, '../src/scripts/' + filename), 'utf8' @@ -165,7 +159,6 @@ export async function readScript( * Write final script which runs * * @param filename - * @param version * @param script */ export async function writeScript(