sequelize/sequelize

View on GitHub

Showing 763 of 763 total issues

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

'use strict';

const assert = require('assert');
const _ = require('lodash');
const Dottie = require('dottie');
Severity: Major
Found in lib/model.js - About 1 wk to fix

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

    'use strict';
    
    const util = require('util');
    const _ = require('lodash');
    const uuidv4 = require('uuid/v4');
    Severity: Major
    Found in lib/dialects/abstract/query-generator.js - About 5 days to fix

      Function _groupJoinData has a Cognitive Complexity of 251 (exceeds 5 allowed). Consider refactoring.
      Open

        static _groupJoinData(rows, includeOptions, options) {
      
          /*
           * Assumptions
           * ID is not necessarily the first field
      Severity: Minor
      Found in lib/dialects/abstract/query.js - About 5 days 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 exports has a Cognitive Complexity of 144 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = BaseTypes => {
        const warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'http://www.postgresql.org/docs/9.4/static/datatype.html');
      
        /**
         * Removes unsupported Postgres options, i.e., LENGTH, UNSIGNED and ZEROFILL, for the integer data types.
      Severity: Minor
      Found in lib/dialects/postgres/data-types.js - About 2 days 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 (smth instanceof Utils.Json) {
            // Parse nested object
            if (smth.conditions) {
              const conditions = this.parseConditionObject(smth.conditions).map(
                condition =>
      Severity: Major
      Found in lib/dialects/mariadb/query-generator.js and 1 other location - About 2 days to fix
      lib/dialects/mysql/query-generator.js on lines 208..264

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

      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 (smth instanceof Utils.Json) {
            // Parse nested object
            if (smth.conditions) {
              const conditions = this.parseConditionObject(smth.conditions).map(condition =>
                `${this.quoteIdentifier(condition.path[0])}->>'$.${_.tail(condition.path).join('.')}' = '${condition.value}'`
      Severity: Major
      Found in lib/dialects/mysql/query-generator.js and 1 other location - About 2 days to fix
      lib/dialects/mariadb/query-generator.js on lines 36..97

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

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

      module.exports = BaseTypes => {
        const warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'http://www.postgresql.org/docs/9.4/static/datatype.html');
      
        /**
         * Removes unsupported Postgres options, i.e., LENGTH, UNSIGNED and ZEROFILL, for the integer data types.
      Severity: Major
      Found in lib/dialects/postgres/data-types.js - About 2 days to fix

        Function selectQuery has a Cognitive Complexity of 107 (exceeds 5 allowed). Consider refactoring.
        Open

          selectQuery(tableName, options, model) {
            options = options || {};
            const limit = options.limit;
            const mainQueryItems = [];
            const subQueryItems = [];
        Severity: Minor
        Found in lib/dialects/abstract/query-generator.js - About 2 days 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 (length) {
                      for (i = 0; i < length; i++) {
                        prefix = $parent ? `${$parent}.${$prevKeyPrefix[i]}` : $prevKeyPrefix[i];
                        primaryKeyAttributes = includeMap[prefix].model.primaryKeyAttributes;
                        $length = primaryKeyAttributes.length;
        Severity: Major
        Found in lib/dialects/abstract/query.js and 1 other location - About 2 days to fix
        lib/dialects/abstract/query.js on lines 658..690

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

        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 (length) {
                  for (i = 0; i < length; i++) {
                    prefix = $parent ? `${$parent}.${$prevKeyPrefix[i]}` : $prevKeyPrefix[i];
                    primaryKeyAttributes = includeMap[prefix].model.primaryKeyAttributes;
                    $length = primaryKeyAttributes.length;
        Severity: Major
        Found in lib/dialects/abstract/query.js and 1 other location - About 2 days to fix
        lib/dialects/abstract/query.js on lines 571..603

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

        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

          _injectAttributes() {
            const newAttributes = {};
        
            newAttributes[this.foreignKey] = _.defaults({}, this.foreignKeyAttribute, {
              type: this.options.keyType || this.source.rawAttributes[this.sourceKey].type,
        Severity: Major
        Found in lib/associations/has-one.js and 1 other location - About 1 day to fix
        lib/associations/belongs-to.js on lines 81..105

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

        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

          _injectAttributes() {
            const newAttributes = {};
        
            newAttributes[this.foreignKey] = _.defaults({}, this.foreignKeyAttribute, {
              type: this.options.keyType || this.target.rawAttributes[this.targetKey].type,
        Severity: Major
        Found in lib/associations/belongs-to.js and 1 other location - About 1 day to fix
        lib/associations/has-one.js on lines 80..104

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

        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 94 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Model {
          static get QueryInterface() {
            return this.sequelize.getQueryInterface();
          }
        
        
        Severity: Major
        Found in lib/model.js - About 1 day to fix

          Function set has a Cognitive Complexity of 86 (exceeds 5 allowed). Consider refactoring.
          Open

            set(key, value, options) {
              let values;
              let originalValue;
          
              if (typeof key === 'object' && key !== null) {
          Severity: Minor
          Found in lib/model.js - About 1 day 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

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

          'use strict';
          
          const _ = require('lodash');
          
          const Utils = require('./utils');
          Severity: Major
          Found in lib/query-interface.js - About 1 day to fix

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

            'use strict';
            
            const Utils = require('../../utils');
            const util = require('util');
            const DataTypes = require('../../data-types');
            Severity: Major
            Found in lib/dialects/postgres/query-generator.js - About 1 day to fix

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

              'use strict';
              
              const _ = require('lodash');
              const Utils = require('../../utils');
              const DataTypes = require('../../data-types');
              Severity: Major
              Found in lib/dialects/mssql/query-generator.js - About 1 day to fix

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

                      if (dataType.includes('PRIMARY KEY')) {
                        primaryKeys.push(attr);
                
                        if (dataType.includes('REFERENCES')) {
                          // MySQL doesn't support inline REFERENCES declarations: move to the end
                Severity: Major
                Found in lib/dialects/mysql/query-generator.js and 1 other location - About 1 day to fix
                lib/dialects/mssql/query-generator.js on lines 130..148

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

                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 (dataType.includes('PRIMARY KEY')) {
                          primaryKeys.push(attr);
                
                          if (dataType.includes('REFERENCES')) {
                            // MSSQL doesn't support inline REFERENCES declarations: move to the end
                Severity: Major
                Found in lib/dialects/mssql/query-generator.js and 1 other location - About 1 day to fix
                lib/dialects/mysql/query-generator.js on lines 83..101

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

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

                  generateInclude(include, parentTableName, topLevelInfo) {
                    const joinQueries = {
                      mainQuery: [],
                      subQuery: []
                    };
                Severity: Minor
                Found in lib/dialects/abstract/query-generator.js - About 1 day 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

                Severity
                Category
                Status
                Source
                Language