balderdashy/waterline

View on GitHub

Showing 357 of 357 total issues

Function forgeStageTwoQuery has a Cognitive Complexity of 231 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function forgeStageTwoQuery(query, orm) {
  // if (process.env.NODE_ENV !== 'production') {
  //   console.time('forgeStageTwoQuery');
  // }

Severity: Minor
Found in lib/waterline/utils/query/forge-stage-two-query.js - About 4 days 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

module.exports = function destroyOne(criteria, explicitCbMaybe, metaContainer){

  // Verify `this` refers to an actual Sails/Waterline model.
  verifyModelMethodContext(this);

Severity: Major
Found in lib/waterline/methods/destroy-one.js and 1 other location - About 3 days to fix
lib/waterline/methods/archive-one.js on lines 33..196

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

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

module.exports = function archiveOne(criteria, explicitCbMaybe, metaContainer){

  // Verify `this` refers to an actual Sails/Waterline model.
  verifyModelMethodContext(this);

Severity: Major
Found in lib/waterline/methods/archive-one.js and 1 other location - About 3 days to fix
lib/waterline/methods/destroy-one.js on lines 32..195

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

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 normalizeConstraint has a Cognitive Complexity of 188 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function normalizeConstraint (constraintRhs, constraintTarget, modelIdentity, orm, meta){
  if (_.isUndefined(constraintRhs)) {
    throw new Error('Consistency violation: The internal normalizeConstraint() utility must always be called with a first argument (the RHS of the constraint to normalize).  But instead, got: '+util.inspect(constraintRhs, {depth:5})+'');
  }
  if (!_.isString(constraintTarget)) {
Severity: Minor
Found in lib/waterline/utils/query/private/normalize-constraint.js - About 3 days 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 forgeStageTwoQuery has 708 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function forgeStageTwoQuery(query, orm) {
  // if (process.env.NODE_ENV !== 'production') {
  //   console.time('forgeStageTwoQuery');
  // }

Severity: Major
Found in lib/waterline/utils/query/forge-stage-two-query.js - About 3 days to fix

    Function normalizeValueToSet has a Cognitive Complexity of 130 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function normalizeValueToSet(value, supposedAttrName, modelIdentity, orm, meta) {
    
      // ================================================================================================
      assert(_.isString(supposedAttrName), '`supposedAttrName` must be a string.');
      // (`modelIdentity` and `orm` will be automatically checked by calling `getModel()` below)
    Severity: Minor
    Found in lib/waterline/utils/query/private/normalize-value-to-set.js - About 2 days 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 normalizeConstraint has 425 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function normalizeConstraint (constraintRhs, constraintTarget, modelIdentity, orm, meta){
      if (_.isUndefined(constraintRhs)) {
        throw new Error('Consistency violation: The internal normalizeConstraint() utility must always be called with a first argument (the RHS of the constraint to normalize).  But instead, got: '+util.inspect(constraintRhs, {depth:5})+'');
      }
      if (!_.isString(constraintTarget)) {
    Severity: Major
    Found in lib/waterline/utils/query/private/normalize-constraint.js - About 2 days to fix

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

        function Waterline() {
        
          // Start by setting up an array of model definitions.
          // (This will hold the raw model definitions that were passed in,
          // plus any implicitly introduced models-- but that part comes later)
        Severity: Major
        Found in lib/waterline.js - About 1 day to fix

          Function forgeStageThreeQuery has 380 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = function forgeStageThreeQuery(options) {
            //  ╦  ╦╔═╗╦  ╦╔╦╗╔═╗╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
            //  ╚╗╔╝╠═╣║  ║ ║║╠═╣ ║ ║╣   │ │├─┘ │ ││ ││││└─┐
            //   ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝  └─┘┴   ┴ ┴└─┘┘└┘└─┘
            if (!_.has(options, 'stageTwoQuery') || !_.isPlainObject(options.stageTwoQuery)) {
          Severity: Major
          Found in lib/waterline/utils/query/forge-stage-three-query.js - About 1 day to fix

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

                  try {
                    forgeStageTwoQuery(query, orm);
                  } catch (e) {
                    switch (e.code) {
            
            
            Severity: Major
            Found in lib/waterline/methods/add-to-collection.js and 1 other location - About 1 day to fix
            lib/waterline/methods/remove-from-collection.js on lines 200..267

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

            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 {
                    forgeStageTwoQuery(query, orm);
                  } catch (e) {
                    switch (e.code) {
            
            
            Severity: Major
            Found in lib/waterline/methods/remove-from-collection.js and 1 other location - About 1 day to fix
            lib/waterline/methods/add-to-collection.js on lines 198..265

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

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

              orm.initialize = function initialize(options, done) {
            
                try {
            
            
            
            Severity: Major
            Found in lib/waterline.js - About 1 day to fix

              File forge-stage-two-query.js has 723 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              /**
               * Module dependencies
               */
              
              var assert = require('assert');
              Severity: Major
              Found in lib/waterline/utils/query/forge-stage-two-query.js - About 1 day to fix

                Function helpFind has 332 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                module.exports = function helpFind(WLModel, s2q, omen, done) {
                
                  if (!_.isFunction(done)) {
                    throw new Error('Consistency violation: `done` (4th argument) should be a function');
                  }
                Severity: Major
                Found in lib/waterline/utils/query/help-find.js - About 1 day to fix

                  Function normalizeValueToSet has 301 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports = function normalizeValueToSet(value, supposedAttrName, modelIdentity, orm, meta) {
                  
                    // ================================================================================================
                    assert(_.isString(supposedAttrName), '`supposedAttrName` must be a string.');
                    // (`modelIdentity` and `orm` will be automatically checked by calling `getModel()` below)
                  Severity: Major
                  Found in lib/waterline/utils/query/private/normalize-value-to-set.js - About 1 day to fix

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

                        else if (modifierKind === 'nin') {
                    
                          if (!_.isArray(modifier)) {
                            throw flaverr('E_CONSTRAINT_NOT_USABLE', new Error(
                              'A `nin` ("not in") modifier should always be provided as an array.  '+
                    Severity: Major
                    Found in lib/waterline/utils/query/private/normalize-constraint.js and 1 other location - About 1 day to fix
                    lib/waterline/utils/query/private/normalize-constraint.js on lines 370..415

                    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

                        else if (modifierKind === 'in') {
                    
                          if (!_.isArray(modifier)) {
                            throw flaverr('E_CONSTRAINT_NOT_USABLE', new Error(
                              'An `in` modifier should always be provided as an array.  '+
                    Severity: Major
                    Found in lib/waterline/utils/query/private/normalize-constraint.js and 1 other location - About 1 day to fix
                    lib/waterline/utils/query/private/normalize-constraint.js on lines 419..464

                    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

                    Function forgeStageThreeQuery has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
                    Open

                    module.exports = function forgeStageThreeQuery(options) {
                      //  ╦  ╦╔═╗╦  ╦╔╦╗╔═╗╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
                      //  ╚╗╔╝╠═╣║  ║ ║║╠═╣ ║ ║╣   │ │├─┘ │ ││ ││││└─┐
                      //   ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝  └─┘┴   ┴ ┴└─┘┘└┘└─┘
                      if (!_.has(options, 'stageTwoQuery') || !_.isPlainObject(options.stageTwoQuery)) {
                    Severity: Minor
                    Found in lib/waterline/utils/query/forge-stage-three-query.js - About 1 day 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

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

                              if (_.has(Object.getPrototypeOf(WLChild), 'junctionTable') && WLChild.junctionTable) {
                                // Assumes the generated junction table will only ever have two foreign key
                                // values. Should be safe for now and any changes would need to be made in
                                // Waterline-Schema where a map could be formed anyway.
                                _.each(WLChild.schema, function(wlsAttrDef, key) {
                    Severity: Major
                    Found in lib/waterline/methods/replace-collection.js and 1 other location - About 1 day to fix
                    lib/waterline/methods/remove-from-collection.js on lines 342..370

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language