sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

Function _validateIncludedElements has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  static _validateIncludedElements(options, tableNames) {
    if (!options.model) options.model = this;

    tableNames = tableNames || {};
    options.includeNames = [];
Severity: Minor
Found in src/model.js - About 4 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

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

      if (this._dialect.supports.inserts.updateOnDuplicate == ' ON CONFLICT DO UPDATE SET') {
        // postgres / sqlite
        // If no conflict target columns were specified, use the primary key names from options.upsertKeys
        const conflictKeys = options.upsertKeys.map(attr => this.quoteIdentifier(attr));
        const updateKeys = options.updateOnDuplicate.map(
Severity: Major
Found in src/dialects/abstract/query-generator.js and 1 other location - About 4 hrs to fix
src/dialects/abstract/query-generator.js on lines 300..314

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

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

      if (this._dialect.supports.inserts.updateOnDuplicate == ' ON CONFLICT DO UPDATE SET') {
        // postgres / sqlite
        // If no conflict target columns were specified, use the primary key names from options.upsertKeys
        const conflictKeys = options.upsertKeys.map(attr => this.quoteIdentifier(attr));
        const updateKeys = options.updateOnDuplicate.map(
Severity: Major
Found in src/dialects/abstract/query-generator.js and 1 other location - About 4 hrs to fix
src/dialects/abstract/query-generator.js on lines 191..204

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

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

  async connect(config) {
    config.user = config.username;
    const connectionConfig = _.pick(config, ['user', 'password', 'host', 'database', 'port']);

    connectionConfig.types = {
Severity: Major
Found in src/dialects/postgres/connection-manager.js - About 4 hrs to fix

    Function exports has 113 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = BaseTypes => {
      BaseTypes.ABSTRACT.prototype.dialectTypes = 'https://dev.mysql.com/doc/refman/5.7/en/data-types.html';
    
      /**
       * types: [buffer_type, ...]
    Severity: Major
    Found in src/dialects/mysql/data-types.js - About 4 hrs to fix

      Function _whereParseSingleValueObject has 113 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _whereParseSingleValueObject(key, field, prop, value, options) {
          if (prop === Op.not) {
            if (Array.isArray(value)) {
              prop = Op.notIn;
            } else if (value !== null && value !== true && value !== false) {
      Severity: Major
      Found in src/dialects/abstract/query-generator.js - About 4 hrs to fix

        Function generateThroughJoin has 113 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          generateThroughJoin(include, includeAs, parentTableName, topLevelInfo) {
            const through = include.through;
            const throughTable = through.model.getTableName();
            const throughAs = `${includeAs.internalAs}->${through.as}`;
            const externalThroughAs = `${includeAs.externalAs}.${through.as}`;
        Severity: Major
        Found in src/dialects/abstract/query-generator.js - About 4 hrs to fix

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

                if (
                  this.constructor._timestampAttributes.deletedAt &&
                  defaults[this.constructor._timestampAttributes.deletedAt]
                ) {
                  this.dataValues[this.constructor._timestampAttributes.deletedAt] = Utils.toDefaultValue(
          Severity: Major
          Found in src/model.js and 2 other locations - About 4 hrs to fix
          src/model.js on lines 181..190
          src/model.js on lines 192..201

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

          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 3 locations. Consider refactoring.
          Open

                if (
                  this.constructor._timestampAttributes.updatedAt &&
                  defaults[this.constructor._timestampAttributes.updatedAt]
                ) {
                  this.dataValues[this.constructor._timestampAttributes.updatedAt] = Utils.toDefaultValue(
          Severity: Major
          Found in src/model.js and 2 other locations - About 4 hrs to fix
          src/model.js on lines 181..190
          src/model.js on lines 203..212

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

          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 3 locations. Consider refactoring.
          Open

                if (
                  this.constructor._timestampAttributes.createdAt &&
                  defaults[this.constructor._timestampAttributes.createdAt]
                ) {
                  this.dataValues[this.constructor._timestampAttributes.createdAt] = Utils.toDefaultValue(
          Severity: Major
          Found in src/model.js and 2 other locations - About 4 hrs to fix
          src/model.js on lines 192..201
          src/model.js on lines 203..212

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

          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.js has 351 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          const AbstractQuery = require('../abstract/query');
          const sequelizeErrors = require('../../errors');
          const parserStore = require('../parserStore')('mssql');
          const _ = require('lodash');
          const { logger } = require('../../utils/logger');
          Severity: Minor
          Found in src/dialects/mssql/query.js - About 4 hrs to fix

            Function exports has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
            Open

            module.exports = BaseTypes => {
              const warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'https://www.sqlite.org/datatype3.html');
            
              /**
               * Removes unsupported SQLite options, i.e., UNSIGNED and ZEROFILL, for the integer data types.
            Severity: Minor
            Found in src/dialects/sqlite/data-types.js - About 4 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 set has 110 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              set(key, value, options) {
                let values;
                let originalValue;
            
                if (typeof key === 'object' && key !== null) {
            Severity: Major
            Found in src/model.js - About 4 hrs to fix

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

                  static parse(value, options) {
                    value = value.string();
                    if (value === null) {
                      return value;
                    }
              Severity: Major
              Found in src/dialects/mariadb/data-types.js and 1 other location - About 4 hrs to fix
              src/dialects/mysql/data-types.js on lines 61..72

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

              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

                  static parse(value, options) {
                    value = value.string();
                    if (value === null) {
                      return value;
                    }
              Severity: Major
              Found in src/dialects/mysql/data-types.js and 1 other location - About 4 hrs to fix
              src/dialects/mariadb/data-types.js on lines 58..69

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

              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 (instances) {
                    const results = await Target.findAll(options);
                    const result = {};
                    for (const _instance of instances) {
                      result[_instance.get(this.sourceKey, { raw: true })] = null;
              Severity: Major
              Found in src/associations/has-one.js and 1 other location - About 4 hrs to fix
              src/associations/belongs-to.js on lines 163..175

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

              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 (instances) {
                    const results = await Target.findAll(options);
                    const result = {};
                    for (const _instance of instances) {
                      result[_instance.get(this.foreignKey, { raw: true })] = null;
              Severity: Major
              Found in src/associations/belongs-to.js and 1 other location - About 4 hrs to fix
              src/associations/has-one.js on lines 165..177

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

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

              module.exports = BaseTypes => {
                BaseTypes.ABSTRACT.prototype.dialectTypes = 'https://mariadb.com/kb/en/library/resultset/#field-types';
              
                /**
                 * types: [buffer_type, ...]
              Severity: Major
              Found in src/dialects/mariadb/data-types.js - About 4 hrs to fix

                Function _injectAttributes has 105 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _injectAttributes() {
                    this.identifier = this.foreignKey;
                    this.foreignIdentifier = this.otherKey;
                
                    // remove any PKs previously defined by sequelize
                Severity: Major
                Found in src/associations/belongs-to-many.js - About 4 hrs to fix

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

                      if (this.as) {
                        this.isAliased = true;
                  
                        if (_.isPlainObject(this.as)) {
                          this.options.name = this.as;
                  Severity: Major
                  Found in src/associations/belongs-to-many.js and 1 other location - About 4 hrs to fix
                  src/associations/has-many.js on lines 36..51

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

                  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