mbroadst/thinkagain

View on GitHub

Showing 143 of 143 total issues

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

            for (let i = 0, ii = doc[key].length; i < ii; ++i) {
              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 and 1 other location - About 1 hr to fix
lib/model.js on lines 119..123

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

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

  constructor(model, options) {
    this.constructor = model;  // The constructor for this model
    this._model = model._getModel(); // The instance of Model

    //TODO: We do not need to make a deep copy. We can do the same as for this._schemaOptions.
Severity: Minor
Found in lib/document.js - About 1 hr to fix

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

        let executeInsert = (resolve, reject) => {
          toSave--;
          resolves.push(resolve);
          rejects.push(reject);
    
    
    Severity: Minor
    Found in lib/model.js - About 1 hr to fix

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

              if ((this[key].isSaved() === true) &&
                ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key]) === -1)))) {
                let deletePromise = this[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false)
                  .then(() => { delete this[key]; });
                promises.push(deletePromise);
      Severity: Major
      Found in lib/document.js and 1 other location - About 1 hr to fix
      lib/document.js on lines 1081..1086

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

      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

              if ((this[key].isSaved() === true) &&
                ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key]) === -1)))) {
                let deletePromise = this[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false)
                  .then(() => { delete this[key]; });
                promises.push(deletePromise);
      Severity: Major
      Found in lib/document.js and 1 other location - About 1 hr to fix
      lib/document.js on lines 1067..1077

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

      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 (typeof docToSave === 'function') {
            callback = docToSave;
            saveAll = true;
            docToSave = {};
          } else {
      Severity: Major
      Found in lib/document.js and 1 other location - About 1 hr to fix
      lib/document.js on lines 995..1002

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

      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

        run(options, callback) {
          if (typeof options === 'function') {
            callback = options;
            options = {};
          }
      Severity: Major
      Found in lib/query.js and 1 other location - About 1 hr to fix
      lib/query.js on lines 86..92

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

      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

        execute(options, callback) {
          if (typeof options === 'function') {
            callback = options;
            options = {};
          }
      Severity: Major
      Found in lib/query.js and 1 other location - About 1 hr to fix
      lib/query.js on lines 71..77

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

      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 (typeof docToDelete === 'function') {
            callback = docToDelete;
            deleteAll = true;
            docToDelete = {};
          } else {
      Severity: Major
      Found in lib/document.js and 1 other location - About 1 hr to fix
      lib/document.js on lines 270..277

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

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

      function hook(options) {
        let preHooks = options.preHooks;
        if (Array.isArray(preHooks) === false) {
          preHooks = [];
        }
      Severity: Minor
      Found in lib/util.js - About 1 hr to fix

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

          hasMany(joinedModel, fieldDoc, leftKey, rightKey, options) {
            if ((joinedModel instanceof Model) === false) {
              throw new Errors.ThinkAgainError('First argument of `hasMany` must be a Model');
            }
        
        
        Severity: Minor
        Found in lib/model.js - About 1 hr to fix

          Function hasOne has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            hasOne(joinedModel, fieldDoc, leftKey, rightKey, options) {
              if ((joinedModel instanceof Model) === false) {
                throw new Errors.ThinkAgainError('First argument of `hasOne` must be a Model');
              }
          
          
          Severity: Minor
          Found in lib/model.js - About 1 hr to fix

            Function constructor has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              constructor(model, query, options, error) {
                this._model = model; // constructor of the model we should use for the results.
                if (model !== undefined) {
                  this._r = model._getModel()._thinkagain.r;
                  util.loopKeys(model._getModel()._staticMethods, (staticMethods, key) => {
            Severity: Minor
            Found in lib/query.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 _promisesReady has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              _promisesReady() {
                let self = this;
                if (this._promisesReadyPromise) return this._promisesReadyPromise;
                let verifyAll = function() {
                  return Promise.all(self._pendingPromises)
            Severity: Minor
            Found in lib/model.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 __makeSavableCopy has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              __makeSavableCopy(doc, model, r) {
                // model is an instance of a Model (for the top level fields), or undefined
                let result, copyFlag;
            
                if (util.isPlainObject(doc) && (doc instanceof Buffer === false)) {
            Severity: Minor
            Found in lib/document.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 constructor has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              constructor(model, query, options, error) {
                this._model = model; // constructor of the model we should use for the results.
                if (model !== undefined) {
                  this._r = model._getModel()._thinkagain.r;
                  util.loopKeys(model._getModel()._staticMethods, (staticMethods, key) => {
            Severity: Minor
            Found in lib/query.js - About 1 hr to fix

              Function _asyncHook has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function _asyncHook(args) {
                // One of the hook, or the function is asynchronous, so we will
                // always return a promise
                // We only need to keep track of the result return/resolved for fn
              
              
              Severity: Minor
              Found in lib/util.js - About 1 hr to fix

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

                          this[key][i].__proto__._parents._hasMany[this._getModel()._name].push({ // eslint-disable-line
                            doc: this,
                            key: key
                          });
                Severity: Major
                Found in lib/document.js and 1 other location - About 1 hr to fix
                lib/document.js on lines 951..954

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

                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

                                        r.table(joins[key].model.getTableName())
                                      .getAll(doc(joins[key].leftKey), {index: joins[key].rightKey}));
                Severity: Major
                Found in lib/query.js and 1 other location - About 1 hr to fix
                lib/query.js on lines 324..325

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

                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

                                r.table(joins[key].model.getTableName())
                                  .getAll(doc(joins[key].leftKey), {index: joins[key].rightKey}).coerceTo('ARRAY')
                Severity: Major
                Found in lib/query.js and 1 other location - About 1 hr to fix
                lib/query.js on lines 351..352

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

                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