Skip to content

Commit 69ef736

Browse files
committed
Fixing deepscan, sonarcloud, and other linting issues
1 parent f1075d1 commit 69ef736

28 files changed

+754
-1120
lines changed

kbase-extension/static/kbase/js/kbwidget.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ return KBWidget(
2727
version : "1.0.0", //future proofing, but completely unused
2828
2929
_accessors : [ //optional. A list of values to automatically create setter/getters for.
30-
'foo' //you'll now be able to store something at $widget.foo('newValue') and access it via var foo = $widget.foo();
30+
'foo' //you'll now be able to store something at $widget.foo('newValue') and access it via const foo = $widget.foo();
3131
{name : 'bar', setter : 'setBar', getter : 'getBar'} // the setter/getter can also be overridden If these functions are not
3232
// defined in your object, you'll get default implementations. Add new methods
3333
// in the object body for specific behavior. See the caveat about bindings and notifications
@@ -59,14 +59,14 @@ return KBWidget(
5959
6060
Instantiate as follows:
6161
62-
var $fancy = $('some-jquery-selector').myFancyNewWidget(
62+
const $fancy = $('some-jquery-selector').myFancyNewWidget(
6363
{
6464
bar : 7
6565
}
6666
);
6767
68-
var foo = $fancy.foo();
69-
var $element = $fancy.$elem; //is the same as $('some-jquery-selector');
68+
const foo = $fancy.foo();
69+
const $element = $fancy.$elem; //is the same as $('some-jquery-selector');
7070
7171
You get a lot of methods availabe by default:
7272
@@ -198,7 +198,7 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
198198
};
199199

200200
const makeBindingBlurCallback = function (elem, $target, attribute, transformers, accessors) {
201-
return $.proxy(function (e, vals) {
201+
return $.proxy(function (e) {
202202
if (e.type === 'keypress' && e.which !== 13) {
203203
return;
204204
}
@@ -410,15 +410,15 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
410410
return $(tag);
411411
};
412412

413-
const KBWidget = function (def) {
413+
var KBWidget = function (def) {
414414
def = def || {};
415415

416-
var Widget = function ($elem) {
416+
const Widget = function ($elem) {
417417
let self = this;
418418

419419
//XXX THIS IS FOR BACKWARDS COMPATIBILITY WITH JQUERY PLUGIN SYNTAX __ONLY__
420420
if (!(this instanceof Widget)) {
421-
var args = $elem;
421+
const args = $elem;
422422
self = new Widget(this, args);
423423
$elem = this;
424424
if (window.console) {
@@ -443,7 +443,7 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
443443
$elem.get(0).kb_obj = self;
444444
}
445445

446-
var args = Array.prototype.slice.call(arguments, 1);
446+
const args = Array.prototype.slice.call(arguments, 1);
447447

448448
$elem[def.name] = function (method) {
449449
if (window.console) {
@@ -471,7 +471,6 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
471471
Widget.prototype.__attributes = {};
472472

473473
if (defCopy._accessors !== undefined) {
474-
//for (var accessor in defCopy._accessors) {
475474
$.each(
476475
defCopy._accessors,
477476
$.proxy((idx, accessor) => {
@@ -615,15 +614,13 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
615614
const opts = $.extend(true, {}, this.options);
616615
this.options = $.extend(true, {}, opts, args);
617616

618-
let arg;
619-
for (arg in args) {
617+
for (const arg in args) {
620618
if (args[arg] === undefined && this.options[arg] !== undefined) {
621619
delete this.options[arg];
622620
}
623621
}
624622

625-
let attribute;
626-
for (attribute in this.__attributes) {
623+
for (const attribute in this.__attributes) {
627624
if (this.options[attribute] !== undefined) {
628625
const setter = this.__attributes[attribute].setter;
629626
this[setter](this.options[attribute]);
@@ -645,12 +642,12 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
645642
if (this.options.template) {
646643
$.ajax(this.options.template)
647644
.done(
648-
$.proxy(function (res) {
645+
$.proxy(function () {
649646
this.templateSuccess.apply(this, arguments);
650647
}, this)
651648
)
652649
.fail(
653-
$.proxy(function (res) {
650+
$.proxy(function () {
654651
this.templateFailure.apply(this, arguments);
655652
}, this)
656653
);
@@ -662,10 +659,7 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
662659
templateSuccess: function (templateString) {
663660
const template = Handlebars.compile(templateString);
664661

665-
const html = template();
666-
667662
const res = template(this.templateContent());
668-
669663
const $res = $.jqElem('span').append(res);
670664
this._rewireIds($res, this);
671665

@@ -727,7 +721,7 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
727721
setValuesForKeys: function setValuesForKeys(obj) {
728722
const objCopy = $.extend({}, obj);
729723

730-
for (attribute in this.__attributes) {
724+
for (const attribute in this.__attributes) {
731725
if (objCopy[attribute] !== undefined) {
732726
const setter = this.__attributes[attribute].setter;
733727
this[setter](objCopy[attribute]);
@@ -769,7 +763,7 @@ define(['jquery', 'handlebars'], ($, Handlebars) => {
769763
$elem.removeAttr('id');
770764
}
771765

772-
$.each($elem.find('[id]'), function (idx) {
766+
$.each($elem.find('[id]'), function () {
773767
$target.data($(this).attr('id'), $(this));
774768
$(this).attr('data-id', $(this).attr('id'));
775769
$(this).removeAttr('id');

kbase-extension/static/kbase/js/widgets/function_input/kbStandaloneListselect.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Listselect Renderer
33
44
Provides a select list that allows the selection of one or multiple data items that can be filtered by their attributes. The attribute to be filtered will be displayed as the label in the selection list. Filters can be chained by pressing the enter key in the filter box.
@@ -140,7 +140,7 @@
140140

141141
render: function (index) {
142142
const renderer = rendererListselect[index];
143-
143+
let button_span, result_list;
144144
if (renderer.settings.navigation_url) {
145145
renderer.settings.navigation_callback = renderer.update_data;
146146
}
@@ -231,14 +231,9 @@
231231
renderer.settings.filter_attribute + ' <span class="caret"></span>';
232232
const filter_list = document.createElement('ul');
233233
filter_list.setAttribute('class', 'dropdown-menu');
234-
filter_list.setAttribute(
235-
'style',
236-
renderer.settings.extra_wide
237-
? 'max-height: 200px; overflow: auto;'
238-
: 'max-height: 200px; overflow: auto;'
239-
);
234+
filter_list.setAttribute('style', 'max-height: 200px; overflow: auto;');
240235
let filter_string = '';
241-
for (var i = 0; i < renderer.settings.filter.length; i++) {
236+
for (let i = 0; i < renderer.settings.filter.length; i++) {
242237
filter_string +=
243238
'<li><a onclick="rendererListselect[' +
244239
renderer.index +
@@ -265,7 +260,7 @@
265260
'style',
266261
'font-size: 9px; position: relative; top: -5px;'
267262
);
268-
for (var i = 0; i < renderer.settings.filter_breadcrumbs.length; i++) {
263+
for (let i = 0; i < renderer.settings.filter_breadcrumbs.length; i++) {
269264
const bc_button = document.createElement('button');
270265
bc_button.setAttribute('class', 'btn btn-mini');
271266
bc_button.setAttribute('style', 'margin-right: 3px;');
@@ -276,7 +271,7 @@
276271
': ' +
277272
renderer.settings.filter_breadcrumbs[i][1] +
278273
' <span style="font-size: 11px; color: gray;">x</span>';
279-
bc_button.addEventListener('click', function (event) {
274+
bc_button.addEventListener('click', function () {
280275
rendererListselect[index].removeBreadcrumb(this, index);
281276
});
282277
filter_breadcrumbs.appendChild(bc_button);
@@ -285,7 +280,7 @@
285280
// check for multi-select vs single select
286281
if (renderer.settings.multiple) {
287282
// create the result list
288-
var result_list = document.createElement('select');
283+
const result_list = document.createElement('select');
289284
result_list.setAttribute('multiple', '');
290285
result_list.setAttribute('style', 'width: 415px');
291286
result_list.setAttribute('size', renderer.settings.rows);
@@ -294,7 +289,7 @@
294289
renderer.redrawResultlist(result_list, index);
295290

296291
// create the action buttons
297-
var button_span = document.createElement('span');
292+
button_span = document.createElement('span');
298293
button_span.setAttribute('style', 'position: relative; bottom: 100px;');
299294
const button_left = document.createElement('a');
300295
button_left.setAttribute('class', 'btn btn-small btn-default');
@@ -411,12 +406,12 @@
411406
? renderer.settings.button.icon
412407
: '<i class="fa fa-check"></i>');
413408
if (typeof renderer.settings.callback == 'function') {
414-
var index = renderer.index;
409+
const index = renderer.index;
415410
if (renderer.settings.multiple) {
416411
submit_button.addEventListener('click', () => {
417412
const selection_result = [];
418413
if (renderer.settings.return_object) {
419-
for (var x = 0; x < result_list.options.length; x++) {
414+
for (let x = 0; x < result_list.options.length; x++) {
420415
for (let y = 0; y < renderer.settings.data.length; y++) {
421416
if (
422417
result_list.options[x].value ==
@@ -428,7 +423,7 @@
428423
}
429424
}
430425
} else {
431-
for (var x = 0; x < result_list.options.length; x++) {
426+
for (let x = 0; x < result_list.options.length; x++) {
432427
selection_result.push(result_list.options[x].value);
433428
}
434429
}
@@ -550,7 +545,7 @@
550545
redrawResultlist: function (result_list, index) {
551546
const renderer = rendererListselect[index];
552547
const result_list_array = [];
553-
for (var i = 0; i < renderer.settings.selection_data.length; i++) {
548+
for (let i = 0; i < renderer.settings.selection_data.length; i++) {
554549
result_list_array.push([
555550
renderer.settings.selection_data[i][renderer.settings.value],
556551
'<option value="' +
@@ -566,7 +561,7 @@
566561
result_list_array.sort(renderer.listsort);
567562
}
568563
let result_list_string = '';
569-
for (var i = 0; i < result_list_array.length; i++) {
564+
for (let i = 0; i < result_list_array.length; i++) {
570565
result_list_string += result_list_array[i][1];
571566
}
572567
result_list.innerHTML = result_list_string;
@@ -579,7 +574,7 @@
579574
renderer.settings.filtered_data = renderer.settings.data;
580575

581576
// apply all filter breadcrumbs
582-
for (var i = 0; i < renderer.settings.filter_breadcrumbs.length; i++) {
577+
for (let i = 0; i < renderer.settings.filter_breadcrumbs.length; i++) {
583578
renderer.settings.filtered_data = renderer.filter(
584579
{
585580
data: renderer.settings.filtered_data,
@@ -609,7 +604,7 @@
609604

610605
// create the selection list
611606
let settings_string = '';
612-
for (var i = 0; i < renderer.settings.filtered_data.length; i++) {
607+
for (let i = 0; i < renderer.settings.filtered_data.length; i++) {
613608
if (
614609
!renderer.settings.selection[
615610
renderer.settings.filtered_data[i][renderer.settings.value]
@@ -708,7 +703,7 @@
708703
}
709704
},
710705
update_data: function (params, index) {
711-
const renderer = rendererListselect[index];
706+
let renderer = rendererListselect[index];
712707

713708
if (typeof params == 'string' && params == 'more') {
714709
renderer.settings.offset = renderer.settings.data.length;
@@ -777,7 +772,7 @@
777772
headers: headers,
778773
dataType: 'json',
779774
success: function (data) {
780-
const renderer = rendererListselect[index];
775+
renderer = rendererListselect[index];
781776
renderer.settings.total_count = data.total_count;
782777
if (typeof params == 'string' && params == 'more') {
783778
renderer.settings.data = renderer.settings.data.concat(data.data);

kbase-extension/static/kbase/js/widgets/function_input/kbaseDefaultNarrativeInput.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
1010
Config,
1111
kbaseNarrativeInput
1212
) => {
13+
'use strict';
1314
return KBWidget({
1415
name: 'kbaseDefaultNarrativeInput',
1516
parent: kbaseNarrativeInput,
@@ -48,7 +49,7 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
4849
p.default !== '' && p.default !== undefined
4950
? " placeholder='" + p.default + "'"
5051
: '';
51-
input =
52+
const input =
5253
"<input class='form-control' style='width: 95%' name='" +
5354
pid +
5455
"'" +
@@ -93,7 +94,7 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
9394
$(this.$elem)
9495
.find('[name^=param]')
9596
.filter(':input')
96-
.each((key, field) => {
97+
.each((_key, field) => {
9798
let value = field.value;
9899
if (!value) value = field.placeholder;
99100
paramList.push(value.trim());
@@ -117,7 +118,7 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
117118
$(this.$elem)
118119
.find('[name^=param]')
119120
.filter(':input')
120-
.each((key, field) => {
121+
.each((_key, field) => {
121122
state[field.name] = field.value;
122123
});
123124

@@ -135,18 +136,16 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
135136
$(this.$elem)
136137
.find('[name^=param]')
137138
.filter(':input')
138-
.each((key, field) => {
139+
.each((_key, field) => {
139140
const $field = $(field);
140141
const fieldName = $field.attr('name');
141142

142143
// If it's a text field, just dump the value in there.
143-
if ($field.is('input') && $field.attr('type') === 'text') {
144-
$field.val(state[fieldName]);
145-
}
146-
147-
// If it's a select field, do the same... we'll have comboboxen or something,
148-
// eventually, so I'm just leaving this open for that.
149-
else if ($field.is('select')) {
144+
// If it's a select field, do the same.
145+
if (
146+
($field.is('input') && $field.attr('type') === 'text') ||
147+
$field.is('select')
148+
) {
150149
$field.val(state[fieldName]);
151150
}
152151
});
@@ -223,7 +222,7 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
223222
// case 3 - data, need new datalist
224223
// case 4 - data, need to update existing datalist
225224
else if (objList.length > 0) {
226-
var $datalist;
225+
let $datalist;
227226
if (!datalistID) {
228227
datalistID = this.genUUID();
229228
$input.attr('list', datalistID);
@@ -233,9 +232,9 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativeInp
233232
$datalist = $(this.$elem.find('#' + datalistID));
234233
}
235234
$datalist.empty();
236-
for (let j = 0; j < objList.length; j++) {
235+
for (const element of objList) {
237236
$datalist.append(
238-
$('<option>').attr('value', objList[j][1]).append(objList[j][1])
237+
$('<option>').attr('value', element[1]).append(element[1])
239238
);
240239
}
241240
}

kbase-extension/static/kbase/js/widgets/function_input/parameter_input/kbaseNarrativeParameterCheckboxInput.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,8 @@ define(['kbwidget', 'bootstrap', 'jquery', 'narrativeConfig', 'kbaseNarrativePar
258258
// handle case with multiple fields
259259
if (this.$elem.find('#' + this.spec.id).prop('checked')) {
260260
return this.checkedValue;
261-
} else {
262-
return this.uncheckedValue;
263261
}
264-
return '';
262+
return this.uncheckedValue;
265263
},
266264
});
267265
});

0 commit comments

Comments
 (0)