sebastian-software/core

View on GitHub
source/class/core/JSON.js

Summary

Maintainability
F
4 days
Test Coverage

File JSON.js has 329 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
==================================================================================================
  Core - JavaScript Foundation
  Copyright 2010-2012 Zynga Inc.
  Copyright 2012-2014 Sebastian Werner
Severity: Minor
Found in source/class/core/JSON.js - About 3 hrs to fix

    Function lex has 94 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          var lex = function () {
            var source = Source, length = source.length, symbol, value, begin, position, sign;
            while (Index < length) {
              symbol = source.charAt(Index);
              if ("\t\r\n ".indexOf(symbol) > -1) {
    Severity: Major
    Found in source/class/core/JSON.js - About 3 hrs to fix

      Function get has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            var get = function (value) {
              var results, any, key;
              if (value == "$") {
                // Unexpected end of input.
                abort();
      Severity: Major
      Found in source/class/core/JSON.js - About 2 hrs to fix

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

              var serialize = function (property, object, callback, properties, whitespace, indentation, stack)
              {
                var value = object[property], className, date, results, element, index, length, prefix, any, result;
                if ((typeof value == "object" || typeof value == "function") && value)
                {
        Severity: Major
        Found in source/class/core/JSON.js - About 2 hrs to fix

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

                var serialize = function (property, object, callback, properties, whitespace, indentation, stack)
          Severity: Major
          Found in source/class/core/JSON.js - About 50 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (stack[length] === value) {
                          // Cyclic structures cannot be serialized by `JSON.stringify`.
                          throw TypeError();
                        }
            Severity: Major
            Found in source/class/core/JSON.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          for (index = 0, length = filter.length; index < length; value = filter[index++], ((getClass.call(value) == "[object String]" || getClass.call(value) == "[object Number]") && (properties[value] = 1)));
              Severity: Major
              Found in source/class/core/JSON.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if (symbol == "-") {
                              sign = true;
                              symbol = source.charAt(++Index);
                            }
                Severity: Major
                Found in source/class/core/JSON.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if (source.slice(Index, Index + 4) == "true") {
                                Index += 4;
                                return true;
                              } else if (source.slice(Index, Index + 5) == "false") {
                                Index += 5;
                  Severity: Major
                  Found in source/class/core/JSON.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                for (;; any || (any = true)) {
                                  value = lex();
                                  // A closing square bracket marks the end of the array literal.
                                  if (value == "]") {
                                    break;
                    Severity: Major
                    Found in source/class/core/JSON.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  for (length = value.length; length--;) {
                                    update(value, length, callback);
                                  }
                      Severity: Major
                      Found in source/class/core/JSON.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    for (index = 0, length = value.length; index < length; any || (any = true), index++) {
                                      element = serialize(index, value, callback, properties, whitespace, indentation, stack);
                                      results.push(element === undef ? "null" : element);
                                    }
                        Severity: Major
                        Found in source/class/core/JSON.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                    } else if (value == "{") {
                                      // Parses a JSON object, returning a new JavaScript object.
                                      results = {};
                                      for (;; any || (any = true)) {
                                        value = lex();
                          Severity: Major
                          Found in source/class/core/JSON.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        if ((width -= width % 1) > 0) {
                                          for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
                                        }
                            Severity: Major
                            Found in source/class/core/JSON.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                          if (source.charAt(Index) == '"') {
                                            Index++;
                                            // Return the revived string.
                                            return value;
                                          }
                              Severity: Major
                              Found in source/class/core/JSON.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            if (symbol >= "0" && symbol <= "9") {
                                              // Leading zeroes are interpreted as octal literals.
                                              if (symbol == "0" && (symbol = source.charAt(Index + 1), symbol >= "0" && symbol <= "9")) {
                                                // Illegal octal literal.
                                                abort();
                                Severity: Major
                                Found in source/class/core/JSON.js - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                              if (sign) {
                                                abort();
                                              }
                                  Severity: Major
                                  Found in source/class/core/JSON.js - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                              } else if (getClass.call(width) == "[object String]") {
                                                whitespace = width.length <= 10 ? width : width.slice(0, 10);
                                              }
                                    Severity: Major
                                    Found in source/class/core/JSON.js - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                    if (element !== undef) {
                                                      // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
                                                      // is not the empty string, let `member` {quote(property) + ":"}
                                                      // be the concatenation of `member` and the `space` character."
                                                      // The "`space` character" refers to the literal space
                                      Severity: Major
                                      Found in source/class/core/JSON.js - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                    for (value = "@", Index++; Index < length;) {
                                                      symbol = source.charAt(Index);
                                                      if (symbol < " ") {
                                                        // Unescaped ASCII control characters are not permitted.
                                                        abort();
                                        Severity: Major
                                        Found in source/class/core/JSON.js - About 45 mins to fix

                                          Consider simplifying this complex logical expression.
                                          Open

                                                              if (!(symbol >= "0" && symbol <= "9" || symbol >= "a" && symbol <= "f" || symbol >= "A" && symbol <= "F")) {
                                                                // Invalid Unicode escape sequence.
                                                                abort();
                                                              }
                                          Severity: Major
                                          Found in source/class/core/JSON.js - About 40 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                      return result;
                                            Severity: Major
                                            Found in source/class/core/JSON.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                            return false;
                                              Severity: Major
                                              Found in source/class/core/JSON.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                        return "$";
                                                Severity: Major
                                                Found in source/class/core/JSON.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                                return null;
                                                  Severity: Major
                                                  Found in source/class/core/JSON.js - About 30 mins to fix

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

                                                                result = any ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
                                                    Severity: Major
                                                    Found in source/class/core/JSON.js and 1 other location - About 1 hr to fix
                                                    source/class/core/JSON.js on lines 138..138

                                                    Duplicated Code

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

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

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

                                                    Tuning

                                                    This issue has a mass of 67.

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

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

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

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

                                                    Refactorings

                                                    Further Reading

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

                                                                result = any ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
                                                    Severity: Major
                                                    Found in source/class/core/JSON.js and 1 other location - About 1 hr to fix
                                                    source/class/core/JSON.js on lines 156..156

                                                    Duplicated Code

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

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

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

                                                    Tuning

                                                    This issue has a mass of 67.

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

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

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

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

                                                    Refactorings

                                                    Further Reading

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

                                                                  if (any) {
                                                                    if (value == ",") {
                                                                      value = lex();
                                                                      if (value == "]") {
                                                                        // Unexpected trailing `,` in array literal.
                                                    Severity: Major
                                                    Found in source/class/core/JSON.js and 1 other location - About 1 hr to fix
                                                    source/class/core/JSON.js on lines 418..429

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

                                                    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

                                                                  if (any) {
                                                                    if (value == ",") {
                                                                      value = lex();
                                                                      if (value == "}") {
                                                                        // Unexpected trailing `,` in object literal.
                                                    Severity: Major
                                                    Found in source/class/core/JSON.js and 1 other location - About 1 hr to fix
                                                    source/class/core/JSON.js on lines 388..399

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

                                                    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