From 52765755371a08fc94f1655da5ea22046a3e8440 Mon Sep 17 00:00:00 2001 From: Ugo Bechameil Date: Fri, 12 Jul 2024 15:21:39 +0200 Subject: [PATCH] HCK-7073 - Fix sonar reports (#32) * Fix sonar reliability reports * Fix reliability reports * Update indexHelper.js --------- Co-authored-by: chulanovskyi-bs <56116665+chulanovskyi-bs@users.noreply.github.com> --- forward_engineering/helpers/keyHelper.js | 17 +++-------------- reverse_engineering/helpers/connectionHelper.js | 6 +++--- reverse_engineering/helpers/indexHelper.js | 6 +++--- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/forward_engineering/helpers/keyHelper.js b/forward_engineering/helpers/keyHelper.js index b35277f..30f6992 100644 --- a/forward_engineering/helpers/keyHelper.js +++ b/forward_engineering/helpers/keyHelper.js @@ -98,9 +98,7 @@ module.exports = (_, clean) => { } const primaryKeyConstraints = mapProperties(jsonSchema, ([name, schema]) => { - if (!isPrimaryKey(schema)) { - return; - } else if (_.isEmpty(schema.primaryKeyConstraintName)) { + if (!isPrimaryKey(schema) || _.isEmpty(schema.primaryKeyConstraintName)) { return; } @@ -109,25 +107,16 @@ module.exports = (_, clean) => { 'PRIMARY KEY', name, schema.isActivated, - jsonSchema, ); }).filter(Boolean); const uniqueKeyConstraints = _.flatten( mapProperties(jsonSchema, ([name, schema]) => { - if (!isUniqueKey(schema)) { - return; - } else if (_.isEmpty(schema.uniqueKeyConstraintName)) { + if (!isUniqueKey(schema) || _.isEmpty(schema.uniqueKeyConstraintName)) { return; } - return hydrateKeyConstraintOptions( - schema.uniqueKeyConstraintName, - 'UNIQUE', - name, - schema.isActivated, - jsonSchema, - ); + return hydrateKeyConstraintOptions(schema.uniqueKeyConstraintName, 'UNIQUE', name, schema.isActivated); }), ).filter(Boolean); diff --git a/reverse_engineering/helpers/connectionHelper.js b/reverse_engineering/helpers/connectionHelper.js index 9aa5512..551d572 100644 --- a/reverse_engineering/helpers/connectionHelper.js +++ b/reverse_engineering/helpers/connectionHelper.js @@ -136,14 +136,14 @@ const createConnection = async (connectionInfo, sshService, logger) => { return { execute: query => { - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { const queryArgument = createArgument('query', query); const queryResult = spawn(`"${javaPath}"`, [...teradataClientCommandArguments, queryArgument], { shell: true, }); queryResult.on('error', error => { - reject(error); + reject(new Error(error)); }); const errorData = []; @@ -172,7 +172,7 @@ const createConnection = async (connectionInfo, sshService, logger) => { const parsedResult = JSON.parse(rowJson); if (parsedResult.error) { - reject(parsedResult.error); + reject(new Error(parsedResult.error)); return; } diff --git a/reverse_engineering/helpers/indexHelper.js b/reverse_engineering/helpers/indexHelper.js index 1c2b99d..a5b67a8 100644 --- a/reverse_engineering/helpers/indexHelper.js +++ b/reverse_engineering/helpers/indexHelper.js @@ -5,7 +5,7 @@ const cleanKeyName = (name = '') => { }; const parseIndexKeys = statement => { const mathResult = statement.match(regexConfig.indexKeyName); - if (!mathResult || !mathResult.length) { + if (!mathResult?.length) { return []; } @@ -14,7 +14,7 @@ const parseIndexKeys = statement => { const parseHashIndexStatement = statement => { const matchResult = regexConfig.createHashIndex.exec(statement); - if (!matchResult || !matchResult.groups) { + if (!matchResult?.groups) { return {}; } @@ -32,7 +32,7 @@ const parseHashIndexStatement = statement => { const parseJoinIndexStatement = statement => { const matchResult = regexConfig.createJoinIndex.exec(statement); - if (!matchResult || !matchResult.groups) { + if (!matchResult?.groups) { return {}; }