From fa8a671e6fdf770a98254d275a366488dbff78aa Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 14 Mar 2020 07:53:43 +0530 Subject: [PATCH] Improve code quality --- .eslintrc.json | 3 +-- __tests__/install.test.ts | 2 ++ __tests__/matchers.test.ts | 10 ---------- __tests__/utils.test.ts | 12 ++++++------ dist/index.js | 32 +++++++++++++++++--------------- jest.config.js | 2 +- src/config.ts | 1 + src/extensions.ts | 6 ++---- src/install.ts | 2 +- src/tools.ts | 17 +++++++++++------ src/utils.ts | 11 ++--------- 11 files changed, 44 insertions(+), 54 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__/install.test.ts b/__tests__/install.test.ts index 45119282..c6fa5d0b 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -69,6 +69,8 @@ jest.mock('../src/install', () => ({ * @param extension_csv * @param ini_values_csv * @param coverage_driver + * @param tools + * @param pecl */ function setEnv( version: string | number, diff --git a/__tests__/matchers.test.ts b/__tests__/matchers.test.ts index 1d55d6f0..e814873c 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 59dcb80e..c4dfdfc3 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 ba401070..e6fc1d58 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1072,7 +1072,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* () { @@ -1116,6 +1115,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* () { @@ -1135,10 +1135,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'); }); @@ -1148,7 +1146,6 @@ exports.readScript = readScript; * Write final script which runs * * @param filename - * @param version * @param script */ function writeScript(filename, script) { @@ -1586,6 +1583,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* () { @@ -1648,6 +1646,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 @@ -1738,7 +1738,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; } }); } @@ -1746,9 +1746,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) { @@ -1771,6 +1769,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) { @@ -1833,7 +1834,7 @@ exports.getSymfonyUri = getSymfonyUri; /** * 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* () { @@ -1926,7 +1927,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) { @@ -1975,7 +1977,7 @@ function addTools(tools_csv, php_version, os_version) { break; case 'composer': // If RC is released as latest release, switch to getcomposer. - // Prefered source is GitHub as it is faster. + // Preferred source is GitHub as it is faster. // url = github + 'composer/composer/releases/latest/download/composer.phar'; url = 'https://getcomposer.org/composer-stable.phar'; script += yield addArchive(tool, version, url, os_version); @@ -2258,6 +2260,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* () { @@ -2342,7 +2345,7 @@ function build(filename, version, os_version) { /.*-(beta|alpha|devel|snapshot).*/.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); @@ -2721,9 +2724,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'; @@ -2862,7 +2864,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 7654dee9..db42fe66 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -89,12 +89,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'; @@ -235,7 +233,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 c908b8ec..db021ce0 100644 --- a/src/install.ts +++ b/src/install.ts @@ -37,7 +37,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 b6071aee..ae99103f 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( @@ -272,7 +276,7 @@ export async function getSymfonyUri( /** * 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($|:.*)/; @@ -381,7 +385,8 @@ export async function addPackage( /** * Setup tools * - * @param tool_csv + * @param tools_csv + * @param php_version * @param os_version */ export async function addTools( @@ -439,7 +444,7 @@ export async function addTools( break; case 'composer': // If RC is released as latest release, switch to getcomposer. - // Prefered source is GitHub as it is faster. + // Preferred source is GitHub as it is faster. // url = github + 'composer/composer/releases/latest/download/composer.phar'; url = 'https://getcomposer.org/composer-stable.phar'; script += await addArchive(tool, version, url, os_version); diff --git a/src/utils.ts b/src/utils.ts index f263b985..28173434 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(