Fix following issues reported by SonarQube:

1) Properties of variables with "null" or "undefined" values should not be accessed
2) Variables should not be self-assigned
3) "in" should not be used with primitive types
This commit is contained in:
Khushboo Vashi 2020-06-15 16:16:57 +05:30 committed by Akshay Joshi
parent 641f7bbe9d
commit 8ab358ccec
6 changed files with 9 additions and 9 deletions

View File

@ -249,7 +249,7 @@ define('pgadmin.node.rule', [
prev_e = prev_j ? t.itemData(prev_j) : null,
prev_k = t.hasParent(prev_j) ? t.parent(prev_j) : null,
prev_f = prev_k ? t.itemData(prev_k) : null;
if( prev_f._type == 'catalog') {
if(!_.isNull(prev_f) && prev_f._type == 'catalog') {
return false;
} else {
return true;
@ -264,7 +264,7 @@ define('pgadmin.node.rule', [
prev_i = t.hasParent(i) ? t.parent(i) : null;
prev_j = t.hasParent(prev_i) ? t.parent(prev_i) : null;
prev_e = prev_j ? t.itemData(prev_j) : null;
if(prev_e._type == 'schema') {
if(!_.isNull(prev_e) && prev_e._type == 'schema') {
return true;
}else{
return false;

View File

@ -389,7 +389,7 @@ define('pgadmin.node.mview', [
i = item || t.selected(),
d = data || (i && i.length == 1 ? t.itemData(i): undefined),
node = this || (d && pgAdmin.Browser.Nodes[d._type]),
info = node.getTreeNodeHierarchy.apply(node, [i]),
info = node && node.getTreeNodeHierarchy.apply(node, [i]),
version = info.server.version;
// disable refresh concurrently if server version is 9.3

View File

@ -44,7 +44,7 @@ function(gettext, _, $, Backbone, Backform, Backgrid, Alertify, pgAdmin, pgNode)
case 'enum':
model.set({'value': value}, {silent:true});
var options = [],
enumVals = variable.enumvals;
enumVals = variable && variable.enumvals;
_.each(enumVals, function(enumVal) {
options.push([enumVal, enumVal]);

View File

@ -58,7 +58,7 @@ define('pgadmin.browser', [
var data = JSON.parse(payload).data;
if (data.length && data[0]._type !== 'column' &&
data[0]._type !== 'catalog_object_column') {
data = data.sort(function(a, b) {
data.sort(function(a, b) {
return pgAdmin.natural_sort(a.label, b.label);
});
}
@ -1265,7 +1265,7 @@ define('pgadmin.browser', [
var _parent = this.t.parent(this.i) || null;
// If there is no parent then just update the node
if(_parent.length == 0 && ctx.op == 'UPDATE') {
if(_parent && _parent.length == 0 && ctx.op == 'UPDATE') {
updateNode();
} else {
var postRemove = function() {

View File

@ -349,7 +349,7 @@ define([
sel_rows = [],
item = pgBrowser.tree.selected(),
d = item ? pgBrowser.tree.itemData(item) : null,
node = pgBrowser.Nodes[d._type],
node = d && pgBrowser.Nodes[d._type],
url = undefined,
msg = undefined,
title = undefined;

View File

@ -896,7 +896,7 @@ define('pgadmin.browser.node', [
if (bgcolor) {
// li tag for the current branch
var first_level_element = element.parents()[3] || null,
var first_level_element = (element && element.parents()[3]) || null,
dynamic_class = 'pga_server_' + data._id + '_bgcolor',
style_tag;
@ -1012,7 +1012,7 @@ define('pgadmin.browser.node', [
data = item && t.itemData(item);
// In case of unload remove the collection counter
if (self.is_collection && 'collection_count' in data) {
if (self.is_collection && data === Object(data) &&'collection_count' in data) {
delete data.collection_count;
t.setLabel(item, {
label: _.escape(data._label),