anywhichway/stringformatter

View on GitHub

Showing 37 of 37 total issues

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

(function(exports) {
    
    // (c) 2007 Steven Levithan <stevenlevithan.com>
    // MIT License matchRecursiveRegExp
    // (c) 2014, 2015 Simon Y. Blackwell <syblackwell@anywhichway.com>
Severity: Major
Found in index.js and 1 other location - About 2 mos to fix
browser/stringformatter.js on lines 2..882

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

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

(function(exports) {
    
    // (c) 2007 Steven Levithan <stevenlevithan.com>
    // MIT License matchRecursiveRegExp
    // (c) 2014, 2015 Simon Y. Blackwell <syblackwell@anywhichway.com>
Severity: Major
Found in browser/stringformatter.js and 1 other location - About 2 mos to fix
index.js on lines 1..881

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

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

Function 1 has a Cognitive Complexity of 698 (exceeds 5 allowed). Consider refactoring.
Open

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(exports) {
    
    // (c) 2007 Steven Levithan <stevenlevithan.com>
    // MIT License matchRecursiveRegExp
Severity: Minor
Found in browser/stringformatter.js - About 2 wks 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

Function 1 has 809 lines of code (exceeds 25 allowed). Consider refactoring.
Open

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(exports) {
    
    // (c) 2007 Steven Levithan <stevenlevithan.com>
    // MIT License matchRecursiveRegExp
Severity: Major
Found in browser/stringformatter.js - About 4 days to fix

    File stringformatter.js has 811 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
    (function(exports) {
        
        // (c) 2007 Steven Levithan <stevenlevithan.com>
        // MIT License matchRecursiveRegExp
    Severity: Major
    Found in browser/stringformatter.js - About 1 day to fix

      File index.js has 809 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      (function(exports) {
          
          // (c) 2007 Steven Levithan <stevenlevithan.com>
          // MIT License matchRecursiveRegExp
          // (c) 2014, 2015 Simon Y. Blackwell <syblackwell@anywhichway.com>
      Severity: Major
      Found in index.js - About 1 day to fix

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

            function StringFormatter() {
                var me = this;
                me.cache = {}; // cache for format strings
                me.gcOn = true;
                me.hits = 0; // number of times format has been called
        Severity: Major
        Found in browser/stringformatter.js - About 3 hrs to fix

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

              function StringFormatter() {
                  var me = this;
                  me.cache = {}; // cache for format strings
                  me.gcOn = true;
                  me.hits = 0; // number of times format has been called
          Severity: Major
          Found in index.js - About 3 hrs to fix

            Function arrayFormatter has 61 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function arrayFormatter(spec,formatter) {
                    function inrange(index) {
                        if(spec.include) {
                            if(spec.include.some(function(range) {
                                if(index===range || (range instanceof Array && index >= range[0] && index <= range[1])) {
            Severity: Major
            Found in index.js - About 2 hrs to fix

              Function arrayFormatter has 61 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function arrayFormatter(spec,formatter) {
                      function inrange(index) {
                          if(spec.include) {
                              if(spec.include.some(function(range) {
                                  if(index===range || (range instanceof Array && index >= range[0] && index <= range[1])) {
              Severity: Major
              Found in browser/stringformatter.js - About 2 hrs to fix

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

                    StringFormatter.prototype.format = function(formatspec /*,vargs*/) {
                        var me = this;
                        var args = Array.prototype.slice.call(arguments,1);
                        // turn format spec into a string, rarely needed unless someone is building format specs on the fly
                        var stringformatter = (formatspec instanceof Object ? JSON.stringify(formatspec) : formatspec);
                Severity: Major
                Found in index.js - About 2 hrs to fix

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

                      StringFormatter.prototype.format = function(formatspec /*,vargs*/) {
                          var me = this;
                          var args = Array.prototype.slice.call(arguments,1);
                          // turn format spec into a string, rarely needed unless someone is building format specs on the fly
                          var stringformatter = (formatspec instanceof Object ? JSON.stringify(formatspec) : formatspec);
                  Severity: Major
                  Found in browser/stringformatter.js - About 2 hrs to fix

                    Function e has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
                    Severity: Minor
                    Found in browser/stringformatter.js - About 2 hrs 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

                    Function number has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                                    number: function(spec,value) {
                                        var result = parseFloat(value), padding = "";
                                        if(result+""==="NaN") {
                                            return (spec["ifNaN"]!==null && spec["ifNaN"]!==undefined ? spec["ifNaN"] : result);
                                        } else if(result===Infinity || result===-Infinity) {
                    Severity: Minor
                    Found in browser/stringformatter.js - About 1 hr to fix

                      Function number has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                      number: function(spec,value) {
                                          var result = parseFloat(value), padding = "";
                                          if(result+""==="NaN") {
                                              return (spec["ifNaN"]!==null && spec["ifNaN"]!==undefined ? spec["ifNaN"] : result);
                                          } else if(result===Infinity || result===-Infinity) {
                      Severity: Minor
                      Found in index.js - About 1 hr to fix

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

                            function objectFormatter(spec,formatter) {
                                function inrange(key) {
                                    if(spec.include) {
                                        return spec.include.indexOf(key)>=0;
                                    }
                        Severity: Minor
                        Found in browser/stringformatter.js - About 1 hr to fix

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

                              function objectFormatter(spec,formatter) {
                                  function inrange(key) {
                                      if(spec.include) {
                                          return spec.include.indexOf(key)>=0;
                                      }
                          Severity: Minor
                          Found in index.js - About 1 hr to fix

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

                                DateFormat.prototype.format = function() {
                                    if(!this.spec) {
                                        return this.date.toString();
                                    }
                                    var substitutions = [];
                            Severity: Minor
                            Found in index.js - About 1 hr to fix

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

                                  DateFormat.prototype.format = function() {
                                      if(!this.spec) {
                                          return this.date.toString();
                                      }
                                      var substitutions = [];
                              Severity: Minor
                              Found in browser/stringformatter.js - About 1 hr to fix

                                Function replaceRecursiveRegExp has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    function replaceRecursiveRegExp (str, left, right, flags, subst,keepdelim) {
                                        var    f = flags || "",
                                            g = f.indexOf("g") > -1,
                                            x = new RegExp(left + "|" + right, (!g ? "g" :"") + f),
                                            l = new RegExp(left, f.replace(/g/g, "")),
                                Severity: Minor
                                Found in browser/stringformatter.js - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language