From ab4f18fbeba4cc4a8db3371008e0dbb29c99f10b Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 10 Sep 2015 17:21:38 +0200 Subject: improve code quality --- server/sonar-web/.eslintrc | 2 +- .../src/main/js/apps/nav/global/search-view.js | 8 +-- .../js/apps/project-permissions/groups-view.js | 4 +- .../main/js/apps/project-permissions/users-view.js | 10 ++-- .../restore-built-in-profiles-view.js | 2 +- .../js/components/common/handlebars-extensions.js | 7 +-- .../js/components/common/jquery-isolated-scroll.js | 21 +------- .../navigator/filters/ajax-select-filters.js | 34 +++--------- .../components/navigator/filters/base-filters.js | 24 ++------- .../navigator/filters/checkbox-filters.js | 24 ++------- .../components/navigator/filters/choice-filters.js | 30 +++-------- .../navigator/filters/favorite-filters.js | 24 ++------- .../js/components/navigator/filters/filter-bar.js | 22 +------- .../components/navigator/filters/metric-filters.js | 24 ++------- .../navigator/filters/more-criteria-filters.js | 24 ++------- .../components/navigator/filters/range-filters.js | 26 ++-------- .../components/navigator/filters/string-filters.js | 26 ++-------- .../main/js/components/workspace/models/items.js | 4 +- server/sonar-web/src/main/js/libs/application.js | 60 +++++++++++----------- .../sonar-web/src/main/js/libs/recent-history.js | 28 ++-------- .../src/main/js/libs/select2-jquery-ui-fix.js | 21 +------- .../src/main/js/libs/widgets/bubble-chart.js | 4 +- .../sonar-web/src/main/js/libs/widgets/timeline.js | 2 +- 23 files changed, 103 insertions(+), 328 deletions(-) (limited to 'server') diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index e8523d53f38..95ac0b44959 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -106,7 +106,7 @@ "no-shadow-restricted-names": 1, // disallow shadowing of names such as arguments "no-undef": 2, // disallow use of undeclared variables unless mentioned in a /*global */ block "no-undef-init": 2, // disallow use of undefined when initializing variables - "no-undefined": 2, // disallow use of undefined variable (off by default) + "no-undefined": 0, // disallow use of undefined variable (off by default) "no-unused-vars": 2, // disallow declaration of variables that are not used in the code "no-use-before-define": 0, // disallow use of variables before they are defined diff --git a/server/sonar-web/src/main/js/apps/nav/global/search-view.js b/server/sonar-web/src/main/js/apps/nav/global/search-view.js index 2aaad79d8d3..e38787aba66 100644 --- a/server/sonar-web/src/main/js/apps/nav/global/search-view.js +++ b/server/sonar-web/src/main/js/apps/nav/global/search-view.js @@ -120,7 +120,7 @@ define([ that.favorite = r.map(function (f) { var isFile = ['FIL', 'UTS'].indexOf(f.qualifier) !== -1; return { - url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + dashboardParameters(true), + url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + window.dashboardParameters(true), name: isFile ? window.collapsedDirFromPath(f.lname) + window.fileFromPath(f.lname) : f.name, icon: 'favorite' }; @@ -132,8 +132,10 @@ define([ resetResultsToDefault: function () { var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')), history = (recentHistory || []).map(function (historyItem, index) { + var url = baseUrl + '/dashboard/index?id=' + encodeURIComponent(historyItem.key) + + window.dashboardParameters(true); return { - url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(historyItem.key) + dashboardParameters(true), + url: url, name: historyItem.name, q: historyItem.icon, extra: index === 0 ? t('browsed_recently') : null @@ -167,7 +169,7 @@ define([ collection.push(_.extend(item, { q: domain.q, extra: index === 0 ? domain.name : null, - url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(item.key) + dashboardParameters(true) + url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(item.key) + window.dashboardParameters(true) })); }); }); diff --git a/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js b/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js index 122a6a0ed20..e5315e5dd14 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js +++ b/server/sonar-web/src/main/js/apps/project-permissions/groups-view.js @@ -39,7 +39,9 @@ define([ }, onDestroy: function () { - this.options.refresh && this.options.refresh(); + if (this.options.refresh) { + this.options.refresh(); + } this._super(); }, diff --git a/server/sonar-web/src/main/js/apps/project-permissions/users-view.js b/server/sonar-web/src/main/js/apps/project-permissions/users-view.js index 5f54a1ad2a9..370db728ba1 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/users-view.js +++ b/server/sonar-web/src/main/js/apps/project-permissions/users-view.js @@ -9,6 +9,8 @@ define([ onRender: function () { this._super(); + var searchUrl = baseUrl + '/api/permissions/users?ps=100&permission=' + this.options.permission + + '&projectId=' + this.options.project; new window.SelectList({ el: this.$('#project-permissions-users'), width: '100%', @@ -18,7 +20,7 @@ define([ return item.name + '
' + item.login + ''; }, queryParam: 'q', - searchUrl: baseUrl + '/api/permissions/users?ps=100&permission=' + this.options.permission + '&projectId=' + this.options.project, + searchUrl: searchUrl, selectUrl: baseUrl + '/api/permissions/add_user', deselectUrl: baseUrl + '/api/permissions/remove_user', extra: { @@ -35,14 +37,16 @@ define([ }, onDestroy: function () { - this.options.refresh && this.options.refresh(); + if (this.options.refresh) { + this.options.refresh(); + } this._super(); }, serializeData: function () { return _.extend(Modal.prototype.serializeData.apply(this, arguments), { projectName: this.options.projectName - }) + }); } }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js index bd223c261f3..2d39c14761c 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/restore-built-in-profiles-view.js @@ -27,7 +27,7 @@ define([ return ModalFormView.extend({ template: Templates['quality-profiles-restore-built-in-profiles'], - onFormSubmit: function (e) { + onFormSubmit: function () { ModalFormView.prototype.onFormSubmit.apply(this, arguments); this.disableForm(); this.sendRequest(); diff --git a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js index c85329a0535..557e883f087 100644 --- a/server/sonar-web/src/main/js/components/common/handlebars-extensions.js +++ b/server/sonar-web/src/main/js/components/common/handlebars-extensions.js @@ -19,6 +19,7 @@ */ (function () { Handlebars.registerHelper('log', function () { + /* eslint no-console: 0 */ var args = Array.prototype.slice.call(arguments, 0, -1); console.log.apply(console, args); }); @@ -198,12 +199,12 @@ }); Handlebars.registerHelper('eq', function (v1, v2, options) { - // use `==` instead of `===` to ignore types + /* eslint eqeqeq: 0 */ return v1 == v2 ? options.fn(this) : options.inverse(this); }); Handlebars.registerHelper('notEq', function (v1, v2, options) { - // use `==` instead of `===` to ignore types + /* eslint eqeqeq: 0 */ return v1 != v2 ? options.fn(this) : options.inverse(this); }); @@ -315,7 +316,7 @@ return ret; }); - Handlebars.registerHelper('sum', function (a, b) { + Handlebars.registerHelper('sum', function () { var args = Array.prototype.slice.call(arguments, 0, -1); return args.reduce(function (p, c) { return p + +c; diff --git a/server/sonar-web/src/main/js/components/common/jquery-isolated-scroll.js b/server/sonar-web/src/main/js/components/common/jquery-isolated-scroll.js index e65a9c61541..2733b2a7359 100644 --- a/server/sonar-web/src/main/js/components/common/jquery-isolated-scroll.js +++ b/server/sonar-web/src/main/js/components/common/jquery-isolated-scroll.js @@ -1,23 +1,4 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -;(function ($) { +(function ($) { $.fn.isolatedScroll = function () { this.on('wheel', function (e) { diff --git a/server/sonar-web/src/main/js/components/navigator/filters/ajax-select-filters.js b/server/sonar-web/src/main/js/components/navigator/filters/ajax-select-filters.js index 36c07bbe947..c427c91102f 100644 --- a/server/sonar-web/src/main/js/components/navigator/filters/ajax-select-filters.js +++ b/server/sonar-web/src/main/js/components/navigator/filters/ajax-select-filters.js @@ -1,27 +1,9 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ define([ + 'jquery', './base-filters', './choice-filters', '../templates' -], function (BaseFilters, ChoiceFilters) { +], function ($, BaseFilters, ChoiceFilters) { var PAGE_SIZE = 100; @@ -247,7 +229,7 @@ define([ renderInput: function() { var value = this.model.get('value') || [], - input = $j('') + input = $('') .prop('name', this.model.get('property')) .prop('type', 'hidden') .css('display', 'none') @@ -337,7 +319,7 @@ define([ return that.createRequest(v); }); - $j.when.apply($j, requests).done(function () { + $.when.apply($, requests).done(function () { that.onRestore(value); }); }, @@ -376,7 +358,7 @@ define([ createRequest: function(v) { var that = this; - return $j + return $ .ajax({ url: baseUrl + '/api/resources', type: 'GET', @@ -407,7 +389,7 @@ define([ createRequest: function(v) { var that = this; - return $j + return $ .ajax({ url: baseUrl + '/api/resources', type: 'GET', @@ -438,7 +420,7 @@ define([ createRequest: function(v) { var that = this; - return $j + return $ .ajax({ url: baseUrl + '/api/users/search', type: 'GET', @@ -471,7 +453,7 @@ define([ createRequest: function(v) { var that = this; - return $j + return $ .ajax({ url: baseUrl + '/api/users/search', type: 'GET', diff --git a/server/sonar-web/src/main/js/components/navigator/filters/base-filters.js b/server/sonar-web/src/main/js/components/navigator/filters/base-filters.js index e4298597794..938b76028ee 100644 --- a/server/sonar-web/src/main/js/components/navigator/filters/base-filters.js +++ b/server/sonar-web/src/main/js/components/navigator/filters/base-filters.js @@ -1,25 +1,7 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ define([ + 'jquery', '../templates' -], function () { +], function ($) { var Filter = Backbone.Model.extend({ @@ -95,7 +77,7 @@ define([ attachDetailsView: function() { - this.detailsView.$el.detach().appendTo($j('body')); + this.detailsView.$el.detach().appendTo($('body')); }, diff --git a/server/sonar-web/src/main/js/components/navigator/filters/checkbox-filters.js b/server/sonar-web/src/main/js/components/navigator/filters/checkbox-filters.js index 8c837802e24..964dfa1ff81 100644 --- a/server/sonar-web/src/main/js/components/navigator/filters/checkbox-filters.js +++ b/server/sonar-web/src/main/js/components/navigator/filters/checkbox-filters.js @@ -1,26 +1,8 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ define([ + 'jquery', './base-filters', '../templates' -], function (BaseFilters) { +], function ($, BaseFilters) { return BaseFilters.BaseFilterView.extend({ template: Templates['checkbox-filter'], @@ -39,7 +21,7 @@ define([ renderInput: function() { if (this.model.get('enabled')) { - $j('') + $('') .prop('name', this.model.get('property')) .prop('type', 'checkbox') .prop('value', 'true') diff --git a/server/sonar-web/src/main/js/components/navigator/filters/choice-filters.js b/server/sonar-web/src/main/js/components/navigator/filters/choice-filters.js index 31fc08656ba..f65a5b58876 100644 --- a/server/sonar-web/src/main/js/components/navigator/filters/choice-filters.js +++ b/server/sonar-web/src/main/js/components/navigator/filters/choice-filters.js @@ -1,26 +1,8 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ define([ + 'jquery', './base-filters', '../templates' -], function (BaseFilters) { +], function ($, BaseFilters) { var DetailsChoiceFilterView = BaseFilters.DetailsFilterView.extend({ template: Templates['choice-filter'], @@ -116,12 +98,12 @@ define([ onShow: function() { this.bindedOnKeyDown = _.bind(this.onKeyDown, this); - $j('body').on('keydown', this.bindedOnKeyDown); + $('body').on('keydown', this.bindedOnKeyDown); }, onHide: function() { - $j('body').off('keydown', this.bindedOnKeyDown); + $('body').off('keydown', this.bindedOnKeyDown); }, @@ -247,12 +229,12 @@ define([ renderInput: function() { - var input = $j('') .prop('name', this.model.get('property')) .prop('multiple', true) .css('display', 'none'); this.choices.each(function(item) { - var option = $j('