gitlabhq/gitlabhq

View on GitHub
app/assets/javascripts/gl_dropdown.js

Summary

Maintainability
F
6 days
Test Coverage

File gl_dropdown.js has 921 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable func-names, no-underscore-dangle, no-var, one-var, vars-on-top, no-unused-vars, no-shadow, no-cond-assign, prefer-arrow-callback, no-return-assign, no-else-return, camelcase, no-lonely-if, guard-for-in, no-restricted-syntax, consistent-return, prefer-template, no-param-reassign, no-loop-func */
/* global fuzzaldrinPlus */

import $ from 'jquery';
import _ from 'underscore';
Severity: Major
Found in app/assets/javascripts/gl_dropdown.js - About 2 days to fix

    Function GitLabDropdown has 172 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function GitLabDropdown(el1, options) {
        var searchFields, selector, self;
        this.el = el1;
        this.options = options;
        this.updateLabel = this.updateLabel.bind(this);
    Severity: Major
    Found in app/assets/javascripts/gl_dropdown.js - About 6 hrs to fix

      Function renderItem has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        GitLabDropdown.prototype.renderItem = function(data, group, index) {
          var field, html, selected, text, url, value, rowHidden;
      
          if (!this.options.renderRow) {
            value = this.options.id ? this.options.id(data) : data.id;
      Severity: Major
      Found in app/assets/javascripts/gl_dropdown.js - About 3 hrs to fix

        Function rowClicked has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          GitLabDropdown.prototype.rowClicked = function(el) {
            var field, groupName, isInput, selectedIndex, selectedObject, value, isMarking;
        
            const { fieldName } = this.options;
            isInput = $(this.el).is('input');
        Severity: Major
        Found in app/assets/javascripts/gl_dropdown.js - About 3 hrs to fix

          Function GitLabDropdownFilter has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function GitLabDropdownFilter(input, options) {
              var $clearButton, $inputContainer, ref, timeout;
              this.input = input;
              this.options = options;
              this.filterInputBlur = (ref = this.options.filterInputBlur) != null ? ref : true;
          Severity: Major
          Found in app/assets/javascripts/gl_dropdown.js - About 2 hrs to fix

            Function filter has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              GitLabDropdownFilter.prototype.filter = function(search_text) {
                var data, elements, group, key, results, tmp;
                if (this.options.onFilter) {
                  this.options.onFilter(search_text);
                }
            Severity: Major
            Found in app/assets/javascripts/gl_dropdown.js - About 2 hrs to fix

              Function GitLabDropdownInput has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function GitLabDropdownInput(input, options) {
                  var $inputContainer, $clearButton;
                  var _this = this;
                  this.input = input;
                  this.options = options;
              Severity: Minor
              Found in app/assets/javascripts/gl_dropdown.js - About 1 hr to fix

                Function addArrowKeyEvent has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  GitLabDropdown.prototype.addArrowKeyEvent = function() {
                    var $input, ARROW_KEY_CODES, selector;
                    ARROW_KEY_CODES = [38, 40];
                    $input = this.dropdown.find('.dropdown-input-field');
                    selector = SELECTABLE_CLASSES;
                Severity: Minor
                Found in app/assets/javascripts/gl_dropdown.js - About 1 hr to fix

                  Function highlightRowAtIndex has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    GitLabDropdown.prototype.highlightRowAtIndex = function($listItems, index) {
                      var $dropdownContent,
                        $listItem,
                        dropdownContentBottom,
                        dropdownContentHeight,
                  Severity: Minor
                  Found in app/assets/javascripts/gl_dropdown.js - About 1 hr to fix

                    Function opened has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      GitLabDropdown.prototype.opened = function(e) {
                        var contentHtml;
                        this.resetRows();
                        this.addArrowKeyEvent();
                    
                    
                    Severity: Minor
                    Found in app/assets/javascripts/gl_dropdown.js - About 1 hr to fix

                      Function parseData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        GitLabDropdown.prototype.parseData = function(data) {
                          var full_html, groupData, html, name;
                          this.renderedData = data;
                          if (this.options.filterable && data.length === 0) {
                            // render no matching results
                      Severity: Minor
                      Found in app/assets/javascripts/gl_dropdown.js - About 1 hr to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    for (key in data) {
                                      group = data[key];
                                      tmp = fuzzaldrinPlus.filter(group, search_text, {
                                        key: this.options.keys,
                                      });
                        Severity: Major
                        Found in app/assets/javascripts/gl_dropdown.js - About 45 mins to fix

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                              $clearButton.on(
                                'click',
                                (function(_this) {
                                  // Clear click
                                  return function(e) {
                          Severity: Major
                          Found in app/assets/javascripts/gl_dropdown.js and 1 other location - About 2 hrs to fix
                          app/assets/javascripts/gl_dropdown.js on lines 83..96

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 82.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                              $clearButton.on(
                                'click',
                                (function(_this) {
                                  // Clear click
                                  return function(e) {
                          Severity: Major
                          Found in app/assets/javascripts/gl_dropdown.js and 1 other location - About 2 hrs to fix
                          app/assets/javascripts/gl_dropdown.js on lines 22..35

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 82.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                              this.input
                                .on('keydown', function(e) {
                                  var keyCode = e.which;
                                  if (keyCode === 13 && !options.elIsInput) {
                                    e.preventDefault();
                          Severity: Major
                          Found in app/assets/javascripts/gl_dropdown.js and 1 other location - About 1 hr to fix
                          app/assets/javascripts/gl_dropdown.js on lines 99..135

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 67.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                              this.input
                                .on('keydown', function(e) {
                                  var keyCode = e.which;
                                  if (keyCode === 13 && !options.elIsInput) {
                                    e.preventDefault();
                          Severity: Major
                          Found in app/assets/javascripts/gl_dropdown.js and 1 other location - About 1 hr to fix
                          app/assets/javascripts/gl_dropdown.js on lines 37..57

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 67.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          There are no issues that match your filters.

                          Category
                          Status