FanaHOVA/blazer

View on GitHub
app/assets/javascripts/blazer/Sortable.js

Summary

Maintainability
F
4 days
Test Coverage

File Sortable.js has 779 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**!
 * Sortable
 * @author  RubaXa   <trash@rubaxa.org>
 * @license MIT
 */
Severity: Major
Found in app/assets/javascripts/blazer/Sortable.js - About 1 day to fix

    Function _onDragOver has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _onDragOver: function (/**Event*/evt) {
          var el = this.el,
            target,
            dragRect,
            revert,
    Severity: Major
    Found in app/assets/javascripts/blazer/Sortable.js - About 3 hrs to fix

      Function _autoScroll has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
            // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
            if (rootEl && options.scroll) {
              var el,
                rect,
      Severity: Major
      Found in app/assets/javascripts/blazer/Sortable.js - About 2 hrs to fix

        Function _onDrop has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _onDrop: function (/**Event*/evt) {
              var el = this.el,
                options = this.options;
        
              clearInterval(this._loopId);
        Severity: Major
        Found in app/assets/javascripts/blazer/Sortable.js - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                if (activeGroup && !options.disabled &&
                  (isOwner
                    ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
                    : activeGroup.pull && groupPut && (
                      (activeGroup.name === group.name) || // by Name
          Severity: Critical
          Found in app/assets/javascripts/blazer/Sortable.js - About 2 hrs to fix

            Function Sortable has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              function Sortable(el, options) {
                this.el = el; // root element
                this.options = options = _extend({}, options);
            
            
            
            Severity: Minor
            Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

              Function _onDragStart has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
                    var dataTransfer = evt.dataTransfer,
                      options = this.options;
              
                    this._offUpEvents();
              Severity: Minor
              Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

                Function _onTapStart has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _onTapStart: function (/** Event|TouchEvent */evt) {
                      var _this = this,
                        el = this.el,
                        options = this.options,
                        type = evt.type,
                Severity: Minor
                Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

                  Function _prepareDragStart has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
                        var _this = this,
                          el = _this.el,
                          options = _this.options,
                          ownerDocument = el.ownerDocument,
                  Severity: Minor
                  Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                            if (
                              (tag === '>*' && el.parentNode === ctx) || (
                                (tag === '' || el.nodeName.toUpperCase() == tag) &&
                                (!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
                              )
                    Severity: Major
                    Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                                  else if (floating) {
                                    after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
                                  } else {
                                    after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
                                  }
                      Severity: Major
                      Found in app/assets/javascripts/blazer/Sortable.js - About 1 hr to fix

                        Function _dispatchEvent has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
                        Severity: Major
                        Found in app/assets/javascripts/blazer/Sortable.js - About 50 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                        while (i--) {
                                          touchDragOverListeners[i]({
                                            clientX: touchEvt.clientX,
                                            clientY: touchEvt.clientY,
                                            target: target,
                          Severity: Major
                          Found in app/assets/javascripts/blazer/Sortable.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                          if ((scrollEl.offsetWidth < scrollEl.scrollWidth) ||
                                            (scrollEl.offsetHeight < scrollEl.scrollHeight)
                                          ) {
                                            break;
                                          }
                            Severity: Major
                            Found in app/assets/javascripts/blazer/Sortable.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                          if (moveVector === 1 || moveVector === -1) {
                                            after = (moveVector === 1);
                                          }
                                          else if (floating) {
                                            after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
                              Severity: Major
                              Found in app/assets/javascripts/blazer/Sortable.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            if (after && !nextSibling) {
                                              el.appendChild(dragEl);
                                            } else {
                                              target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
                                            }
                                Severity: Major
                                Found in app/assets/javascripts/blazer/Sortable.js - About 45 mins to fix

                                  Function _onMove has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                    function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
                                  Severity: Minor
                                  Found in app/assets/javascripts/blazer/Sortable.js - About 45 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                            return;
                                    Severity: Major
                                    Found in app/assets/javascripts/blazer/Sortable.js - About 30 mins to fix

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

                                          if (dst && src) {
                                            for (var key in src) {
                                              if (src.hasOwnProperty(key)) {
                                                dst[key] = src[key];
                                              }
                                      Severity: Minor
                                      Found in app/assets/javascripts/blazer/Sortable.js and 1 other location - About 35 mins to fix
                                      app/assets/javascripts/blazer/chartkick.js on lines 1669..1675

                                      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 46.

                                      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