mbroadst/thinkagain

View on GitHub

Showing 143 of 143 total issues

File document.js has 951 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
const Promise = require('bluebird'),
      Errors = require('./errors'),
      util = require('./util');

Severity: Major
Found in lib/document.js - About 2 days to fix

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

                  && (joins[field].leftKey === joins[field].rightKey)) {
                query = this._query(joins[field].leftKey).do(leftKey => {
                  return joinedModel.get(joinedDocument[joinedModel._pk]).bracket(joins[field].rightKey).do(rightKey => {
                    if (model.getTableName() < joinedModel.getTableName()) {
                      return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
    Severity: Major
    Found in lib/query.js and 1 other location - About 1 day to fix
    lib/query.js on lines 645..661

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

    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

              } else {
                query = this._query(joins[field].leftKey).do(leftKey => {
                  return joinedModel.get(joinedDocument[joinedModel._pk]).bracket(joins[field].rightKey).do(rightKey => {
                    if (model.getTableName() < joinedModel.getTableName()) {
                      return linkModel.getAll(leftKey.add('_').add(rightKey)).delete()._query;
    Severity: Major
    Found in lib/query.js and 1 other location - About 1 day to fix
    lib/query.js on lines 629..645

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

    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

    File model.js has 724 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    const Promise = require('bluebird'),
          EventEmitter = require('events'),
          Document = require('./document'),
          Errors = require('./errors'),
    Severity: Major
    Found in lib/model.js - About 1 day to fix

      File query.js has 597 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      'use strict';
      const Promise = require('bluebird'),
            Errors = require('./errors'),
            Feed = require('./feed'),
            util = require('./util');
      Severity: Major
      Found in lib/query.js - About 1 day to fix

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

            util.loopKeys(this.__proto__._parents._belongsLinks, (belongsLinks, key) => { // eslint-disable-line
              for (let i = 0, ii = belongsLinks[key].length; i < ii; ++i) {
                let parentDoc = belongsLinks[key][i].doc;
                let field = belongsLinks[key][i].key;
                for (let j = 0, jj = parentDoc[field].length; j < jj; ++j) {
        Severity: Major
        Found in lib/document.js and 1 other location - About 7 hrs to fix
        lib/document.js on lines 1264..1275

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

        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

            util.loopKeys(this.__proto__._parents._hasMany, (hasMany, key) => { // eslint-disable-line
              for (let i = 0, ii = hasMany[key].length; i < ii; ++i) {
                let parentDoc = hasMany[key][i].doc;
                let field = hasMany[key][i].key;
                for (let j = 0, jj = parentDoc[field].length; j < jj; ++j) {
        Severity: Major
        Found in lib/document.js and 1 other location - About 7 hrs to fix
        lib/document.js on lines 1278..1289

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

        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

          post(ev, fn) {
            if (typeof fn !== 'function') {
              throw new Errors.ThinkAgainError('Second argument to `pre` must be a function');
            }
            if (fn.length > 1) {
        Severity: Major
        Found in lib/model.js and 1 other location - About 7 hrs to fix
        lib/model.js on lines 907..919

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

        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

          pre(ev, fn) {
            if (typeof fn !== 'function') {
              throw new Errors.ThinkAgainError('Second argument to `pre` must be a function');
            }
            if (fn.length > 1) {
        Severity: Major
        Found in lib/model.js and 1 other location - About 7 hrs to fix
        lib/model.js on lines 921..933

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

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

          _deleteHook(docToDelete, deleteAll, deletedDocs, deleteSelf, updateParents, callback) {
            let model = this._getModel(); // instance of Model
            let r = model._thinkagain.r;
        
            let promises = [];
        Severity: Major
        Found in lib/document.js - About 5 hrs to fix

          Document has 42 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Document {
          
            /**
             * Create a document of a model (returned by `thinkagain.createModel`).
             * @param {function} model The model of this document
          Severity: Minor
          Found in lib/document.js - About 5 hrs to fix

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

                          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 and 1 other location - About 5 hrs to fix
            lib/document.js on lines 1132..1136

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

            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

                          } else 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 and 1 other location - About 5 hrs to fix
            lib/document.js on lines 1141..1145

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

            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

            Model has 36 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class Model extends EventEmitter {
            
              /*
              * Constructor for a Model. Note that this is not what `thinkagain.createModel`
              * returns. It is the prototype of what `thinkagain.createModel` returns.
            Severity: Minor
            Found in lib/model.js - About 4 hrs to fix

              Function getJoin has 109 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                getJoin(modelToGet, _getAll, gotModel) {
                  let r = this._model._getModel()._thinkagain.r;
                  let model = this._model;
                  let joins = this._model._getModel()._joins;
              
              
              Severity: Major
              Found in lib/query.js - About 4 hrs to fix

                Function removeRelation has 105 lines of code (exceeds 25 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: Major
                Found in lib/query.js - About 4 hrs to fix

                  Function setSaved has 100 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    setSaved(all) {
                      this.__proto__._saved = true; // eslint-disable-line
                      if (all !== true) return;
                      util.loopKeys(this._getModel()._joins, (joins, key) => {
                        switch (joins[key].type) { // eslint-disable-line
                  Severity: Major
                  Found in lib/document.js - About 4 hrs to fix

                    Function hasAndBelongsToMany has 100 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      hasAndBelongsToMany(joinedModel, fieldDoc, leftKey, rightKey, options) {
                        let link;
                        let thinkagain = this._getModel()._thinkagain;
                        options = options || {};
                    
                    
                    Severity: Major
                    Found in lib/model.js - About 4 hrs to fix

                      Function addRelation has 99 lines of code (exceeds 25 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: Major
                      Found in lib/query.js - About 3 hrs to fix

                        Function _saveLinks has 85 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          _saveLinks(docToSave, saveAll) {
                            let model = this._getModel();
                            let constructor = this.getModel();
                            let r = model._thinkagain.r;
                        
                        
                        Severity: Major
                        Found in lib/document.js - About 3 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language