mangroveorg/datawinners

View on GitHub
datawinners/media/javascript/Knockout-Validation/Src/api.js

Summary

Maintainability
F
1 wk
Test Coverage

Function api has a Cognitive Complexity of 132 (exceeds 5 allowed). Consider refactoring.
Open

var api = (function () {

    var isInitialized = 0,
        configuration = ko.validation.configuration,
        utils = ko.validation.utils;
Severity: Minor
Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 2 days 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 api has 278 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var api = (function () {

    var isInitialized = 0,
        configuration = ko.validation.configuration,
        utils = ko.validation.utils;
Severity: Major
Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 day to fix

    File api.js has 281 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var api = (function () {
    
        var isInitialized = 0,
            configuration = ko.validation.configuration,
            utils = ko.validation.utils;
    Severity: Minor
    Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 2 hrs to fix

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

              group: function group(obj, options) { // array of observables or viewModel
                  options = ko.utils.extend(ko.utils.extend({}, configuration.grouping), options);
      
                  var context = {
                      options: options,
      Severity: Minor
      Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 hr to fix

        Function setRules has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                setRules: function (target, definition) {
                    var setRules = function (target, definition) {
                        if (!target || !definition) { return; }
        
                        for (var prop in definition) {
        Severity: Minor
        Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 hr to fix

          Function traverseGraph has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function traverseGraph(obj, context, level) {
                  var objValues = [],
                      val = obj.peek ? obj.peek() : obj;
          
                  if (obj.__kv_traversed === true) { return; }
          Severity: Minor
          Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 hr to fix

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

                        var setRules = function (target, definition) {
                            if (!target || !definition) { return; }
            
                            for (var prop in definition) {
                                if (!definition.hasOwnProperty(prop)) { continue; }
            Severity: Minor
            Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 hr to fix

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

                      parseInputValidationAttributes: function (element, valueAccessor) {
                          ko.utils.arrayForEach(ko.validation.configuration.html5Attributes, function (attr) {
                              if (utils.hasAttribute(element, attr)) {
              
                                  var params = element.getAttribute(attr) || true;
              Severity: Minor
              Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 1 hr to fix

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

                            ko.bindingHandlers[handlerName].init = function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                Severity: Minor
                Found in datawinners/media/javascript/Knockout-Validation/Src/api.js - About 35 mins to fix

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

                      function traverseGraph(obj, context, level) {
                          var objValues = [],
                              val = obj.peek ? obj.peek() : obj;
                  
                          if (obj.__kv_traversed === true) { return; }
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 2 days to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 226..274

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

                  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

                              if (options.observable) {
                                  runTraversal(obj, context);
                  
                                  result = ko.computed(function () {
                                      context.graphMonitor(); //register dependency
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 3 hrs to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 338..354

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

                  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

                          makeBindingHandlerValidatable: function (handlerName) {
                              var init = ko.bindingHandlers[handlerName].init;
                  
                              ko.bindingHandlers[handlerName].init = function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                  
                  
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 3 hrs to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 574..583

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

                  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

                                      if (attr === 'min' || attr === 'max')
                                      {
                                          // If we're validating based on the min and max attributes, we'll
                                          // need to know what the 'type' attribute is set to
                                          var typeAttr = element.getAttribute('type');
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 2 hrs to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 502..515

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

                  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

                                      if (unwrappedTargetValue && utils.isArray(unwrappedTargetValue)) {
                                          for (var i = 0; i < unwrappedTargetValue.length; i++) {
                                              setRules(unwrappedTargetValue[i], nonRules);
                                          }
                                          //otherwise, just apply to this property
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 2 hrs to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 617..624

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

                  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

                          insertValidationMessage: function (element) {
                              var span = document.createElement('SPAN');
                              span.className = utils.getConfigOptions(element).errorMessageClass;
                              utils.insertAfter(element, span);
                              return span;
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 1 hr to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 487..492

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

                  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

                          addRule: function (observable, rule) {
                              observable.extend({ validatable: true });
                  
                              //push a Rule Context to the observables local array of Rule Contexts
                              observable.rules.push(rule);
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 1 hr to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 402..408

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

                  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

                                      return ko.validation.addRule(observable, {
                                          rule: ruleName,
                                          message: params.message,
                                          params: utils.isEmptyVal(params.params) ? true : params.params,
                                          condition: params.onlyIf
                  Severity: Minor
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 55 mins to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 457..462

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

                  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

                                  if (ctx.rule === "pattern") {
                                      if (ctx.params instanceof RegExp) {
                                          params = ctx.params.source; // we need the pure string representation of the RegExpr without the //gi stuff
                                      }
                                  }
                  Severity: Minor
                  Found in datawinners/media/javascript/Knockout-Validation/Src/api.js and 1 other location - About 50 mins to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 559..563

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

                  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