CleverStack/clever-odm

View on GitHub

Showing 53 of 53 total issues

Function exports has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function( grunt ) {
  var dbTarget        = grunt.option( 'module' ) || null
    , defaultConfig   = require( path.join( __dirname, 'config', 'default.json' ) )
    , configFile      = null
    , config          = {};
Severity: Major
Found in Gruntfile.js - About 3 hrs to fix

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

      var targetModelName    = assocTo.shift()
        , associationOptions = assocTo.shift()
        , sourceModel        = injector.getInstance(sourceModelName + 'Model')
        , targetModel        = injector.getInstance((associationOptions.through ? associationOptions.through : targetModelName) + 'Model')
        , alias              = associationOptions.alias || associationOptions.as || targetModelName.replace('Model','')
    Severity: Major
    Found in lib/model/associations/hasOne.js and 1 other location - About 3 hrs to fix
    lib/model/associations/index.js on lines 36..41

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

    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 targetModelName    = assocTo.shift()
              , associationOptions = assocTo.shift()
              , sourceModel        = injector.getInstance(sourceModelName + 'Model')
              , targetModel        = injector.getInstance((associationOptions.through ? associationOptions.through : targetModelName) + 'Model')
              , alias              = associationOptions.alias || associationOptions.as || targetModelName.replace('Model','')
    Severity: Major
    Found in lib/model/associations/index.js and 1 other location - About 3 hrs to fix
    lib/model/associations/hasOne.js on lines 7..12

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

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

    function defineAssociations(models) {
      /*jshint validthis: true */
      var cleverOdm  = this
        , modelNames = Object.keys(models);
    
    
    Severity: Minor
    Found in lib/model/associations/index.js - About 3 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 associateModels has 86 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          function associateModels(callback) {
            async.forEachSeries(
              Object.keys(seedData),
              function forEachSeedDataModel(modelName, cb) {
                var ModelType = models[modelName.replace('Model', '')]
    Severity: Major
    Found in bin/seedModels.js - About 3 hrs to fix

      Function forEachSeedDataModel has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                function forEachSeedDataModel(modelName, cb) {
                  var ModelType = models[modelName.replace('Model', '')]
                    , Models = seedData[modelName];
      
                  if (!ModelType || !Models || ModelType.type !== 'ODM') {
      Severity: Major
      Found in bin/seedModels.js - About 3 hrs to fix

        Function associateModel has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                      function associateModel(data, modelCb) {
                        if (data.associations !== undefined) {
                          var assocLength = Object.keys(data.associations).length
                            , called      = 0
                            , model       = _.findWhere(assocMap[modelName], { id: data.id });
        Severity: Major
        Found in bin/seedModels.js - About 2 hrs to fix

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

            association.identifier  = inflect.pluralize(associationOptions.foreignKey ? associationOptions.foreignKey : (Klass.underscored === true ? inflect.foreign_key(targetModelName, Klass.primaryKey) : inflect.camelize(targetModelName + '_' + Klass.primaryKey, true)));
          Severity: Major
          Found in lib/model/associations/hasMany.js and 1 other location - About 2 hrs to fix
          lib/model/associations/belongsTo.js on lines 17..17

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

          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

            association.identifier  = inflect.singularize(associationOptions.foreignKey ? associationOptions.foreignKey : (Klass.underscored === true ? inflect.foreign_key(targetModelName, Klass.primaryKey) : inflect.camelize(targetModelName + '_' + Klass.primaryKey, true)));
          Severity: Major
          Found in lib/model/associations/belongsTo.js and 1 other location - About 2 hrs to fix
          lib/model/associations/hasMany.js on lines 17..17

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

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

            defineField: function(Klass, fields, mongooseConf, name) {
              var fieldDefinition = {}
                , columnName      = name
                , options         = Klass.fields[name];
          
          
          Severity: Minor
          Found in module.js - About 2 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 defineField has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            defineField: function(Klass, fields, mongooseConf, name) {
              var fieldDefinition = {}
                , columnName      = name
                , options         = Klass.fields[name];
          
          
          Severity: Major
          Found in module.js - About 2 hrs to fix

            Function belongsTo has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function belongsTo(mongoose, Klass, Proto, assocTo) {
              assocTo      = assocTo instanceof Array ? underscore.clone(assocTo) : [assocTo, {}];
            
              if (Klass.primaryKeys.length !== 1) {
                throw new Error('belongsTo association not support without primaryKeys.');
            Severity: Minor
            Found in lib/model/associations/belongsTo.js - About 2 hrs to fix

              Function hasMany has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports = function hasMany(mongoose, Klass, Proto, assocTo) {
                assocTo      = assocTo instanceof Array ? underscore.clone(assocTo) : [assocTo, {}];
              
                if (Klass.primaryKeys.length !== 1) {
                  throw new Error('hasMany association not support without primaryKeys.');
              Severity: Minor
              Found in lib/model/associations/hasMany.js - About 1 hr to fix

                Function createModels has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      function createModels(callback) {
                        async.forEachSeries(
                          Object.keys(seedData),
                          function forEachSeedDataModel(modelName, cb) {
                            var ModelType = models[modelName.replace('Model', '')]
                Severity: Minor
                Found in bin/seedModels.js - About 1 hr to fix

                  Function defineAssociationAccessors has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function defineAssociationAccessors(sourceModel, assocType, targetModel, alias, association) {
                    console.dir(arguments);
                    process.exit(1);
                    var accessors   = this[assocType]
                      , singular    = inflect.singularize(alias)
                  Severity: Minor
                  Found in lib/model/associations/accessors/index.js - About 1 hr to fix

                    Function belongsTo has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                    Open

                    module.exports = function belongsTo(mongoose, Klass, Proto, assocTo) {
                      assocTo      = assocTo instanceof Array ? underscore.clone(assocTo) : [assocTo, {}];
                    
                      if (Klass.primaryKeys.length !== 1) {
                        throw new Error('belongsTo association not support without primaryKeys.');
                    Severity: Minor
                    Found in lib/model/associations/belongsTo.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 hasOne has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    module.exports = function hasOne(mongoose, model, proto, assocTo) {
                      assocTo      = assocTo instanceof Array ? underscore.clone(assocTo) : [assocTo, {}];
                    
                      var targetModelName    = assocTo.shift()
                        , associationOptions = assocTo.shift()
                    Severity: Minor
                    Found in lib/model/associations/hasOne.js - About 1 hr to fix

                      Function defineAssociations has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function defineAssociations(models) {
                        /*jshint validthis: true */
                        var cleverOdm  = this
                          , modelNames = Object.keys(models);
                      
                      
                      Severity: Minor
                      Found in lib/model/associations/index.js - About 1 hr to fix

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

                        module.exports = function hasMany(mongoose, Klass, Proto, assocTo) {
                          assocTo      = assocTo instanceof Array ? underscore.clone(assocTo) : [assocTo, {}];
                        
                          if (Klass.primaryKeys.length !== 1) {
                            throw new Error('hasMany association not support without primaryKeys.');
                        Severity: Minor
                        Found in lib/model/associations/hasMany.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 getFieldType has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          getFieldType: function(Klass, options, name) {
                            var field;
                        
                            switch(options.type) {
                        
                        
                        Severity: Minor
                        Found in module.js - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language