mangroveorg/datawinners

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

Summary

Maintainability
F
6 days
Test Coverage

Function minMaxValidatorFactory has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function minMaxValidatorFactory(validatorName) {
    var isMaxValidation = validatorName === "max";

    return function (val, options) {
        if (ko.validation.utils.isEmptyVal(val)) {
Severity: Major
Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 2 hrs to fix

    Avoid too many return statements within this function.
    Open

                        return (!isNaN(val) && parseFloat(val) <= parseFloat(comparisonValue));
    Severity: Major
    Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                          return (!isNaN(val) && parseFloat(val) >= parseFloat(comparisonValue));
      Severity: Major
      Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            return val <= comparisonValue;
        Severity: Major
        Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                              return false;
          Severity: Major
          Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                                return val >= comparisonValue;
            Severity: Major
            Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                  return ((valMatches[1] < comparisonValueMatches[1]) || // older year
                                      // same year, older month
                                      ((valMatches[1] === comparisonValueMatches[1]) && (valMatches[2] <= comparisonValueMatches[2])));
              Severity: Major
              Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return (valMatches[1] > comparisonValueMatches[1]) || // newer year
                                        // same year, newer month
                                        ((valMatches[1] === comparisonValueMatches[1]) && (valMatches[2] >= comparisonValueMatches[2]));
                Severity: Major
                Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js - About 30 mins to fix

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

                          switch (type.toLowerCase()) {
                              case "week":
                                  regex = /^(\d{4})-W(\d{2})$/;
                                  valMatches = val.match(regex);
                                  if (valMatches === null) {
                  Severity: Major
                  Found in datawinners/media/javascript/Knockout-Validation/Src/rules.js and 1 other location - About 2 days to fix
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 705..769

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

                  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

                  ko.validation.rules['required'] = {
                      validator: function (val, required) {
                          var stringTrimRegEx = /^\s+|\s+$/g,
                              testVal;
                  
                  
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 656..677

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

                  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 3 locations. Consider refactoring.
                  Open

                  ko.validation.rules['digit'] = {
                      validator: function (value, validate) {
                          if (!validate) { return true; }
                          return ko.validation.utils.isEmptyVal(value) || (validate && /^\d+$/.test(value));
                      },
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 205..211
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 213..219

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

                  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 3 locations. Consider refactoring.
                  Open

                  ko.validation.rules['dateISO'] = {
                      validator: function (value, validate) {
                          if (!validate) { return true; }
                          return ko.validation.utils.isEmptyVal(value) || (validate && /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value));
                      },
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 213..219
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 221..227

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

                  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 3 locations. Consider refactoring.
                  Open

                  ko.validation.rules['number'] = {
                      validator: function (value, validate) {
                          if (!validate) { return true; }
                          return ko.validation.utils.isEmptyVal(value) || (validate && /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value));
                      },
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 205..211
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 221..227

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

                  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

                  ko.validation.rules['maxLength'] = {
                      validator: function (val, maxLength) {
                          return ko.validation.utils.isEmptyVal(val) || val.length <= maxLength;
                      },
                      message: 'Please enter no more than {0} characters.'
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 150..155

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

                  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

                  ko.validation.rules['minLength'] = {
                      validator: function (val, minLength) {
                          return ko.validation.utils.isEmptyVal(val) || val.length >= minLength;
                      },
                      message: 'Please enter at least {0} characters.'
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 157..162

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

                  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

                  ko.validation.rules['equal'] = {
                      validator: function (val, params) {
                          var otherValue = params;
                          return val === ko.validation.utils.getValue(otherValue);
                      },
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 248..254

                  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

                  ko.validation.rules['notEqual'] = {
                      validator: function (val, params) {
                          var otherValue = params;
                          return val !== ko.validation.utils.getValue(otherValue);
                      },
                  datawinners/media/javascript/Knockout-Validation/Src/rules.js on lines 240..246

                  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

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

                          if (options.typeAttr === undefined) {
                              // This validator is being called from javascript rather than
                              // being bound from markup
                              type = "text";
                              comparisonValue = options;
                  datawinners/media/javascript/Knockout-Validation/Dist/knockout.validation.js on lines 688..696

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

                  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