volontariat/voluntary

View on GitHub
app/assets/javascripts/voluntary/lib/sugar.js

Summary

Maintainability
F
2 wks
Test Coverage

File sugar.js has 4177 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 *  Sugar Library edge
 *
 *  Freely distributable and licensed under the MIT-style license.
 *  Copyright (c) 2015 Andrew Plummer
Severity: Major
Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 wk to fix

    Function getExtendedDate has 192 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function getExtendedDate(contextDate, f, localeCode, prefer, forceUTC) {
        // TODO can we split this up into smaller methods?
        var d, relative, baseLocalization, afterCallbacks, loc, set, unit, unitIndex, weekday, num, tmp, weekdayForward;
    
        afterCallbacks = [];
    Severity: Major
    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 7 hrs to fix

      Function setLocalization has 109 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function setLocalization(localeCode, set) {
          var loc;
      
          function initializeField(name) {
            var val = loc[name];
      Severity: Major
      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 4 hrs to fix

        Function buildBase64 has 84 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function buildBase64(key) {
            var encodeAscii, decodeAscii;
        
            function catchEncodingError(fn) {
              return function(str) {
        Severity: Major
        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 3 hrs to fix

          Function buildDateMethods has 78 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function buildDateMethods() {
              extendSimilar(date, DateUnits, function(methods, u, i) {
                var name = u.name, caps = simpleCapitalize(name), since, until;
                u.addMethod = 'add' + caps + 's';
          
          
          Severity: Major
          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 3 hrs to fix

            Function updateDate has 68 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              function updateDate(d, params, reset, advance, prefer, weekdayForward) {
                var specificityIndex;
            
                function getParam(key) {
                  return isDefined(params[key]) ? params[key] : params[key + 's'];
            Severity: Major
            Found in app/assets/javascripts/voluntary/lib/sugar.js - About 2 hrs to fix

              Function runTagReplacements has 60 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function runTagReplacements(str, reg, strip, replacementFn, fullString) {
              
                  var match;
                  var result = '';
                  var currentIndex = 0;
              Severity: Major
              Found in app/assets/javascripts/voluntary/lib/sugar.js - About 2 hrs to fix

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

                    addFormat: function(src, allowsTime, match, variant, iso) {
                      var to = match || [], loc = this, time, timeMarkers, lastIsNumeral;
                
                      src = src.replace(/\s+/g, '[,. ]*');
                      src = src.replace(/\{([^,]+?)\}/g, function(all, k) {
                Severity: Major
                Found in app/assets/javascripts/voluntary/lib/sugar.js - About 2 hrs to fix

                  Function every has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      'every': function(amount, fn) {
                        var increment,
                            precision,
                            dio,
                            unit,
                  Severity: Minor
                  Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                    Function buildStartEndsWith has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      function buildStartEndsWith() {
                        var override = true;
                        try {
                          // If String#startsWith does not exist or alternately if it exists but
                          // correctly throws an error here, then there is no need to flag the
                    Severity: Minor
                    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                      Function buildFormatTokens has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        function buildFormatTokens() {
                      
                          createPaddedToken('f', function(d) {
                            return callDateGet(d, 'Milliseconds');
                          }, true);
                      Severity: Minor
                      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                        Function createLazyFunction has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          function createLazyFunction(fn, ms, immediate, limit) {
                            var queue = [], locked = false, execute, rounded, perExecution, result;
                            ms = ms || 1;
                            limit = limit || Infinity;
                            rounded = ceil(ms);
                        Severity: Minor
                        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                          Function collateStrings has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            function collateStrings(a, b) {
                              var aValue, bValue, aChar, bChar, aEquiv, bEquiv, index = 0, tiebreaker = 0;
                          
                              var sortIgnore      = sugarArray[AlphanumericSortIgnore];
                              var sortIgnoreCase  = sugarArray[AlphanumericSortIgnoreCase];
                          Severity: Minor
                          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                            Function stringify has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              function stringify(thing, stack) {
                                var type = typeof thing, isObject, isArrayLike, klass, value, arr, key, i, len;
                            
                                // Return quickly if string to save cycles
                                if (type === 'string') return thing;
                            Severity: Minor
                            Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

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

                                function mergeObject(target, source, deep, resolve) {
                              
                                  // Will not merge a primitive type.
                                  if (!isObjectType(source)) return target;
                              
                              
                              Severity: Minor
                              Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

                                Function compareDate has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  function compareDate(d, find, localeCode, buffer, forceUTC) {
                                    var p, t, min, max, override, accuracy = 0, loBuffer = 0, hiBuffer = 0;
                                    p = getExtendedDate(null, find, localeCode, null, forceUTC);
                                    if (buffer > 0) {
                                      loBuffer = hiBuffer = buffer;
                                Severity: Minor
                                Found in app/assets/javascripts/voluntary/lib/sugar.js - About 1 hr to fix

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

                                    function defineOnGlobal(klass, name, instance, original, prop, existed, polyfill) {
                                  Severity: Major
                                  Found in app/assets/javascripts/voluntary/lib/sugar.js - About 50 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                  if (set.sign && (tmp = loc.modifiersByName[set.sign])) {
                                                    // Unit and sign, ie "months ago", "weeks from now", etc.
                                                    num *= tmp.value;
                                                  }
                                    Severity: Major
                                    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

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

                                        function arrayFind(arr, f, startIndex, loop, returnIndex, context) {
                                      Severity: Minor
                                      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

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

                                          function abbreviateNumber(num, roundTo, str, mid, limit, bytes) {
                                        Severity: Minor
                                        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                          Avoid deeply nested control flow statements.
                                          Open

                                                        if (set.shift && !set.unit) {
                                                          set.unit = loc.units[5];
                                                        }
                                          Severity: Major
                                          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                            Avoid deeply nested control flow statements.
                                            Open

                                                          if (set.shift && !set.unit) set.unit = loc.units[7];
                                            Severity: Major
                                            Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                              Avoid deeply nested control flow statements.
                                              Open

                                                            if (set.shift) {
                                                              // Shift and unit, ie "next month", "last week", etc.
                                                              num *= (tmp = loc.modifiersByName[set.shift]) ? tmp.value : 0;
                                                            }
                                              Severity: Major
                                              Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                                Avoid deeply nested control flow statements.
                                                Open

                                                              if (set.num && set.month) {
                                                                // If we have "the 2nd Tuesday of June", then pass the "weekdayForward" flag
                                                                // along to updateDate so that the date does not accidentally traverse into
                                                                // the previous month. This needs to be independent of the "prefer" flag because
                                                                // we are only ensuring that the weekday is in the future, not the entire date.
                                                Severity: Major
                                                Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

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

                                                    function updateDate(d, params, reset, advance, prefer, weekdayForward) {
                                                  Severity: Minor
                                                  Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                                    Avoid deeply nested control flow statements.
                                                    Open

                                                                  if (isDefined(set.weekday)) {
                                                                    // Units can be with non-relative dates, set here. ie "the day after monday"
                                                                    setDate(d, [{ weekday: set.weekday }, true]);
                                                                    delete set.weekday;
                                                                  }
                                                    Severity: Major
                                                    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

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

                                                        function extendSimilar(klass, set, fn, instance, polyfill, override) {
                                                      Severity: Minor
                                                      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                                        Avoid deeply nested control flow statements.
                                                        Open

                                                                      if (set.offsetSign === '-') {
                                                                        set.offsetMinutes *= -1;
                                                                      }
                                                        Severity: Major
                                                        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 45 mins to fix

                                                          Consider simplifying this complex logical expression.
                                                          Open

                                                                if (obj.start && obj.end) {
                                                                  return obj.start >= this.start && obj.start <= this.end &&
                                                                         obj.end   >= this.start && obj.end   <= this.end;
                                                                } else {
                                                                  return obj >= this.start && obj <= this.end;
                                                          Severity: Major
                                                          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 40 mins to fix

                                                            Function createDate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                            Open

                                                              function createDate(contextDate, f, localeCode, prefer, forceUTC) {
                                                            Severity: Minor
                                                            Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                              Function entryAtIndex has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                              Open

                                                                function entryAtIndex(obj, length, index, overshoot, isString) {
                                                              Severity: Minor
                                                              Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                Function truncateString has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                Open

                                                                  function truncateString(str, length, from, ellipsis, split) {
                                                                Severity: Minor
                                                                Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                  Function getExtendedDate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                  Open

                                                                    function getExtendedDate(contextDate, f, localeCode, prefer, forceUTC) {
                                                                  Severity: Minor
                                                                  Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                    Function setDelay has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                    Open

                                                                      function setDelay(fn, ms, after, scope, args) {
                                                                    Severity: Minor
                                                                    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                      Function runTagReplacements has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                      Open

                                                                        function runTagReplacements(str, reg, strip, replacementFn, fullString) {
                                                                      Severity: Minor
                                                                      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                        Function addFormat has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                        Open

                                                                            addFormat: function(src, allowsTime, match, variant, iso) {
                                                                        Severity: Minor
                                                                        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                          Function extend has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                          Open

                                                                            function extend(klass, methods, instance, polyfill, override) {
                                                                          Severity: Minor
                                                                          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                            Function compareDate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                            Open

                                                                              function compareDate(d, find, localeCode, buffer, forceUTC) {
                                                                            Severity: Minor
                                                                            Found in app/assets/javascripts/voluntary/lib/sugar.js - About 35 mins to fix

                                                                              Avoid too many return statements within this function.
                                                                              Open

                                                                                  return defaultMatcher(f);
                                                                              Severity: Major
                                                                              Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                Avoid too many return statements within this function.
                                                                                Open

                                                                                      return -1;
                                                                                Severity: Major
                                                                                Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                  Avoid too many return statements within this function.
                                                                                  Open

                                                                                        return 0;
                                                                                  Severity: Major
                                                                                  Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                    Avoid too many return statements within this function.
                                                                                    Open

                                                                                            return 0;
                                                                                    Severity: Major
                                                                                    Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                      Avoid too many return statements within this function.
                                                                                      Open

                                                                                            return fuzzyMatcher(f, isObject);
                                                                                      Severity: Major
                                                                                      Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                        Avoid too many return statements within this function.
                                                                                        Open

                                                                                              return el[map];
                                                                                        Severity: Major
                                                                                        Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

                                                                                          Avoid too many return statements within this function.
                                                                                          Open

                                                                                                return 1;
                                                                                          Severity: Major
                                                                                          Found in app/assets/javascripts/voluntary/lib/sugar.js - About 30 mins to fix

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

                                                                                                  return new Range(
                                                                                                    this.start > range.start ? this.start : range.start,
                                                                                                    this.end   < range.end   ? this.end   : range.end
                                                                                                  );
                                                                                            Severity: Major
                                                                                            Found in app/assets/javascripts/voluntary/lib/sugar.js and 1 other location - About 1 hr to fix
                                                                                            app/assets/javascripts/voluntary/lib/sugar.js on lines 5437..5440

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

                                                                                            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

                                                                                                  return new Range(
                                                                                                    this.start < range.start ? this.start : range.start,
                                                                                                    this.end   > range.end   ? this.end   : range.end
                                                                                                  );
                                                                                            Severity: Major
                                                                                            Found in app/assets/javascripts/voluntary/lib/sugar.js and 1 other location - About 1 hr to fix
                                                                                            app/assets/javascripts/voluntary/lib/sugar.js on lines 5457..5460

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

                                                                                            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