TechnologyAdvice/obey

View on GitHub
src/lib/validators.js

Summary

Maintainability
F
5 days
Test Coverage

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

  requiredIfNot: function(def, value, key, errors, data) {
Severity: Minor
Found in src/lib/validators.js - About 35 mins to fix

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

      equalTo: function(def, value, key, errors, data) {
    Severity: Minor
    Found in src/lib/validators.js - About 35 mins to fix

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

        requireIfNot: function(def, value, key, errors, data) {
      Severity: Minor
      Found in src/lib/validators.js - About 35 mins to fix

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

          requiredIf: function(def, value, key, errors, data) {
        Severity: Minor
        Found in src/lib/validators.js - About 35 mins to fix

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

            requireIf: function(def, value, key, errors, data) {
          Severity: Minor
          Found in src/lib/validators.js - About 35 mins to fix

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

              allow: function(def, value, key, errors) {
                const type = 'allow'
                const sub = typeof def.allow === 'object' && !Array.isArray(def.allow) ? Object.keys(def.allow) : def.allow
                const subIsArray = Array.isArray(sub)
                if ((subIsArray && sub.indexOf(value) === -1) || (!subIsArray && sub !== value)) {
            Severity: Minor
            Found in src/lib/validators.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

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

              requiredIf: function(def, value, key, errors, data) {
                const type = 'requiredIf'
                const sub = def.requiredIf
                if (typeof sub === 'object') {
                  const field = Object.keys(sub)[0]
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 day to fix
            src/lib/validators.js on lines 122..138

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

            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

              requiredIfNot: function(def, value, key, errors, data) {
                const type = 'requiredIfNot'
                const sub = def.requiredIfNot
                if (typeof sub === 'object') {
                  const field = Object.keys(sub)[0]
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 day to fix
            src/lib/validators.js on lines 86..102

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

            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

              max: function(def, value, key, errors) {
                const type = 'max'
                const sub = def.max
                if ((Array.isArray(value) || typeof value === 'string') && value.length > def.max) {
                  errors.push({ type, sub, key, value, message: `Length must be less than or equal to ${def.max}` })
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 day to fix
            src/lib/validators.js on lines 49..57

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

            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

              min: function(def, value, key, errors) {
                const type = 'min'
                const sub = def.min
                if ((Array.isArray(value) || typeof value === 'string') && value.length < def.min) {
                  errors.push({ type, sub, key, value, message: `Length must be greater than or equal to ${def.min}` })
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 day to fix
            src/lib/validators.js on lines 67..75

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

            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

              requireIf: function(def, value, key, errors, data) {
                console.log('-----\nObey Warning: `requireIf` should be `requiredIf`\n-----')
                def.requiredIf = def.requireIf
                delete def.requireIf
                validators.requiredIf(def, value, key, errors, data)
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 hr to fix
            src/lib/validators.js on lines 142..147

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

            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

              requireIfNot: function(def, value, key, errors, data) {
                console.log('-----\nObey Warning: `requireIfNot` should be `requiredIfNot`\n-----')
                def.requiredIfNot = def.requireIfNot
                delete def.requireIfNot
                validators.requiredIfNot(def, value, key, errors, data)
            Severity: Major
            Found in src/lib/validators.js and 1 other location - About 1 hr to fix
            src/lib/validators.js on lines 106..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 67.

            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