capejs/capejs

View on GitHub
lib/cape/virtual_forms.js

Summary

Maintainability
F
4 days
Test Coverage

Function apply has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

  apply() {
    let forms, i, len, form, formName, tForm, j, elements, elem, elemName, k

    forms = this.component.root.getElementsByTagName('form')

Severity: Minor
Found in lib/cape/virtual_forms.js - About 7 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 compile has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

  compile() {
    let forms, elements, i, j, elem, segments, lastSegment, obj, o, name

    this.realForms = {}
    forms = this.main.component.root.getElementsByTagName('form')
Severity: Minor
Found in lib/cape/virtual_forms.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 val has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

  val(arg1, arg2) {
    let key1, key2, value

    if (typeof arg1 === 'object') {
      for (key1 in arg1) {
Severity: Minor
Found in lib/cape/virtual_forms.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

File virtual_forms.js has 292 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'

let Cape = require('./utilities')

// Cape.VirtualForms
Severity: Minor
Found in lib/cape/virtual_forms.js - About 3 hrs to fix

    Method 'apply' has a complexity of 17.
    Open

      apply() {
    Severity: Minor
    Found in lib/cape/virtual_forms.js by eslint

    Limit Cyclomatic Complexity (complexity)

    Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

    function a(x) {
        if (true) {
            return x; // 1st path
        } else if (false) {
            return x+1; // 2nd path
        } else {
            return 4; // 3rd path
        }
    }

    Rule Details

    This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

    Examples of incorrect code for a maximum of 2:

    /*eslint complexity: ["error", 2]*/
    
    function a(x) {
        if (true) {
            return x;
        } else if (false) {
            return x+1;
        } else {
            return 4; // 3rd path
        }
    }

    Examples of correct code for a maximum of 2:

    /*eslint complexity: ["error", 2]*/
    
    function a(x) {
        if (true) {
            return x;
        } else {
            return 4;
        }
    }

    Options

    Optionally, you may specify a max object property:

    "complexity": ["error", 2]

    is equivalent to

    "complexity": ["error", { "max": 2 }]

    Deprecated: the object property maximum is deprecated. Please use the property max instead.

    When Not To Use It

    If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

    Further Reading

    Related Rules

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

    Method 'compile' has a complexity of 12.
    Open

      compile() {
    Severity: Minor
    Found in lib/cape/virtual_forms.js by eslint

    Limit Cyclomatic Complexity (complexity)

    Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

    function a(x) {
        if (true) {
            return x; // 1st path
        } else if (false) {
            return x+1; // 2nd path
        } else {
            return 4; // 3rd path
        }
    }

    Rule Details

    This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

    Examples of incorrect code for a maximum of 2:

    /*eslint complexity: ["error", 2]*/
    
    function a(x) {
        if (true) {
            return x;
        } else if (false) {
            return x+1;
        } else {
            return 4; // 3rd path
        }
    }

    Examples of correct code for a maximum of 2:

    /*eslint complexity: ["error", 2]*/
    
    function a(x) {
        if (true) {
            return x;
        } else {
            return 4;
        }
    }

    Options

    Optionally, you may specify a max object property:

    "complexity": ["error", 2]

    is equivalent to

    "complexity": ["error", { "max": 2 }]

    Deprecated: the object property maximum is deprecated. Please use the property max instead.

    When Not To Use It

    If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

    Further Reading

    Related Rules

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

    Function setValuesOfNestedFields has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      setValuesOfNestedFields(formName, prefix, obj) {
        let attrName, key, self
    
        for (key in obj) {
          attrName = prefix ? prefix + '/' + key : key
    Severity: Minor
    Found in lib/cape/virtual_forms.js - About 1 hr 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 object2array has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      object2array(obj) {
        let isArray = true, _obj, key, ary = []
    
        _obj = Cape.deepExtend({}, obj)
        for (key in _obj) {
    Severity: Minor
    Found in lib/cape/virtual_forms.js - About 1 hr 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 update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      update(formName, options) {
        let tForm
    
        tForm = this._.tempForms[formName]
        if (tForm === undefined) {
    Severity: Minor
    Found in lib/cape/virtual_forms.js - About 1 hr 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 apply has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      apply() {
        let forms, i, len, form, formName, tForm, j, elements, elem, elemName, k
    
        forms = this.component.root.getElementsByTagName('form')
    
    
    Severity: Minor
    Found in lib/cape/virtual_forms.js - About 1 hr to fix

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

        compile() {
          let forms, elements, i, j, elem, segments, lastSegment, obj, o, name
      
          this.realForms = {}
          forms = this.main.component.root.getElementsByTagName('form')
      Severity: Minor
      Found in lib/cape/virtual_forms.js - About 1 hr to fix

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

          checkedOn(name) {
            let names, formName, attrName, forms, elements, cb, value
        
            names = this._.getNames(name)
            formName = names[0]
        Severity: Minor
        Found in lib/cape/virtual_forms.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

        Avoid deeply nested control flow statements.
        Open

                    if (elem.name.slice(-2) === '[]') {
                      if (!Array.isArray(obj[elem.name])) obj[elem.name] = []
                      if (elem.checked) obj[elem.name].push(elem.value)
                    }
                    else {
        Severity: Major
        Found in lib/cape/virtual_forms.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      for (k = 0; k < tForm[elemName].length; k++) {
                        if (elem.value === tForm[elemName][k]) {
                          elem.checked = true
                          break
                        }
          Severity: Major
          Found in lib/cape/virtual_forms.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if (elem.value !== tForm[elemName])
                        elem.value = tForm[elemName] ? tForm[elemName] : ''
            Severity: Major
            Found in lib/cape/virtual_forms.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        else if (elem.type === 'radio') {
                          if (elem.checked) obj[elem.name] = elem.value
                        }
                        else {
                          obj[elem.name] = elem.value
              Severity: Major
              Found in lib/cape/virtual_forms.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            for (key2 in value) {
                              if (value.hasOwnProperty(key2)) {
                                this._.setValue(key1 + '.' + key2, value[key2])
                              }
                            }
                Severity: Major
                Found in lib/cape/virtual_forms.js - About 45 mins to fix

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

                    getValue(name) {
                      let names, formName, attrName, form, _form
                  
                      names = this.getNames(name)
                      formName = names[0]
                  Severity: Minor
                  Found in lib/cape/virtual_forms.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

                  Don't make functions within a loop.
                  Open

                            obj[key].forEach(function(element, index) {
                  Severity: Minor
                  Found in lib/cape/virtual_forms.js by eslint

                  Disallow Functions in Loops (no-loop-func)

                  Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:

                  for (var i = 0; i < 10; i++) {
                      funcs[i] = function() {
                          return i;
                      };
                  }

                  In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i in the scope.

                  let or const mitigate this problem.

                  /*eslint-env es6*/
                  
                  for (let i = 0; i < 10; i++) {
                      funcs[i] = function() {
                          return i;
                      };
                  }

                  In this case, each function created within the loop returns a different number as expected.

                  Rule Details

                  This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.

                  Examples of incorrect code for this rule:

                  /*eslint no-loop-func: "error"*/
                  /*eslint-env es6*/
                  
                  for (var i=10; i; i--) {
                      (function() { return i; })();
                  }
                  
                  while(i) {
                      var a = function() { return i; };
                      a();
                  }
                  
                  do {
                      function a() { return i; };
                      a();
                  } while (i);
                  
                  let foo = 0;
                  for (let i=10; i; i--) {
                      // Bad, function is referencing block scoped variable in the outer scope.
                      var a = function() { return foo; };
                      a();
                  }

                  Examples of correct code for this rule:

                  /*eslint no-loop-func: "error"*/
                  /*eslint-env es6*/
                  
                  var a = function() {};
                  
                  for (var i=10; i; i--) {
                      a();
                  }
                  
                  for (var i=10; i; i--) {
                      var a = function() {}; // OK, no references to variables in the outer scopes.
                      a();
                  }
                  
                  for (let i=10; i; i--) {
                      var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
                      a();
                  }
                  
                  var foo = 100;
                  for (let i=10; i; i--) {
                      var a = function() { return foo; }; // OK, all references are referring to never modified variables.
                      a();
                  }
                  //... no modifications of foo after this loop ...

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

                  Don't make functions within a loop.
                  Open

                        segments.forEach(segment => {
                  Severity: Minor
                  Found in lib/cape/virtual_forms.js by eslint

                  Disallow Functions in Loops (no-loop-func)

                  Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:

                  for (var i = 0; i < 10; i++) {
                      funcs[i] = function() {
                          return i;
                      };
                  }

                  In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i in the scope.

                  let or const mitigate this problem.

                  /*eslint-env es6*/
                  
                  for (let i = 0; i < 10; i++) {
                      funcs[i] = function() {
                          return i;
                      };
                  }

                  In this case, each function created within the loop returns a different number as expected.

                  Rule Details

                  This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.

                  Examples of incorrect code for this rule:

                  /*eslint no-loop-func: "error"*/
                  /*eslint-env es6*/
                  
                  for (var i=10; i; i--) {
                      (function() { return i; })();
                  }
                  
                  while(i) {
                      var a = function() { return i; };
                      a();
                  }
                  
                  do {
                      function a() { return i; };
                      a();
                  } while (i);
                  
                  let foo = 0;
                  for (let i=10; i; i--) {
                      // Bad, function is referencing block scoped variable in the outer scope.
                      var a = function() { return foo; };
                      a();
                  }

                  Examples of correct code for this rule:

                  /*eslint no-loop-func: "error"*/
                  /*eslint-env es6*/
                  
                  var a = function() {};
                  
                  for (var i=10; i; i--) {
                      a();
                  }
                  
                  for (var i=10; i; i--) {
                      var a = function() {}; // OK, no references to variables in the outer scopes.
                      a();
                  }
                  
                  for (let i=10; i; i--) {
                      var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
                      a();
                  }
                  
                  var foo = 100;
                  for (let i=10; i; i--) {
                      var a = function() { return foo; }; // OK, all references are referring to never modified variables.
                      a();
                  }
                  //... no modifications of foo after this loop ...

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

                  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
                  Open

                      for (key in obj) {
                  Severity: Minor
                  Found in lib/cape/virtual_forms.js by eslint

                  Require Guarding for-in (guard-for-in)

                  Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

                  for (key in foo) {
                      doSomething(key);
                  }

                  Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

                  Rule Details

                  This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

                  Examples of incorrect code for this rule:

                  /*eslint guard-for-in: "error"*/
                  
                  for (key in foo) {
                      doSomething(key);
                  }

                  Examples of correct code for this rule:

                  /*eslint guard-for-in: "error"*/
                  
                  for (key in foo) {
                      if (Object.prototype.hasOwnProperty.call(foo, key)) {
                          doSomething(key);
                      }
                      if ({}.hasOwnProperty.call(foo, key)) {
                          doSomething(key);
                      }
                  }

                  Related Rules

                  • [no-prototype-builtins](no-prototype-builtins.md)

                  Further Reading

                  The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
                  Open

                      for (name in form) {
                  Severity: Minor
                  Found in lib/cape/virtual_forms.js by eslint

                  Require Guarding for-in (guard-for-in)

                  Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

                  for (key in foo) {
                      doSomething(key);
                  }

                  Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

                  Rule Details

                  This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

                  Examples of incorrect code for this rule:

                  /*eslint guard-for-in: "error"*/
                  
                  for (key in foo) {
                      doSomething(key);
                  }

                  Examples of correct code for this rule:

                  /*eslint guard-for-in: "error"*/
                  
                  for (key in foo) {
                      if (Object.prototype.hasOwnProperty.call(foo, key)) {
                          doSomething(key);
                      }
                      if ({}.hasOwnProperty.call(foo, key)) {
                          doSomething(key);
                      }
                  }

                  Related Rules

                  • [no-prototype-builtins](no-prototype-builtins.md)

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status