From: Stas Vilchik Date: Wed, 18 Jun 2014 05:02:00 +0000 (+0600) Subject: Fix quality flaws X-Git-Tag: 4.4-RC1~371 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=546046706fec812fef7e9530159632bedd174a36;p=sonarqube.git Fix quality flaws --- diff --git a/sonar-server/src/main/js/application.js b/sonar-server/src/main/js/application.js index 7c3508d43e5..00723b0fe60 100644 --- a/sonar-server/src/main/js/application.js +++ b/sonar-server/src/main/js/application.js @@ -67,7 +67,7 @@ function resourceViewerOnBulkIssues() { } var SelectBox = { - cache: new Object(), + cache: {}, init: function (id) { var box = document.getElementById(id); var node; @@ -93,10 +93,11 @@ var SelectBox = { // Redisplay the HTML select box, displaying only the choices containing ALL // the words in text. (It's an AND search.) var tokens = text.toLowerCase().split(/\s+/); - var node, token; - for (var i = 0; (node = SelectBox.cache[id][i]); i++) { + for (var i = 0, n = SelectBox.cache[id].length; i < n; i++) { + var node = SelectBox.cache[id][i]; node.displayed = 1; - for (var j = 0; (token = tokens[j]); j++) { + for (var j = 0, k = tokens.length; j < k; j++) { + var token = tokens[j]; if (node.text.toLowerCase().indexOf(token) == -1) { node.displayed = 0; } @@ -105,15 +106,16 @@ var SelectBox = { SelectBox.redisplay(id); }, delete_from_cache: function (id, value) { - var node, delete_index = null; - for (var i = 0; (node = SelectBox.cache[id][i]); i++) { - if (node.value == value) { + var delete_index = null; + for (var i = 0, n = SelectBox.cache[id].length; i < n; i++) { + var node = SelectBox.cache[id][i]; + if (node.value === value) { delete_index = i; break; } } var j = SelectBox.cache[id].length - 1; - for (var i = delete_index; i < j; i++) { + for (i = delete_index; i < j; i++) { SelectBox.cache[id][i] = SelectBox.cache[id][i + 1]; } SelectBox.cache[id].length--; @@ -123,9 +125,9 @@ var SelectBox = { }, cache_contains: function (id, value) { // Check if an item is contained in the cache - var node; - for (var i = 0; (node = SelectBox.cache[id][i]); i++) { - if (node.value == value) { + for (var i = 0, j = SelectBox.cache[id].length; i < j; i++) { + var node = SelectBox.cache[id][i]; + if (node.value === value) { return true; } } @@ -133,8 +135,8 @@ var SelectBox = { }, move: function (from, to) { var from_box = document.getElementById(from); - var option; - for (var i = 0; (option = from_box.options[i]); i++) { + for (var i = 0, j = from_box.options.length; i < j; i++) { + var option = from_box.options[i]; if (option.selected && SelectBox.cache_contains(from, option.value)) { SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); SelectBox.delete_from_cache(from, option.value); @@ -145,8 +147,8 @@ var SelectBox = { }, move_all: function (from, to) { var from_box = document.getElementById(from); - var option; - for (var i = 0; (option = from_box.options[i]); i++) { + for (var i = 0, j = from_box.options.length; i < j; i++) { + var option = from_box.options[i]; if (SelectBox.cache_contains(from, option.value)) { SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); SelectBox.delete_from_cache(from, option.value); @@ -247,12 +249,12 @@ Treemap.prototype.rootNode = function () { Treemap.prototype.initNodes = function () { var self = this; - $j('#tm-' + this.id).find('a').each(function (index) { + $j('#tm-' + this.id).find('a').each(function () { $j(this).on("click", function (event) { event.stopPropagation(); }); }); - $j('#tm-' + this.id).find('[rid]').each(function (index) { + $j('#tm-' + this.id).find('[rid]').each(function () { $j(this).on("contextmenu", function (event) { event.stopPropagation(); event.preventDefault(); @@ -261,13 +263,13 @@ Treemap.prototype.initNodes = function () { if (self.breadcrumb.length > 1) { self.breadcrumb.pop(); self.load(); - } else if (self.breadcrumb.length == 1) { + } else if (self.breadcrumb.length === 1) { $j("#tm-loading-" + self.id).show(); location.reload(); } return false; }); - $j(this).on("click", function (event) { + $j(this).on("click", function () { var source = $j(this); var rid = source.attr('rid'); var context = new TreemapContext(rid, source.text()); @@ -332,16 +334,16 @@ function openModalWindow(url, options) { modalForm: function (ajax_options) { return this.each(function () { var obj = $j(this); - obj.submit(function (event) { + obj.submit(function () { $j('input[type=submit]', this).attr('disabled', 'disabled'); $j.ajax($j.extend({ type: 'POST', url: obj.attr('action'), data: obj.serialize(), - success: function (data) { + success: function () { window.location.reload(); }, - error: function (xhr, textStatus, errorThrown) { + error: function (xhr) { // If the modal window has defined a modal-error element, then returned text must be displayed in it var errorElt = obj.find(".modal-error"); if (errorElt.length) { @@ -369,7 +371,7 @@ function closeModalWindow() { return false; } -function supports_html5_storage() { +function supportsHTML5Storage() { try { return 'localStorage' in window && window['localStorage'] !== null; } catch (e) { @@ -404,14 +406,14 @@ function openAccordionItem(url, elt, updateCurrentElement) { // Remove all accordion items after current element elementToRemove.remove(); // Display loading image only if not already displayed (if previous call was not finished) - if (currentElement.next('.accordion-loading').length == 0) { + if (currentElement.next('.accordion-loading').length === 0) { loading.insertAfter(currentElement); } } else { // Current element is not in a working view, remove all working views $j('.'+ htmlClass).remove(); // Display loading image only if not already displayed (if previous call was not finished) - if ($j("#accordion-panel").next('.accordion-loading').length == 0) { + if ($j("#accordion-panel").next('.accordion-loading').length === 0) { loading.insertAfter($j("#accordion-panel")); } } @@ -511,7 +513,7 @@ function showDropdownMenu(menuId) { function showDropdownMenuOnElement(elt) { var dropdownElt = $j(elt); - if (dropdownElt == currentlyDisplayedDropdownMenu) { + if (dropdownElt === currentlyDisplayedDropdownMenu) { currentlyDisplayedDropdownMenu = ""; } else { currentlyDisplayedDropdownMenu = dropdownElt; diff --git a/sonar-server/src/main/js/issue.js b/sonar-server/src/main/js/issue.js index 3a91c7401ba..33991b0a00a 100644 --- a/sonar-server/src/main/js/issue.js +++ b/sonar-server/src/main/js/issue.js @@ -55,7 +55,7 @@ function submitIssueForm(elt) { issueElt.replaceWith(replaced); notifyIssueChange(issueKey); } - ).fail(function (jqXHR, textStatus) { + ).fail(function (jqXHR) { closeIssueForm(elt); issueElt.find('.code-issue-actions').replaceWith(jqXHR.responseText); }); @@ -79,7 +79,7 @@ function doIssueAction(elt, action, parameters) { issueElt.replaceWith(replaced); notifyIssueChange(issueKey); } - ).fail(function (jqXHR, textStatus) { + ).fail(function (jqXHR) { issueElt.find('.code-issue-actions').replaceWith(jqXHR.responseText); }); return false; @@ -144,7 +144,7 @@ function doEditIssueComment(elt) { issueElt.replaceWith(replaced); notifyIssueChange(issueKey); }, - error: function (jqXHR, textStatus) { + error: function (jqXHR) { closeIssueForm(elt); var commentElt = formElt.closest('[data-comment-key]'); commentElt.replaceWith(jqXHR.responseText); @@ -165,7 +165,6 @@ function refreshIssue(elt) { /* Open form for creating a manual issue */ function openCIF(elt, componentId, line) { - // TODO check if form is already displayed (by using form id) $j.get(baseUrl + "/issue/create_form?component=" + componentId + "&line=" + line, function (html) { $j(elt).closest('tr').find('td.line').append($j(html)); }); @@ -192,7 +191,7 @@ function submitCreateIssueForm(elt) { var replaced = $j(html); formElt.replaceWith(replaced); } - ).error(function (jqXHR, textStatus, errorThrown) { + ).error(function (jqXHR) { var errorsElt = formElt.find('.code-issue-errors'); errorsElt.html(jqXHR.responseText); errorsElt.removeClass('hidden'); diff --git a/sonar-server/src/main/js/navigator/filters/filter-bar.js b/sonar-server/src/main/js/navigator/filters/filter-bar.js index 6e9aedf7809..b753bd6ff09 100644 --- a/sonar-server/src/main/js/navigator/filters/filter-bar.js +++ b/sonar-server/src/main/js/navigator/filters/filter-bar.js @@ -52,12 +52,11 @@ define( if (el.is(':input') || el.is('a')) { if (e.keyCode === 9 || e.keyCode === 27) { return tabbableSet.index(el) >= tabbableSet.length - 1; - } else { - return false; } - } else { - return true; + return false; } + + return true; }; key('tab', 'list', function() { key.setScope('filters'); diff --git a/sonar-server/src/main/js/resource.js b/sonar-server/src/main/js/resource.js index 04165488070..ed3ed393069 100644 --- a/sonar-server/src/main/js/resource.js +++ b/sonar-server/src/main/js/resource.js @@ -3,7 +3,7 @@ */ function loadResourceViewer(resourceId, tab, display_title, period, elt) { - if (display_title == undefined) { + if (display_title == null) { display_title = true; } @@ -44,7 +44,7 @@ function collapseTests(index, elt){ } /* Source decoration functions */ -function highlight_usages(event){ +function highlightUsages(event){ var isAlreadyHighlighted = false; var selectedElementClasses = $j(this).attr("class").split(" "); if(selectedElementClasses.indexOf("highlighted") !== -1) { diff --git a/sonar-server/src/main/js/top-search.js b/sonar-server/src/main/js/top-search.js index 8137d3d4122..aaca4227a97 100644 --- a/sonar-server/src/main/js/top-search.js +++ b/sonar-server/src/main/js/top-search.js @@ -125,43 +125,34 @@ } }, - debouncedKeyup = _.debounce(onKeyup, 250); + debouncedKeyup = _.debounce(onKeyup, 250), - - el - .on('keydown', function(e) { - function prevent(e) { - e.preventDefault(); + onKeyDown = function(e) { + if ([13, 38, 40, 37, 39, 16, 17, 18, 91, 20, 21].indexOf(e.keyCode) !== -1) { symbol = false; } switch (e.keyCode) { case 13: // return - prevent(e); + e.preventDefault(); choose(); return; case 38: // up - prevent(e); + e.preventDefault(); selectPrev(); return; case 40: // down - prevent(e); + e.preventDefault(); selectNext(); return; - case 37: // left - case 39: // right - case 16: // shift - case 17: // ctrl - case 18: // alt - case 91: // cmd - case 20: // caps - case 27: // esc - symbol = false; - return; default: symbol = true; } - }) + }; + + + el + .on('keydown', onKeyDown) .on('keyup', debouncedKeyup) .on('focus', function() { el.data('placeholder', el.val()); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_projects.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_projects.html.erb index b5ba999b004..f1c1401c77a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_projects.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_projects.html.erb @@ -1,5 +1,5 @@ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb index d24cae1a30e..4e70a8398f0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb @@ -5,7 +5,7 @@ <%