balderdashy/waterline

View on GitHub
lib/waterline/utils/query/private/normalize-criteria.js

Summary

Maintainability
F
6 days
Test Coverage

Function normalizeCriteria has 411 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function normalizeCriteria(criteria, modelIdentity, orm, meta) {

  // Sanity checks.
  // > These are just some basic, initial usage assertions to help catch
  // > bugs during development of Waterline core.
Severity: Major
Found in lib/waterline/utils/query/private/normalize-criteria.js - About 2 days to fix

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

    module.exports = function normalizeCriteria(criteria, modelIdentity, orm, meta) {
    
      // Sanity checks.
      // > These are just some basic, initial usage assertions to help catch
      // > bugs during development of Waterline core.
    Severity: Minor
    Found in lib/waterline/utils/query/private/normalize-criteria.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

    File normalize-criteria.js has 423 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * Module dependencies
     */
    
    var util = require('util');
    Severity: Minor
    Found in lib/waterline/utils/query/private/normalize-criteria.js - About 6 hrs to fix

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

        if (!_.isUndefined(criteria.max)) {
          throw new Error(
            'The `max` clause is no longer supported in Sails/Waterline.\n'+
            'In previous versions, `max` could be provided in a criteria '+
            'to perform an aggregation query.  But as of Sails v1.0/Waterline v0.13, the '+
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 1 other location - About 1 day to fix
      lib/waterline/utils/query/private/normalize-criteria.js on lines 305..340

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

      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

        if (!_.isUndefined(criteria.min)) {
          throw new Error(
            'The `min` clause is no longer supported in Sails/Waterline.\n'+
            'In previous versions, `min` could be provided in a criteria '+
            'to perform an aggregation query.  But as of Sails v1.0/Waterline v0.13, the '+
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 1 other location - About 1 day to fix
      lib/waterline/utils/query/private/normalize-criteria.js on lines 342..377

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

      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

        try {
          WLModel = getModel(modelIdentity, orm);
        } catch (e) {
          switch (e.code) {
            case 'E_MODEL_NOT_REGISTERED': throw new Error('Consistency violation: '+e.message);
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 1 other location - About 2 hrs to fix
      lib/waterline/utils/query/private/normalize-new-record.js on lines 142..149

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

      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

            default:
              throw new Error('Consistency violation: Encountered unexpected internal error when attempting to normalize/validate a provided `sort` clause:\n```\n'+util.inspect(criteria.sort, {depth:5})+'```\nHere is the error:\n```'+e.stack+'\n```');
      Severity: Minor
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 1 other location - About 50 mins to fix
      lib/waterline/utils/query/forge-stage-two-query.js on lines 658..659

      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

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

          try {
            attrDef = getAttribute(attrNameToOmit, modelIdentity, orm);
          } catch (e){
            switch (e.code) {
              case 'E_ATTR_NOT_REGISTERED':
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 3 other locations - About 50 mins to fix
      lib/waterline/utils/query/private/normalize-constraint.js on lines 147..157
      lib/waterline/utils/query/private/normalize-criteria.js on lines 757..767
      lib/waterline/utils/query/private/normalize-sort-clause.js on lines 306..316

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

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

            try {
              attrDef = getAttribute(attrNameToKeep, modelIdentity, orm);
            } catch (e){
              switch (e.code) {
                case 'E_ATTR_NOT_REGISTERED':
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 3 other locations - About 50 mins to fix
      lib/waterline/utils/query/private/normalize-constraint.js on lines 147..157
      lib/waterline/utils/query/private/normalize-criteria.js on lines 869..879
      lib/waterline/utils/query/private/normalize-sort-clause.js on lines 306..316

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

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

            else if (WLModel.hasSchema === false) {
      
              // Make sure this is at least a valid name for a Waterline attribute.
              if (!isValidAttributeName(attrNameToKeep)) {
                throw flaverr('E_HIGHLY_IRREGULAR', new Error(
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 3 other locations - About 35 mins to fix
      lib/waterline/utils/query/private/normalize-constraint.js on lines 173..184
      lib/waterline/utils/query/private/normalize-criteria.js on lines 893..909
      lib/waterline/utils/query/private/normalize-sort-clause.js on lines 335..347

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

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

          else if (WLModel.hasSchema === false) {
      
            // In this case, we just give up and throw an E_HIGHLY_IRREGULAR error here
            // explaining what's up.
            throw flaverr('E_HIGHLY_IRREGULAR', new Error(
      Severity: Major
      Found in lib/waterline/utils/query/private/normalize-criteria.js and 3 other locations - About 35 mins to fix
      lib/waterline/utils/query/private/normalize-constraint.js on lines 173..184
      lib/waterline/utils/query/private/normalize-criteria.js on lines 782..792
      lib/waterline/utils/query/private/normalize-sort-clause.js on lines 335..347

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

      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