trufflesuite/truffle

View on GitHub
packages/debug-utils/index.js

Summary

Maintainability
F
6 days
Test Coverage

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

const OS = require("os");
const debug = require("debug")("debug-utils");
const util = require("util");
const Codec = require("@truffle/codec");
const BN = require("bn.js");
Severity: Major
Found in packages/debug-utils/index.js - About 1 day to fix

    Function formatStacktrace has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

      formatStacktrace: function (stacktrace, indent = 2) {
        //get message or panic code from stacktrace
        const { message, panic, custom } = stacktrace[0];
        //we want to print inner to outer, so first, let's
        //reverse
    Severity: Minor
    Found in packages/debug-utils/index.js - About 6 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 formatStacktrace has 79 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      formatStacktrace: function (stacktrace, indent = 2) {
        //get message or panic code from stacktrace
        const { message, panic, custom } = stacktrace[0];
        //we want to print inner to outer, so first, let's
        //reverse
    Severity: Major
    Found in packages/debug-utils/index.js - About 3 hrs to fix

      Function isUsableCompilation has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        isUsableCompilation: function (compilation) {
          //check #1: is the source order reliable?
          if (compilation.unreliableSourceOrder) {
            debug("unreliable source order");
            return false;
      Severity: Minor
      Found in packages/debug-utils/index.js - About 3 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

      DebugUtils has 26 functions (exceeds 20 allowed). Consider refactoring.
      Open

      var DebugUtils = {
        truffleColors, //make these externally available
      
        //panicCode may be either a number, BN, or decimal string
        panicString: function (panicCode, verbose = false) {
      Severity: Minor
      Found in packages/debug-utils/index.js - About 3 hrs to fix

        Function isUsableCompilation has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          isUsableCompilation: function (compilation) {
            //check #1: is the source order reliable?
            if (compilation.unreliableSourceOrder) {
              debug("unreliable source order");
              return false;
        Severity: Major
        Found in packages/debug-utils/index.js - About 2 hrs to fix

          Function formatCalldata has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            formatCalldata: function (calldata) {
              //takes a Uint8Array
              let selector = calldata.slice(0, Codec.Evm.Utils.SELECTOR_SIZE);
              let words = [];
              for (
          Severity: Minor
          Found in packages/debug-utils/index.js - About 1 hr to fix

            Function formatRangeLines has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              formatRangeLines: function (
                source,
                range,
                uncolorizedSource,
                contextBefore = 2,
            Severity: Minor
            Found in packages/debug-utils/index.js - About 1 hr to fix

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

                formatHelp: function (lastCommand = "n") {
                  var prefix = [
                    "Commands:",
                    truffleColors.mint("(enter)") +
                      " last command entered (" +
              Severity: Minor
              Found in packages/debug-utils/index.js - About 1 hr to fix

                Function tabsToSpaces has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  tabsToSpaces: function (inputLine, tabLength = DEFAULT_TAB_WIDTH) {
                    //note: I'm going to assume for these purposes that everything is
                    //basically ASCII and I don't have to worry about astral planes or
                    //grapheme clusters.  Sorry. :-/
                    let line = "";
                Severity: Minor
                Found in packages/debug-utils/index.js - About 55 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

                Function formatLinePointer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  formatLinePointer: function (
                    line,
                    startCol,
                    endCol,
                    padding,
                Severity: Minor
                Found in packages/debug-utils/index.js - About 55 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

                Function panicString has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  panicString: function (panicCode, verbose = false) {
                    const unknownString = "Unknown panic";
                    const verboseUnknownString = "A panic occurred of unrecognized type.";
                    if (BN.isBN(panicCode)) {
                      try {
                Severity: Minor
                Found in packages/debug-utils/index.js - About 55 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

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

                    line,
                    startCol,
                    endCol,
                    padding,
                    tabLength = DEFAULT_TAB_WIDTH
                Severity: Minor
                Found in packages/debug-utils/index.js - About 35 mins to fix

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

                      source,
                      range,
                      uncolorizedSource,
                      contextBefore = 2,
                      contextAfter = 0
                  Severity: Minor
                  Found in packages/debug-utils/index.js - About 35 mins to fix

                    Function formatStorage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      formatStorage: function (storage) {
                        //storage here is an object mapping hex words to hex words (no 0x)
                    
                        //first: sort the keys (slice to clone as sort is in-place)
                        //note: we can use the default sort here; it will do the righ thing
                    Severity: Minor
                    Found in packages/debug-utils/index.js - About 25 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

                    Function formatBreakpointLocation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      formatBreakpointLocation: function (
                        breakpoint,
                        here,
                        currentSourceId,
                        sourceNames
                    Severity: Minor
                    Found in packages/debug-utils/index.js - About 25 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

                    Function formatAffectedInstances has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      formatAffectedInstances: function (instances) {
                        var hasAllSource = true;
                    
                        var lines = Object.keys(instances).map(function (address) {
                          var instance = instances[address];
                    Severity: Minor
                    Found in packages/debug-utils/index.js - About 25 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

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

                    const shortCommandReference = {
                      "o": "step over",
                      "i": "step into",
                      "u": "step out",
                      "n": "step next",
                    Severity: Major
                    Found in packages/debug-utils/index.js and 1 other location - About 5 hrs to fix
                    packages/debug-utils/index.js on lines 36..63

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

                    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

                    const commandReference = {
                      "o": "step over",
                      "i": "step line / step into",
                      "u": "step out",
                      "n": "step next",
                    Severity: Major
                    Found in packages/debug-utils/index.js and 1 other location - About 5 hrs to fix
                    packages/debug-utils/index.js on lines 65..92

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

                    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

                    const panicTable = {
                      0x01: "Failed assertion",
                      0x11: "Arithmetic overflow",
                      0x12: "Division by zero",
                      0x21: "Enum value out of bounds",
                    Severity: Minor
                    Found in packages/debug-utils/index.js and 1 other location - About 55 mins to fix
                    packages/debug-utils/index.js on lines 24..34

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

                    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

                    const verbosePanicTable = {
                      0x01: "An assert() check was not satisfied.",
                      0x11: "An arithmetic overflow occurred outside an unchecked { ... } block.",
                      0x12: "A division by zero occurred.",
                      0x21: "An integer was cast to an enum type that cannot hold it.",
                    Severity: Minor
                    Found in packages/debug-utils/index.js and 1 other location - About 55 mins to fix
                    packages/debug-utils/index.js on lines 12..22

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

                    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