balderdashy/waterline

View on GitHub

Showing 357 of 357 total issues

File waterline.js has 484 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//  ██╗    ██╗ █████╗ ████████╗███████╗██████╗ ██╗     ██╗███╗   ██╗███████╗
//  ██║    ██║██╔══██╗╚══██╔══╝██╔════╝██╔══██╗██║     ██║████╗  ██║██╔════╝
//  ██║ █╗ ██║███████║   ██║   █████╗  ██████╔╝██║     ██║██╔██╗ ██║█████╗
//  ██║███╗██║██╔══██║   ██║   ██╔══╝  ██╔══██╗██║     ██║██║╚██╗██║██╔══╝
//  ╚███╔███╔╝██║  ██║   ██║   ███████╗██║  ██║███████╗██║██║ ╚████║███████╗
Severity: Minor
Found in lib/waterline.js - About 7 hrs 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

    Function addToCollection has 184 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function addToCollection(/* targetRecordIds, collectionAttrName, associatedIds?, explicitCbMaybe?, meta? */) {
    
      // Verify `this` refers to an actual Sails/Waterline model.
      verifyModelMethodContext(this);
    
    
    Severity: Major
    Found in lib/waterline/methods/add-to-collection.js - About 7 hrs to fix

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

        if (query.method === 'update' && !_.isUndefined(WLModel.fetchRecordsOnUpdate)) {
          if (!_.isBoolean(WLModel.fetchRecordsOnUpdate)) {
            throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnUpdate` model setting to be `true` or `false`.  But instead, got: '+util.inspect(WLModel.fetchRecordsOnUpdate, {depth:5})+'');
          }
      
      
      Severity: Major
      Found in lib/waterline/utils/query/forge-stage-two-query.js and 2 other locations - About 7 hrs to fix
      lib/waterline/utils/query/forge-stage-two-query.js on lines 310..324
      lib/waterline/utils/query/forge-stage-two-query.js on lines 329..343

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

      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

        if (query.method === 'create' && !_.isUndefined(WLModel.fetchRecordsOnCreate)) {
          if (!_.isBoolean(WLModel.fetchRecordsOnCreate)) {
            throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnCreate` model setting to be `true` or `false`.  But instead, got: '+util.inspect(WLModel.fetchRecordsOnCreate, {depth:5})+'');
          }
      
      
      Severity: Major
      Found in lib/waterline/utils/query/forge-stage-two-query.js and 2 other locations - About 7 hrs to fix
      lib/waterline/utils/query/forge-stage-two-query.js on lines 291..305
      lib/waterline/utils/query/forge-stage-two-query.js on lines 310..324

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

      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

        if (query.method === 'destroy' && !_.isUndefined(WLModel.fetchRecordsOnDestroy)) {
          if (!_.isBoolean(WLModel.fetchRecordsOnDestroy)) {
            throw new Error('Consistency violation: If specified, expecting `fetchRecordsOnDestroy` model setting to be `true` or `false`.  But instead, got: '+util.inspect(WLModel.fetchRecordsOnDestroy, {depth:5})+'');
          }
      
      
      Severity: Major
      Found in lib/waterline/utils/query/forge-stage-two-query.js and 2 other locations - About 7 hrs to fix
      lib/waterline/utils/query/forge-stage-two-query.js on lines 291..305
      lib/waterline/utils/query/forge-stage-two-query.js on lines 329..343

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

      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 removeFromCollection has 181 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = function removeFromCollection(/* targetRecordIds?, collectionAttrName?, associatedIds?, explicitCbMaybe?, meta? */) {
      
        // Verify `this` refers to an actual Sails/Waterline model.
        verifyModelMethodContext(this);
      
      
      Severity: Major
      Found in lib/waterline/methods/remove-from-collection.js - About 7 hrs to fix

        File normalize-constraint.js has 457 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-constraint.js - About 7 hrs to fix

          Function update has 174 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = function update(criteria, valuesToSet, explicitCbMaybe, metaContainer) {
          
            // Verify `this` refers to an actual Sails/Waterline model.
            verifyModelMethodContext(this);
          
          
          Severity: Major
          Found in lib/waterline/methods/update.js - About 6 hrs to fix

            Function normalizeWhereClause has 174 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm, meta) {
            
              // Look up the Waterline model for this query.
              // > This is so that we can reference the original model definition.
              var WLModel = getModel(modelIdentity, orm);
            Severity: Major
            Found in lib/waterline/utils/query/private/normalize-where-clause.js - About 6 hrs to fix

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

                              async.each(transformedRecordsMaybe, function _eachRecord(record, next) {
              
                                // If the `skipAllLifecycleCallbacks` meta flag was set, don't run any of
                                // the methods.
                                if (_.has(query.meta, 'skipAllLifecycleCallbacks') && query.meta.skipAllLifecycleCallbacks) {
              Severity: Major
              Found in lib/waterline/methods/destroy.js and 1 other location - About 6 hrs to fix
              lib/waterline/methods/update.js on lines 413..443

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

              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

                          async.each(transformedRecords, function _eachRecord(record, next) {
              
                            // If the `skipAllLifecycleCallbacks` meta flag was set, don't run any of
                            // the methods.
                            if (_.has(query.meta, 'skipAllLifecycleCallbacks') && query.meta.skipAllLifecycleCallbacks) {
              Severity: Major
              Found in lib/waterline/methods/update.js and 1 other location - About 6 hrs to fix
              lib/waterline/methods/destroy.js on lines 522..551

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

              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 _afterRunningBeforeLC has 164 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    })(function _afterRunningBeforeLC(err, query) {
                      if (err) {
                        return done(err);
                      }
              
              
              Severity: Major
              Found in lib/waterline/methods/destroy.js - About 6 hrs to fix

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

                    else if (modifierKind === '>') {
                
                      // If it matches a known attribute, verify that the attribute does not declare
                      // itself `type: 'boolean'` (it wouldn't make any sense to attempt that)
                      if (attrDef && attrDef.type === 'boolean'){
                Severity: Major
                Found in lib/waterline/utils/query/private/normalize-constraint.js and 2 other locations - About 6 hrs to fix
                lib/waterline/utils/query/private/normalize-constraint.js on lines 505..836
                lib/waterline/utils/query/private/normalize-constraint.js on lines 541..836

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

                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

                    else if (modifierKind === '<') {
                
                      // If it matches a known attribute, verify that the attribute does not declare
                      // itself `type: 'boolean'` (it wouldn't make any sense to attempt that)
                      if (attrDef && attrDef.type === 'boolean'){
                Severity: Major
                Found in lib/waterline/utils/query/private/normalize-constraint.js and 2 other locations - About 6 hrs to fix
                lib/waterline/utils/query/private/normalize-constraint.js on lines 469..836
                lib/waterline/utils/query/private/normalize-constraint.js on lines 505..836

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

                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

                    else if (modifierKind === '>=') {
                
                      // If it matches a known attribute, verify that the attribute does not declare
                      // itself `type: 'boolean'` (it wouldn't make any sense to attempt that)
                      if (attrDef && attrDef.type === 'boolean'){
                Severity: Major
                Found in lib/waterline/utils/query/private/normalize-constraint.js and 2 other locations - About 6 hrs to fix
                lib/waterline/utils/query/private/normalize-constraint.js on lines 469..836
                lib/waterline/utils/query/private/normalize-constraint.js on lines 541..836

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

                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

                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

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

                          try {
                            assert.equal(schemaDef.collection.toLowerCase(), schemaDef.collection, '`schemaDef.collection` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.collection);
                            assert.equal(schemaDef.referenceIdentity.toLowerCase(), schemaDef.referenceIdentity, '`schemaDef.referenceIdentity` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.referenceIdentity);
                            assert.equal(Object.getPrototypeOf(WLChild).identity.toLowerCase(), Object.getPrototypeOf(WLChild).identity, '`Object.getPrototypeOf(WLChild).identity` (identity) should have already been normalized before getting here!  But it was not: '+Object.getPrototypeOf(WLChild).identity);
                          } catch (e) { return proceed(e); }
                  Severity: Major
                  Found in lib/waterline/methods/remove-from-collection.js and 1 other location - About 6 hrs to fix
                  lib/waterline/methods/replace-collection.js on lines 283..287

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

                  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

                          try {
                            assert.equal(schemaDef.collection.toLowerCase(), schemaDef.collection, '`schemaDef.collection` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.collection);
                            assert.equal(schemaDef.referenceIdentity.toLowerCase(), schemaDef.referenceIdentity, '`schemaDef.referenceIdentity` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.referenceIdentity);
                            assert.equal(Object.getPrototypeOf(WLChild).identity.toLowerCase(), Object.getPrototypeOf(WLChild).identity, '`Object.getPrototypeOf(WLChild).identity` (identity) should have already been normalized before getting here!  But it was not: '+Object.getPrototypeOf(WLChild).identity);
                          } catch (e) { return proceed(e); }
                  Severity: Major
                  Found in lib/waterline/methods/replace-collection.js and 1 other location - About 6 hrs to fix
                  lib/waterline/methods/remove-from-collection.js on lines 285..289

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

                  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 create has 143 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports = function create(newRecord, explicitCbMaybe, metaContainer) {
                  
                    // Verify `this` refers to an actual Sails/Waterline model.
                    verifyModelMethodContext(this);
                  
                  
                  Severity: Major
                  Found in lib/waterline/methods/create.js - About 5 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language