mbroadst/thinkagain

View on GitHub

Showing 143 of 143 total issues

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

              if ((constructor.getTableName() === joins[key].model.getTableName())
                && (joins[key].leftKey === joins[key].rightKey)) {
                // We link on the same model and same key
                // We don't want to save redundant field
                if (link < this[joins[key].leftKey]) {
Severity: Minor
Found in lib/document.js and 1 other location - About 50 mins to fix
lib/query.js on lines 373..401

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

            if ((model.getTableName() === joins[key].model.getTableName()) && (joins[key].leftKey === joins[key].rightKey)) {
              // In case the model is linked with itself on the same key

              innerQuery = r.table(joins[key].link)
                .getAll(doc(joins[key].leftKey), {index: joins[key].leftKey + '_' + joins[key].leftKey})
Severity: Minor
Found in lib/query.js and 1 other location - About 50 mins to fix
lib/document.js on lines 741..767

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

Avoid deeply nested control flow statements.
Open

                if (link < this[joins[key].leftKey]) {
                  newLink.id = link + '_' + this[joins[key].leftKey];
                } else {
                  newLink.id = this[joins[key].leftKey] + '_' + link;
                }
Severity: Major
Found in lib/document.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                    if (model.getTableName() < joinedModel.getTableName()) {
                      return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                    } else if (model.getTableName() > joinedModel.getTableName()) {
                      return linkModel.getAll(rightKey.add('_').add(leftKey)).delete()._query;
                    }
    Severity: Major
    Found in lib/query.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                    if (doc[key][i] instanceof Document === false) {
                      doc[key][i] = new joins[key].model(doc[key][i], _options); // eslint-disable-line
                    }
      Severity: Major
      Found in lib/model.js - About 45 mins to fix

        Function _validateHook has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          _validateHook(options, modelToValidate, validateAll, validatedModel, prefix) {
            options = options || {};
        
            let dataToValidate = this;
            if (!!options.data) {
        Severity: Minor
        Found in lib/document.js - About 45 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

        Avoid deeply nested control flow statements.
        Open

                        if (model.getTableName() < joinedModel.getTableName()) {
                          return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
                        } else if (model.getTableName() > joinedModel.getTableName()) {
                          return linkModel.getAll(rightKey.add('_').add(leftKey)).delete()._query;
                        }
        Severity: Major
        Found in lib/query.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                          for (let k = 0, kk = joined[joinKey].length; k < kk; ++k) {
                            if (joined[joinKey][k].doc === this) {
                              joined[joinKey].splice(k, 1);
                              return false;
                            }
          Severity: Major
          Found in lib/document.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (this.getModel()._getModel()._pk === joins[key].leftKey) {
                          if (this._getModel()._name < joins[key].model._getModel()._name) {
                            linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                          } else {
                            linksPks.push(this[key][i][joins[key].rightKey] + '_' + this[joins[key].leftKey]);
            Severity: Major
            Found in lib/document.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                            if (this[key][i].isSaved() === true) {
                              newKeys[this[key][i][joins[key].rightKey]] = true;
                            }
              Severity: Major
              Found in lib/document.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                              if (this._getModel()._name === joins[key].model._getModel()._name) {
                                if (this[joins[key].leftKey] < this[key][i][joins[key].rightKey]) {
                                  //TODO Add test for this
                                  linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                                } else {
                Severity: Major
                Found in lib/document.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  if (constructor.getTableName() < joins[key].model.getTableName()) {
                                    newLink.id = this[joins[key].leftKey] + '_' + link;
                                  } else if (constructor.getTableName() > joins[key].model.getTableName()) {
                                    newLink.id = link + '_' + this[joins[key].leftKey];
                                  } else {
                  Severity: Major
                  Found in lib/document.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if (typeof this[key][i]._emitRetrieve === 'function') {
                                  this[key][i]._emitRetrieve();
                                }
                    Severity: Major
                    Found in lib/document.js - About 45 mins to fix

                      Consider simplifying this complex logical expression.
                      Open

                            if (((key in docToSave) || (saveAll === true)) &&
                                (join.type === 'hasMany') && ((saveAll === false) || (savedModel[join.model.getTableName()] !== true))
                                && (Array.isArray(this[key]))) {
                              savedModel[join.model.getTableName()] = true;
                      
                      
                      Severity: Major
                      Found in lib/document.js - About 40 mins to fix

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

                                    if ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                      innerQuery = innerQuery.coerceTo('ARRAY');
                                    }
                        Severity: Minor
                        Found in lib/query.js and 2 other locations - About 40 mins to fix
                        lib/query.js on lines 392..394
                        lib/query.js on lines 412..414

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

                        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 ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                        innerQuery = innerQuery.coerceTo('ARRAY');
                                      }
                        Severity: Minor
                        Found in lib/query.js and 2 other locations - About 40 mins to fix
                        lib/query.js on lines 358..360
                        lib/query.js on lines 412..414

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

                        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 ((modelToGet[key] == null) || (modelToGet[key]._array !== false)) { // eslint-disable-line
                                      innerQuery = innerQuery.coerceTo('ARRAY');
                                    }
                        Severity: Minor
                        Found in lib/query.js and 2 other locations - About 40 mins to fix
                        lib/query.js on lines 358..360
                        lib/query.js on lines 392..394

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

                        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 executeHooks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function executeHooks(hookIndex, hooks, doc, reject, next) {
                        Severity: Minor
                        Found in lib/util.js - About 35 mins to fix

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

                          function recurse(key, joins, modelTo, all, done) {
                          Severity: Minor
                          Found in lib/util.js - About 35 mins to fix

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

                              for (let j = 0, jj = postHooks.length; j < jj; ++j) {
                                postHooks[j].call(doc);
                              }
                            Severity: Minor
                            Found in lib/util.js and 1 other location - About 35 mins to fix
                            lib/util.js on lines 124..126

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

                            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