public inbox for [email protected]
help / color / mirror / Atom feedFrom: Nikhil Mohite <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: Patch for SonarQube fixes.
Date: Mon, 18 Jan 2021 11:15:39 +0530
Message-ID: <CAOBg0AO3tVZMT68DyMLyc6w+za9sHA+NHEs_rosfVGNP=kgxeQ@mail.gmail.com> (raw)
Hi Team,
I have fixed a few sonarQube issues, PFA patch
Details as follows:
1. Preferences:
- Refactor this function to reduce its Cognitive Complexity from 18 to
the 15 allowed.
- Merge this if statement with the enclosing one.
- Define a constant instead of duplicating this literal 'tab settings' 5
times.
2. Connection:
- Remove this unneeded "pass".
3. Sqleditor:
- Remove this useless assignment to variable "msgDiv".
4. Debugger:
- Review this useless assignment: "index" already holds the assigned
value along all execution paths.
- 'label' is already declared in the upper scope.
- 'label' is already declared in the upper scope.
- 'browser_preferences' is already declared in the upper scope.
5. FileManager:
- 'path' is already declared in the upper scope.
--
*Thanks & Regards,*
*Nikhil Mohite*
*Software Engineer.*
*EDB Postgres* <https://www.enterprisedb.com/;
*Mob.No: +91-7798364578.*
Attachments:
[application/octet-stream] SonarQubeCodeSmellFixes.patch (14.2K, 3-SonarQubeCodeSmellFixes.patch)
download | inline diff:
diff --git a/web/pgadmin/browser/register_browser_preferences.py b/web/pgadmin/browser/register_browser_preferences.py
index 3b335be1..7f909c41 100644
--- a/web/pgadmin/browser/register_browser_preferences.py
+++ b/web/pgadmin/browser/register_browser_preferences.py
@@ -444,7 +444,7 @@ def register_browser_preferences(self):
)
self.dynamic_tab_title = self.preference.register(
- 'tab settings', 'dynamic_tabs',
+ 'tab_settings', 'dynamic_tabs',
gettext("Dynamic tab size"), 'boolean', False,
category_label=PREF_LABEL_TABS_SETTINGS,
help_str=gettext(
@@ -453,7 +453,7 @@ def register_browser_preferences(self):
)
self.qt_tab_title = self.preference.register(
- 'tab settings', 'qt_tab_title_placeholder',
+ 'tab_settings', 'qt_tab_title_placeholder',
gettext("Query tool tab title"),
'text', '%DATABASE%/%USERNAME%@%SERVER%',
category_label=PREF_LABEL_DISPLAY,
@@ -466,7 +466,7 @@ def register_browser_preferences(self):
)
self.ve_edt_tab_title = self.preference.register(
- 'tab settings', 'vw_edt_tab_title_placeholder',
+ 'tab_settings', 'vw_edt_tab_title_placeholder',
gettext("View/Edit data tab title"),
'text', '%SCHEMA%.%TABLE%/%DATABASE%/%USERNAME%@%SERVER%',
category_label=PREF_LABEL_DISPLAY,
@@ -479,7 +479,7 @@ def register_browser_preferences(self):
)
self.debugger_tab_title = self.preference.register(
- 'tab settings', 'debugger_tab_title_placeholder',
+ 'tab_settings', 'debugger_tab_title_placeholder',
gettext("Debugger tab title"),
'text', '%FUNCTION%(%ARGS%)',
category_label=PREF_LABEL_DISPLAY,
@@ -492,7 +492,7 @@ def register_browser_preferences(self):
)
self.open_in_new_tab = self.preference.register(
- 'tab settings', 'new_browser_tab_open',
+ 'tab_settings', 'new_browser_tab_open',
gettext("Open in new browser tab"), 'select2', None,
category_label=PREF_LABEL_OPTIONS,
options=[{'label': gettext('Query Tool'), 'value': 'qt'},
diff --git a/web/pgadmin/misc/file_manager/static/js/utility.js b/web/pgadmin/misc/file_manager/static/js/utility.js
index 7e335ee8..67c4be04 100644
--- a/web/pgadmin/misc/file_manager/static/js/utility.js
+++ b/web/pgadmin/misc/file_manager/static/js/utility.js
@@ -949,18 +949,18 @@ define([
};
renameItem(file_data);
- let path = $('.currentpath').val();
+ let current_path = $('.currentpath').val();
if(isFolder == true) {
// if its folder rename, remove the temporary added class
$(this).closest('.tbl_folder').removeClass('tbl_folder_rename');
- if(path.includes('\\')) {
- path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
+ if(current_path.includes('\\')) {
+ current_path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
}
else {
- path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
+ current_path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
}
}
- getFolderInfo(path);
+ getFolderInfo(current_path);
}
}
} else {
@@ -1005,18 +1005,18 @@ define([
};
renameItem(file_data);
- let path = $('.currentpath').val();
+ let current_path = $('.currentpath').val();
if(isFolder == true) {
// if its folder rename, remove the temporary added class
$(this).closest('.tbl_folder').removeClass('tbl_folder_rename');
- if(path.includes('\\')) {
- path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
+ if(current_path.includes('\\')) {
+ current_path = $('.currentpath').val().split('\\').slice(0, -2).join('\\')+'\\';
}
else {
- path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
+ current_path = $('.currentpath').val().split('/').slice(0, -2).join('/')+'/';
}
}
- getFolderInfo(path);
+ getFolderInfo(current_path);
}
}
} else {
diff --git a/web/pgadmin/preferences/__init__.py b/web/pgadmin/preferences/__init__.py
index 7ef18aeb..f11f4317 100644
--- a/web/pgadmin/preferences/__init__.py
+++ b/web/pgadmin/preferences/__init__.py
@@ -204,9 +204,9 @@ def save(pid):
if data['name'] in ['vw_edt_tab_title_placeholder',
'qt_tab_title_placeholder',
- 'debugger_tab_title_placeholder']:
- if data['value'].isspace():
- data['value'] = ''
+ 'debugger_tab_title_placeholder'] \
+ and data['value'].isspace():
+ data['value'] = ''
res, msg = Preferences.save(
data['mid'], data['category_id'], data['id'], data['value'])
diff --git a/web/pgadmin/tools/debugger/static/js/debugger.js b/web/pgadmin/tools/debugger/static/js/debugger.js
index b803f692..a609cf7e 100644
--- a/web/pgadmin/tools/debugger/static/js/debugger.js
+++ b/web/pgadmin/tools/debugger/static/js/debugger.js
@@ -453,9 +453,9 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
- let browser_preferences = pgBrowser.get_preferences_for_module('browser');
- var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
- debuggerUtils.setDebuggerTitle(panel, browser_preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
+ let preferences = pgBrowser.get_preferences_for_module('browser');
+ var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
+ debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
@@ -597,9 +597,9 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
- let browser_preferences = pgBrowser.get_preferences_for_module('browser');
- var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
- debuggerUtils.setDebuggerTitle(panel, browser_preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
+ let preferences = pgBrowser.get_preferences_for_module('browser');
+ var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
+ debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
diff --git a/web/pgadmin/tools/debugger/static/js/debugger_ui.js b/web/pgadmin/tools/debugger/static/js/debugger_ui.js
index 0dd59eff..b1ffeac9 100644
--- a/web/pgadmin/tools/debugger/static/js/debugger_ui.js
+++ b/web/pgadmin/tools/debugger/static/js/debugger_ui.js
@@ -801,8 +801,8 @@ define([
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
- var label = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
- debuggerUtils.setDebuggerTitle(panel, self.preferences, label, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
+ var name = treeInfo.function ? treeInfo.function.label : treeInfo.trigger_function ? treeInfo.trigger_function.label : treeInfo.trigger ? treeInfo.trigger.label : treeInfo.procedure.label;
+ debuggerUtils.setDebuggerTitle(panel, self.preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
diff --git a/web/pgadmin/tools/debugger/static/js/debugger_utils.js b/web/pgadmin/tools/debugger/static/js/debugger_utils.js
index 6bc984ff..49675efc 100644
--- a/web/pgadmin/tools/debugger/static/js/debugger_utils.js
+++ b/web/pgadmin/tools/debugger/static/js/debugger_utils.js
@@ -76,7 +76,7 @@ function setDebuggerTitle(panel, preferences, function_name, schema_name, databa
function get_function_name(function_name) {
var function_data = function_name.split('(');
function_data.splice(-1, 1);
- var index = 0;
+ var index = null;
var func_name = '';
for(index=0; index < function_data.length; index++) {
func_name = func_name.concat(function_data[index]);
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 48364f6c..05deebc4 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -2175,7 +2175,6 @@ define('tools.querytool', [
} else{
loadingDiv = $('#fetching_data');
loadingDiv.removeClass('d-none');
- msgDiv = loadingDiv.find('.sql-editor-busy-text');
}
self.set_selected_option(connection_details);
$.ajax({
diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py
index 00c28417..cd6a07b3 100644
--- a/web/pgadmin/utils/driver/psycopg2/connection.py
+++ b/web/pgadmin/utils/driver/psycopg2/connection.py
@@ -757,7 +757,6 @@ WHERE db.datname = current_database()""")
if cur and cur.query is not None else None
except Exception:
current_app.logger.warning('Error encoding query')
- pass
dsn = self.conn.get_dsn_parameters()
current_app.logger.log(
diff --git a/web/pgadmin/utils/preferences.py b/web/pgadmin/utils/preferences.py
index 27915673..289bf268 100644
--- a/web/pgadmin/utils/preferences.py
+++ b/web/pgadmin/utils/preferences.py
@@ -111,22 +111,10 @@ class _Preference(object):
# The data stored in the configuration will be in string format, we
# need to convert them in proper format.
- if self._type in ('boolean', 'switch', 'node'):
- return res.value == 'True'
- if self._type == 'options':
- for opt in self.options:
- if 'value' in opt and opt['value'] == res.value:
- return res.value
- if self.select2 and self.select2['tags']:
- return res.value
- return self.default
- if self._type == 'select2':
- if res.value:
- res.value = res.value.replace('[', '')
- res.value = res.value.replace(']', '')
- res.value = res.value.replace('\'', '')
- return [val.strip() for val in res.value.split(',')]
- return None
+ is_format_data, data = self._get_format_data(res)
+ if is_format_data:
+ return data
+
if self._type == 'text' and res.value == '' and not self.allow_blanks:
return self.default
@@ -144,6 +132,31 @@ class _Preference(object):
return self.default
return res.value
+ def _get_format_data(self, res):
+ """
+ Configuration data get stored in string format, convert it in to
+ required format.
+ :param res: type value.
+ """
+ if self._type in ('boolean', 'switch', 'node'):
+ return True, res.value == 'True'
+ if self._type == 'options':
+ for opt in self.options:
+ if 'value' in opt and opt['value'] == res.value:
+ return True, res.value
+ if self.select2 and self.select2['tags']:
+ return True, res.value
+ return True, self.default
+ if self._type == 'select2':
+ if res.value:
+ res.value = res.value.replace('[', '')
+ res.value = res.value.replace(']', '')
+ res.value = res.value.replace('\'', '')
+ return True, [val.strip() for val in res.value.split(',')]
+ return True, None
+
+ return False, None
+
def set(self, value):
"""
set
@@ -477,12 +490,6 @@ class Preferences(object):
boolean, integer, numeric, date, datetime,
options, multiline, switch, node
:param default: Default value for the preference/option
- :param min_val: Minimum value for integer, and numeric type
- :param max_val: Maximum value for integer, and numeric type
- :param options: Allowed list of options for 'option' type
- :param help_str: Help string show for that preference/option.
- :param module_label: Label for the module
- :param category_label: Label for the category
"""
min_val = kwargs.get('min_val', None)
max_val = kwargs.get('max_val', None)
view thread (10+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Patch for SonarQube fixes.
In-Reply-To: <CAOBg0AO3tVZMT68DyMLyc6w+za9sHA+NHEs_rosfVGNP=kgxeQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox