sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

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

const assert = require('assert');
const _ = require('lodash');
const Dottie = require('dottie');

const Utils = require('./utils');
Severity: Major
Found in src/model.js - About 1 wk to fix

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

    const util = require('util');
    const _ = require('lodash');
    const uuidv4 = require('uuid').v4;
    
    const Utils = require('../../utils');
    Severity: Major
    Found in src/dialects/abstract/query-generator.js - About 6 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
           * All fields for a level is grouped in the same set (i.e. Panel.id, Task.id, Panel.title is not possible)
      Severity: Minor
      Found in src/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 src/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

      Function run has a Cognitive Complexity of 120 (exceeds 5 allowed). Consider refactoring.
      Open

        async run(sql, parameters) {
          const { connection } = this;
      
          if (!_.isEmpty(this.options.searchPath)) {
            sql = this.sequelize.getQueryInterface().queryGenerator.setSearchPath(this.options.searchPath) + sql;
      Severity: Minor
      Found in src/dialects/postgres/query.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

      Function exports has 441 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 src/dialects/postgres/data-types.js - About 2 days to fix

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

          selectQuery(tableName, options, model) {
            options = options || {};
            const limit = options.limit;
            const mainQueryItems = [];
            const subQueryItems = [];
        Severity: Minor
        Found in src/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 src/dialects/abstract/query.js and 1 other location - About 2 days to fix
        src/dialects/abstract/query.js on lines 674..704

        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 src/dialects/abstract/query.js and 1 other location - About 2 days to fix
        src/dialects/abstract/query.js on lines 589..619

        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

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

        const _ = require('lodash');
        const Utils = require('../../utils');
        const DataTypes = require('../../data-types');
        const TableHints = require('../../table-hints');
        const AbstractQueryGenerator = require('../abstract/query-generator');
        Severity: Major
        Found in src/dialects/mssql/query-generator.js - About 1 day to fix

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

            _injectAttributes() {
              const newAttributes = {
                [this.foreignKey]: {
                  type: this.options.keyType || this.source.rawAttributes[this.sourceKey].type,
                  allowNull: true,
          Severity: Major
          Found in src/associations/has-one.js and 1 other location - About 1 day to fix
          src/associations/belongs-to.js on lines 73..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 321.

          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 = {
                [this.foreignKey]: {
                  type: this.options.keyType || this.target.rawAttributes[this.targetKey].type,
                  allowNull: true,
          Severity: Major
          Found in src/associations/belongs-to.js and 1 other location - About 1 day to fix
          src/associations/has-one.js on lines 74..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 321.

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

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

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

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

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

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

              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 src/dialects/mssql/query-generator.js and 1 other location - About 1 day to fix
              src/dialects/mysql/query-generator.js on lines 87..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 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')) {
                        // MySQL doesn't support inline REFERENCES declarations: move to the end
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 day to fix
              src/dialects/mssql/query-generator.js on lines 142..160

              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 77 (exceeds 5 allowed). Consider refactoring.
              Open

                generateInclude(include, parentTableName, topLevelInfo) {
                  const joinQueries = {
                    mainQuery: [],
                    subQuery: []
                  };
              Severity: Minor
              Found in src/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

              Function bulkCreate has 305 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                static async bulkCreate(records, options = {}) {
                  if (!records.length) {
                    return [];
                  }
              
              
              Severity: Major
              Found in src/model.js - About 1 day to fix

                Function recursiveBulkCreate has 288 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    const recursiveBulkCreate = async (instances, options) => {
                      options = {
                        validate: false,
                        hooks: true,
                        individualHooks: false,
                Severity: Major
                Found in src/model.js - About 1 day to fix
                  Severity
                  Category
                  Status
                  Source
                  Language