codenautas/best-globals

View on GitHub
best-globals.js

Summary

Maintainability
F
6 days
Test Coverage

File best-globals.js has 983 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

(function codenautasModuleDefinition(root, name, factory) {
    /* global define */
    /* istanbul ignore next */
Severity: Major
Found in best-globals.js - About 2 days to fix

    Function TimeInterval has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    bestGlobals.TimeInterval = function TimeInterval(timePack){
        /* istanbul ignore next */
        if(typeof timePack === 'number'){
            timePack={ms:timePack};
            console.log('|-----------------------------|');
    Severity: Major
    Found in best-globals.js - About 3 hrs to fix

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

      bestGlobals.registerJson4All = function registerJson4All(JSON4all){
          JSON4all.addType(Date, {
              specialTag: function specialTag(value){
                  if(value.isRealDate){
                      return 'date';
      Severity: Major
      Found in best-globals.js - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if(h<0 || m<0 || s<0 || ms<0 || h>23 || m>59 || s>59 || ms>999 || micros<0 || micros>999) { return false; }
        Severity: Critical
        Found in best-globals.js - About 2 hrs to fix

          Function has too many statements (102). Maximum allowed is 100.
          Open

          })(/*jshint -W040 */this, 'bestGlobals', function() {
          Severity: Minor
          Found in best-globals.js by eslint

          enforce a maximum number of statements allowed in function blocks (max-statements)

          The max-statements rule allows you to specify the maximum number of statements allowed in a function.

          function foo() {
            var bar = 1; // one statement
            var baz = 2; // two statements
            var qux = 3; // three statements
          }

          Rule Details

          This rule enforces a maximum number of statements allowed in function blocks.

          Options

          This rule has a number or object option:

          • "max" (default 10) enforces a maximum number of statements allows in function blocks

          Deprecated: The object property maximum is deprecated; please use the object property max instead.

          This rule has an object option:

          • "ignoreTopLevelFunctions": true ignores top-level functions

          max

          Examples of incorrect code for this rule with the default { "max": 10 } option:

          /*eslint max-statements: ["error", 10]*/
          /*eslint-env es6*/
          
          function foo() {
            var foo1 = 1;
            var foo2 = 2;
            var foo3 = 3;
            var foo4 = 4;
            var foo5 = 5;
            var foo6 = 6;
            var foo7 = 7;
            var foo8 = 8;
            var foo9 = 9;
            var foo10 = 10;
          
            var foo11 = 11; // Too many.
          }
          
          let foo = () => {
            var foo1 = 1;
            var foo2 = 2;
            var foo3 = 3;
            var foo4 = 4;
            var foo5 = 5;
            var foo6 = 6;
            var foo7 = 7;
            var foo8 = 8;
            var foo9 = 9;
            var foo10 = 10;
          
            var foo11 = 11; // Too many.
          };

          Examples of correct code for this rule with the default { "max": 10 } option:

          /*eslint max-statements: ["error", 10]*/
          /*eslint-env es6*/
          
          function foo() {
            var foo1 = 1;
            var foo2 = 2;
            var foo3 = 3;
            var foo4 = 4;
            var foo5 = 5;
            var foo6 = 6;
            var foo7 = 7;
            var foo8 = 8;
            var foo9 = 9;
            var foo10 = 10;
            return function () {
          
              // The number of statements in the inner function does not count toward the
              // statement maximum.
          
              return 42;
            };
          }
          
          let foo = () => {
            var foo1 = 1;
            var foo2 = 2;
            var foo3 = 3;
            var foo4 = 4;
            var foo5 = 5;
            var foo6 = 6;
            var foo7 = 7;
            var foo8 = 8;
            var foo9 = 9;
            var foo10 = 10;
            return function () {
          
              // The number of statements in the inner function does not count toward the
              // statement maximum.
          
              return 42;
            };
          }

          ignoreTopLevelFunctions

          Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true } options:

          /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
          
          function foo() {
            var foo1 = 1;
            var foo2 = 2;
            var foo3 = 3;
            var foo4 = 4;
            var foo5 = 5;
            var foo6 = 6;
            var foo7 = 7;
            var foo8 = 8;
            var foo9 = 9;
            var foo10 = 10;
            var foo11 = 11;
          }

          Related Rules

          • [complexity](complexity.md)
          • [max-depth](max-depth.md)
          • [max-len](max-len.md)
          • [max-nested-callbacks](max-nested-callbacks.md)
          • [max-params](max-params.md) Source: http://eslint.org/docs/rules/

          Function forOrder has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          bestGlobals.forOrder = function forOrder(text){
              if(text==null){
                  return 'zzz(null)';
              }
              if(text instanceof Date){
          Severity: Minor
          Found in best-globals.js - About 1 hr to fix

            Function changing has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function changing(original, changes){
                var opts = changing.retreiveOptions(arguments);
                if (changes instanceof ChangingWithSpecial) {
                    return changes.change(original);
                }
            Severity: Minor
            Found in best-globals.js - About 1 hr to fix

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

                  this.toHms = function toHms(omitSeconds, withDays, omitLeftCeros, omitHourCero, omitFirstLeftCero) {
                      var leftCero = omitLeftCeros?'':'0';
                      var tm = this.timeInterval.ms;
                      var prefix = (tm<0?'-':'');
                      var tdiff = [];
              Severity: Minor
              Found in best-globals.js - About 1 hr to fix

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

                bestGlobals.serie = function serie(NorFirstOrObject, NifNoFirst){
                    var last;
                    var first;
                    var step;
                    var n; 
                Severity: Minor
                Found in best-globals.js - About 1 hr to fix

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

                  bestGlobals.dateForceIfNecesary = function dateForceIfNecesary(dt, strict) {
                      if(!strict){
                          if(dt==null) return null;
                      }
                      if(dt.ms == null && ! bestGlobals.date.isOK(dt)) { throw new Error('invalid date'); }
                  Severity: Minor
                  Found in best-globals.js - About 1 hr to fix

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

                    bestGlobals.compareForOrder = function compareForOrder(sortColumns){
                        var thisModule = this || bestGlobals;
                        return function forOrderComparator(row1,row2){
                            var column;
                            var i=0;
                    Severity: Minor
                    Found in best-globals.js - About 1 hr to fix

                      Function ymdHmsMm has 8 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      bestGlobals.datetime.ymdHmsMm = function ymdHmsMm(year, month, day, hour, minutes, seconds, ms, micros){
                      Severity: Major
                      Found in best-globals.js - About 1 hr to fix

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

                        bestGlobals.datetime.ymdHmsM = function ymdHmsM(y, m, d, hh, mm, ss, ms) {
                        Severity: Major
                        Found in best-globals.js - About 50 mins to fix

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

                          bestGlobals.datetime.ymdHms = function ymdHms(y, m, d, hh, mm, ss) {
                          Severity: Minor
                          Found in best-globals.js - About 45 mins to fix

                            Consider simplifying this complex logical expression.
                            Open

                                if(match){
                                    var integerParts={};
                                    integerParts.year    = parseInt(match[2],10)
                                    integerParts.month   = parseInt(match[4],10)
                                    integerParts.day     = parseInt(match[7],10)
                            Severity: Major
                            Found in best-globals.js - About 40 mins to fix

                              Consider simplifying this complex logical expression.
                              Open

                                  if(original===null ||
                                      !bestGlobals.isPlainObject(original) &&
                                          !(original instanceof Error) &&
                                          (!opts.mostlyPlain || typeof original != "object" || !bestGlobals.isPlainObject(changes))
                                       // && !bestGlobals.changing
                              Severity: Major
                              Found in best-globals.js - About 40 mins to fix

                                Consider simplifying this complex logical expression.
                                Open

                                    if(m){
                                        var sign=m[1]=='-'?-1:1;
                                        return bestGlobals.timeInterval({
                                            ms     : m[8]*sign||0,
                                            seconds: m[7]*sign||0,
                                Severity: Major
                                Found in best-globals.js - About 40 mins to fix

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

                                  bestGlobals.Datetime.isValidTime = function isValidTime(h, m, s, ms, micros) {
                                  Severity: Minor
                                  Found in best-globals.js - About 35 mins to fix

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

                                        this.toHms = function toHms(omitSeconds, withDays, omitLeftCeros, omitHourCero, omitFirstLeftCero) {
                                    Severity: Minor
                                    Found in best-globals.js - About 35 mins to fix

                                      Function codenautasModuleDefinition has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      (function codenautasModuleDefinition(root, name, factory) {
                                          /* global define */
                                          /* istanbul ignore next */
                                          if(typeof root.globalModuleName !== 'string'){
                                              root.globalModuleName = name;
                                      Severity: Minor
                                      Found in best-globals.js - About 35 mins to fix

                                      Cognitive Complexity

                                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                      A method's cognitive complexity is based on a few simple rules:

                                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                      • Code is considered more complex for each "break in the linear flow of the code"
                                      • Code is considered more complex when "flow breaking structures are nested"

                                      Further reading

                                      Avoid too many return statements within this function.
                                      Open

                                              return 0;
                                      Severity: Major
                                      Found in best-globals.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    if(!(name in b) || !bestGlobals.sameValue(a[name],b[name])) return false;
                                        Severity: Major
                                        Found in best-globals.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                  return bestGlobals.sameValues(a,b,"right") && bestGlobals.sameValues(a,b,"left");
                                          Severity: Major
                                          Found in best-globals.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                    return true;
                                            Severity: Major
                                            Found in best-globals.js - About 30 mins to fix

                                              Wrap an immediate function invocation in parentheses.
                                              Open

                                                          last = 'to' in NorFirstOrObject ? NorFirstOrObject.to : function (){ throw new Error('serie lack of "from" or "to"') }();
                                              Severity: Minor
                                              Found in best-globals.js by eslint

                                              Require IIFEs to be Wrapped (wrap-iife)

                                              You can immediately invoke function expressions, but not function declarations. A common technique to create an immediately-invoked function expression (IIFE) is to wrap a function declaration in parentheses. The opening parentheses causes the contained function to be parsed as an expression, rather than a declaration.

                                              // function expression could be unwrapped
                                              var x = function () { return { y: 1 };}();
                                              
                                              // function declaration must be wrapped
                                              function () { /* side effects */ }(); // SyntaxError

                                              Rule Details

                                              This rule requires all immediately-invoked function expressions to be wrapped in parentheses.

                                              Options

                                              This rule has two options, a string option and an object option.

                                              String option:

                                              • "outside" enforces always wrapping the call expression. The default is "outside".
                                              • "inside" enforces always wrapping the function expression.
                                              • "any" enforces always wrapping, but allows either style.

                                              Object option:

                                              • "functionPrototypeMethods": true additionally enforces wrapping function expressions invoked using .call and .apply. The default is false.

                                              outside

                                              Examples of incorrect code for the default "outside" option:

                                              /*eslint wrap-iife: ["error", "outside"]*/
                                              
                                              var x = function () { return { y: 1 };}(); // unwrapped
                                              var x = (function () { return { y: 1 };})(); // wrapped function expression

                                              Examples of correct code for the default "outside" option:

                                              /*eslint wrap-iife: ["error", "outside"]*/
                                              
                                              var x = (function () { return { y: 1 };}()); // wrapped call expression

                                              inside

                                              Examples of incorrect code for the "inside" option:

                                              /*eslint wrap-iife: ["error", "inside"]*/
                                              
                                              var x = function () { return { y: 1 };}(); // unwrapped
                                              var x = (function () { return { y: 1 };}()); // wrapped call expression

                                              Examples of correct code for the "inside" option:

                                              /*eslint wrap-iife: ["error", "inside"]*/
                                              
                                              var x = (function () { return { y: 1 };})(); // wrapped function expression

                                              any

                                              Examples of incorrect code for the "any" option:

                                              /*eslint wrap-iife: ["error", "any"]*/
                                              
                                              var x = function () { return { y: 1 };}(); // unwrapped

                                              Examples of correct code for the "any" option:

                                              /*eslint wrap-iife: ["error", "any"]*/
                                              
                                              var x = (function () { return { y: 1 };}()); // wrapped call expression
                                              var x = (function () { return { y: 1 };})(); // wrapped function expression

                                              functionPrototypeMethods

                                              Examples of incorrect code for this rule with the "inside", { "functionPrototypeMethods": true } options:

                                              /* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */
                                              
                                              var x = function(){ foo(); }()
                                              var x = (function(){ foo(); }())
                                              var x = function(){ foo(); }.call(bar)
                                              var x = (function(){ foo(); }.call(bar))

                                              Examples of correct code for this rule with the "inside", { "functionPrototypeMethods": true } options:

                                              /* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */
                                              
                                              var x = (function(){ foo(); })()
                                              var x = (function(){ foo(); }).call(bar)

                                              Source: http://eslint.org/docs/rules/

                                              Unnecessary semicolon.
                                              Open

                                              };
                                              Severity: Minor
                                              Found in best-globals.js by eslint

                                              disallow unnecessary semicolons (no-extra-semi)

                                              Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.

                                              Rule Details

                                              This rule disallows unnecessary semicolons.

                                              Examples of incorrect code for this rule:

                                              /*eslint no-extra-semi: "error"*/
                                              
                                              var x = 5;;
                                              
                                              function foo() {
                                                  // code
                                              };

                                              Examples of correct code for this rule:

                                              /*eslint no-extra-semi: "error"*/
                                              
                                              var x = 5;
                                              
                                              var foo = function() {
                                                  // code
                                              };

                                              When Not To Use It

                                              If you intentionally use extra semicolons then you can disable this rule.

                                              Related Rules

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

                                                  var prune = function(what){
                                                      if(str.substr(str.length-what.length)==what){
                                                          str=str.substr(0,str.length-what.length);
                                                          return true;
                                                      }
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 2 hrs to fix
                                              best-globals.js on lines 483..489

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

                                              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

                                                  var prune = function(what){
                                                      if(str.substr(str.length-what.length)==what){
                                                          str=str.substr(0,str.length-what.length);
                                                          return true;
                                                      }
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 2 hrs to fix
                                              best-globals.js on lines 505..511

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

                                              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

                                                      deserialize: function deserialize(plainValue){
                                                          var ok = /^\d{4}-\d\d-\d\d \d\d:\d\d(:\d\d(.\d+)?)?$/.test(plainValue);
                                                          var value = ok && bestGlobals.datetime.iso(plainValue) || null;
                                                          return {ok, value};
                                                      },
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 1 hr to fix
                                              best-globals.js on lines 894..898

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

                                              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

                                                      deserialize: function deserialize(plainValue){
                                                          var ok = /^\d{4}-\d\d-\d\d$/.test(plainValue);
                                                          var value = ok && bestGlobals.date.iso(plainValue) || null;
                                                          return {ok, value};
                                                      },
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 1 hr to fix
                                              best-globals.js on lines 911..915

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

                                              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

                                              bestGlobals.coalesce.throwErrorIfUndefined=function throwErrorIfUndefined(message){
                                                  if(this === bestGlobals.coalesce){
                                                      return new bestGlobals.coalesce.throwErrorIfUndefined(message);
                                                  }else{
                                                      this.message=message;
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 1 hr to fix
                                              best-globals.js on lines 50..56

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

                                              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

                                              bestGlobals.coalesce.throwError=function throwError(message){
                                                  if(this === bestGlobals.coalesce){
                                                      return new bestGlobals.coalesce.throwError(message);
                                                  }else{
                                                      this.message=message;
                                              Severity: Major
                                              Found in best-globals.js and 1 other location - About 1 hr to fix
                                              best-globals.js on lines 58..64

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

                                              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