wonderlic/swagger-validation

View on GitHub

Showing 28 of 28 total issues

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

var validateInt64 = function(param, value) {
  var type = param.format ? param.format : param.type;
  var isRequired = helper.isRequired(param, value);
  if (isRequired) {
    return isRequired;
Severity: Major
Found in lib/validation/parameters/integer.js and 1 other location - About 1 day to fix
lib/validation/parameters/integer.js on lines 82..111

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

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

var validateInteger = function(param, value) {
  var type = param.format ? param.format : param.type;
  var isRequired = helper.isRequired(param, value);
  if (isRequired) {
    return isRequired;
Severity: Major
Found in lib/validation/parameters/integer.js and 1 other location - About 1 day to fix
lib/validation/parameters/integer.js on lines 30..59

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

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

var body = function(param, req, models, validationObj) {
  var value = _.has(req.query, param.name) ? req.query[param.name] : undefined;
  var ret = helper.paramType(param, value, models, param.allowMultiple);
  if (!_.some(ret, function(val) { return val.hasOwnProperty('error'); })) {
    if (validationObj.replaceValues) {
Severity: Major
Found in lib/validation/paramTypes/query.js and 2 other locations - About 6 hrs to fix
lib/validation/paramTypes/header.js on lines 20..29
lib/validation/paramTypes/path.js on lines 20..29

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

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

var body = function(param, req, models, validationObj) {
  var value = _.has(req.params, param.name) ? req.params[param.name] : undefined;
  var ret = helper.paramType(param, value, models, param.allowMultiple);
  if (!_.some(ret, function(val) { return val.hasOwnProperty('error'); })) {
    if (validationObj.replaceValues) {
Severity: Major
Found in lib/validation/paramTypes/path.js and 2 other locations - About 6 hrs to fix
lib/validation/paramTypes/header.js on lines 20..29
lib/validation/paramTypes/query.js on lines 20..29

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

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

var body = function(param, req, models, validationObj) {
  var value = _.has(req.header, param.name) ? req.header[param.name] : undefined;
  var ret = helper.paramType(param, value, models, param.allowMultiple);
  if (!_.some(ret, function(val) { return val.hasOwnProperty('error'); })) {
    if (validationObj.replaceValues) {
Severity: Major
Found in lib/validation/paramTypes/header.js and 2 other locations - About 6 hrs to fix
lib/validation/paramTypes/path.js on lines 20..29
lib/validation/paramTypes/query.js on lines 20..29

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

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

Function validateObject has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var validateObject = function(param, value, models) {
  var isRequired = helper.isRequired(param, value);
  if (isRequired) {
    return isRequired;
  }
Severity: Major
Found in lib/validation/parameters/object.js - About 2 hrs to fix

    Function validate has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var validate = function(param, value, models) {
      var type = param.uniqueItems ? "set" : "array";
      var isRequired = helper.isRequired(param, value);
      if (isRequired) {
        return isRequired;
    Severity: Minor
    Found in lib/validation/parameters/array.js - About 1 hr to fix

      Function validateString has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      var validateString = function(param, value) {
        var isRequired = helper.isRequired(param, value);
        if (isRequired) {
          return isRequired;
        }
      Severity: Minor
      Found in lib/validation/parameters/string.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 func has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          var func = function(param, value) {
            var model = models[param.type];
      
            // it is probably irrelevant to check as a model without properties is pointless, but it is a nice sanity check
            if (model.properties) {
      Severity: Minor
      Found in lib/validation/parameters/object.js - About 1 hr to fix

        Function validateInt64 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        var validateInt64 = function(param, value) {
          var type = param.format ? param.format : param.type;
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
        Severity: Minor
        Found in lib/validation/parameters/integer.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 validateInteger has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        var validateInteger = function(param, value) {
          var type = param.format ? param.format : param.type;
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
        Severity: Minor
        Found in lib/validation/parameters/integer.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 validateNumber has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        var validateNumber = function(param, value) {
          var type = param.format ? param.format : param.type;
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
        Severity: Minor
        Found in lib/validation/parameters/number.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 validate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        var validate = function(param, value, models) {
          var type = param.uniqueItems ? "set" : "array";
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
        Severity: Minor
        Found in lib/validation/parameters/array.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

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

        var validate = function(param, value) {
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
          }
        Severity: Minor
        Found in lib/validation/parameters/file.js and 1 other location - About 55 mins to fix
        lib/validation/parameters/byte.js on lines 19..26

        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

        var validate = function(param, value) {
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
          }
        Severity: Minor
        Found in lib/validation/parameters/byte.js and 1 other location - About 55 mins to fix
        lib/validation/parameters/file.js on lines 19..26

        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

        Function validateObject has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        var validateObject = function(param, value, models) {
          var isRequired = helper.isRequired(param, value);
          if (isRequired) {
            return isRequired;
          }
        Severity: Minor
        Found in lib/validation/parameters/object.js - About 45 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 isRequired has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        function isRequired(param, value) {
          if (_.isUndefined(value) || _.isNull(value) || value === '') {
            var isParamRequired = param.required && !param.defaultValue;
            return isParamRequired
              ? errorReturn("%s is required", param.name)
        Severity: Minor
        Found in lib/validation/parameters/helper.js - About 45 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 validate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        var validate = function(spec, req, models) {
          var ret = [];
          var isSpecObject = Object.prototype.toString.call(spec) === '[object Object]';
          var validationObj = makeValidationObject(isSpecObject ? spec.validation : {});
        
        
        Severity: Minor
        Found in lib/validation/validate.js - About 45 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

        Consider simplifying this complex logical expression.
        Open

          if (req.query === undefined && req.path === undefined && req.body === undefined
            && req.form === undefined && req.header === undefined && req.params === undefined) {
            return paramTypes.object(param, req, models, validationObj);
          }
        Severity: Major
        Found in lib/validation/paramType.js - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

            if (isNaN(val) || !isFinite(val) || _.isArray(value) || _.isBoolean(value) || (_.isString(value) && value.trim() === '')) {
              return helper.errorReturn("%s is not a type of %s", [param.name, type]);
            }
          Severity: Major
          Found in lib/validation/parameters/number.js - About 40 mins to fix
            Severity
            Category
            Status
            Source
            Language