mbroadst/thinkagain

View on GitHub

Showing 143 of 143 total issues

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

      case 'hasAndBelongsToMany':
        if (Array.isArray(this[key])) {
          for (let i = 0, ii = this[key].length; i < ii; ++i) {
            if (this[key][i] instanceof Document) {
              this[key][i].setSaved(true);
Severity: Major
Found in lib/document.js and 1 other location - About 3 hrs to fix
lib/document.js on lines 857..865

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

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

      case 'hasMany':
        if (Array.isArray(this[key])) {
          for (let i = 0, ii = this[key].length; i < ii; ++i) {
            if (this[key][i] instanceof Document) {
              this[key][i].setSaved(true);
Severity: Major
Found in lib/document.js and 1 other location - About 3 hrs to fix
lib/document.js on lines 867..875

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

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 (this[key][i].__proto__._parents._hasMany[this._getModel()._name] == null) { // eslint-disable-line
            this[key][i].__proto__._parents._hasMany[this._getModel()._name] = []; // eslint-disable-line
          }
Severity: Major
Found in lib/document.js and 1 other location - About 2 hrs to fix
lib/document.js on lines 947..949

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

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 (this[key][i].__proto__._parents._belongsLinks[this._getModel()._name] == null) { // eslint-disable-line
            this[key][i].__proto__._parents._belongsLinks[this._getModel()._name] = []; // eslint-disable-line
          }
Severity: Major
Found in lib/document.js and 1 other location - About 2 hrs to fix
lib/document.js on lines 926..928

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

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

  purge(callback) {
    let model = this._getModel(); // instance of Model
    let r = model._thinkagain.r;

    // Clean parent for hasOne
Severity: Major
Found in lib/document.js - About 2 hrs to fix

    Function removeRelation has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      removeRelation(field, joinedDocument) {
        let model = this._model;
        let joins = this._model._getModel()._joins;
        let joinedModel = joins[field].model;
        let r = this._model._thinkagain.r;
    Severity: Minor
    Found in lib/query.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 new has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static new(name, schema, options, thinkagain) {
        let validate = thinkagain.ajv.compile(schema);
        let proto = new Model(name, validate, options, thinkagain);
        proto._initModel = options.init  !== undefined ? !!options.init : true;
    
    
    Severity: Major
    Found in lib/model.js - About 2 hrs to fix

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

              promises.push(r.table(joinedModel.getTableName()).getAll(this[join.rightKey], {index: join.leftKey}).replace(doc => {
                return doc.without(join.leftKey);
              }).run());
      Severity: Major
      Found in lib/document.js and 1 other location - About 2 hrs to fix
      lib/document.js on lines 1298..1300

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

      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

              promises.push(r.table(joinedModel.getTableName()).getAll(this[join.leftKey], {index: join.rightKey}).replace(doc => {
                return doc.without(join.rightKey);
              }).run());
      Severity: Major
      Found in lib/document.js and 1 other location - About 2 hrs to fix
      lib/document.js on lines 1317..1319

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

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

        save(docs, options) {
          let r = this._getModel()._thinkagain.r;
          let isArray = Array.isArray(docs);
      
          if (!isArray) {
      Severity: Major
      Found in lib/model.js - About 2 hrs to fix

        Function addRelation has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          addRelation(field, joinedDocument) {
            let model = this._model;
            let joins = this._model._getModel()._joins;
            let joinedModel = joins[field].model;
            let r = this._model._thinkagain.r;
        Severity: Minor
        Found in lib/query.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

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

                if (this[key].__proto__._parents._hasOne[this._getModel()._name] == null) { // eslint-disable-line
                  this[key].__proto__._parents._hasOne[this._getModel()._name] = []; // eslint-disable-line
                }
        Severity: Major
        Found in lib/document.js and 1 other location - About 2 hrs to fix
        lib/document.js on lines 902..904

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

        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

                  promises.push(r.table(join.link).getAll(this[join.leftKey], {index: this.getModel().getTableName() + '_' + join.leftKey}).delete().run());
        Severity: Major
        Found in lib/document.js and 1 other location - About 2 hrs to fix
        lib/document.js on lines 1324..1324

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

        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 (this[key].__proto__._parents._belongsTo[this._getModel()._name] == null) { // eslint-disable-line
                  this[key].__proto__._parents._belongsTo[this._getModel()._name] = []; // eslint-disable-line
                }
        Severity: Major
        Found in lib/document.js and 1 other location - About 2 hrs to fix
        lib/document.js on lines 891..893

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

        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

                  promises.push(r.table(join.link).getAll(this[join.rightKey], {index: this.getModel().getTableName() + '_' + join.rightKey}).delete().run());
        Severity: Major
        Found in lib/document.js and 1 other location - About 2 hrs to fix
        lib/document.js on lines 1304..1304

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

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

          _validateQueryResult(result) {
            if (result.errors > 0) {
              return Promise.reject(new Errors.InvalidWrite('An error occured during the write', result));
            }
        
        
        Severity: Major
        Found in lib/query.js - About 2 hrs to fix

          Function save has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

            save(docs, options) {
              let r = this._getModel()._thinkagain.r;
              let isArray = Array.isArray(docs);
          
              if (!isArray) {
          Severity: Minor
          Found in lib/model.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

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

                      } else if (model.getTableName() > joinedModel.getTableName()) {
                        return r.object(
                          'id', rightKey.add('_').add(leftKey),
                          model.getTableName() + '_' + joins[field].leftKey, leftKey,
                          joinedModel.getTableName() + '_' + joins[field].rightKey, rightKey
          Severity: Major
          Found in lib/query.js and 1 other location - About 2 hrs to fix
          lib/query.js on lines 516..528

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

          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() < joinedModel.getTableName()) {
                        return r.object(
                          'id', leftKey.add('_').add(rightKey),
                          model.getTableName() + '_' + joins[field].leftKey, leftKey,
                          joinedModel.getTableName() + '_' + joins[field].rightKey, rightKey
          Severity: Major
          Found in lib/query.js and 1 other location - About 2 hrs to fix
          lib/query.js on lines 522..528

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

          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 (((this[key][i] instanceof Document) && (this[key][i].isSaved() === true))
                      && ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key][i]) === -1)))) {
                      manyPromises.push(this[key][i]._delete(docToDelete[key], deleteAll, deletedDocs, true, false));
                    } else if ((this[key][i] instanceof Document) && (deletedDocs.indexOf(this[key][i]) === -1)) {
                      delete this[key][i][joins[key].rightKey];
          Severity: Major
          Found in lib/document.js and 1 other location - About 2 hrs to fix
          lib/document.js on lines 1116..1147

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

          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