sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

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/has-many.js and 1 other location - About 4 hrs to fix
src/associations/belongs-to-many.js on lines 83..98

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

Function _validateIncludedElement has 103 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static _validateIncludedElement(include, tableNames, options) {
    tableNames[include.model.getTableName()] = true;

    if (include.attributes && !options.raw) {
      include.model._expandAttributes(include);
Severity: Major
Found in src/model.js - About 4 hrs to fix

    Function addLimitAndOffset has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

      addLimitAndOffset(options, model) {
        // Skip handling of limit and offset as postfixes for older SQL Server versions
        if (
          semver.valid(this.sequelize.options.databaseVersion) &&
          semver.lt(this.sequelize.options.databaseVersion, '11.0.0')
    Severity: Minor
    Found in src/dialects/mssql/query-generator.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 exports has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = BaseTypes => {
      const warn = BaseTypes.ABSTRACT.warn.bind(
        undefined,
        'https://msdn.microsoft.com/en-us/library/ms187752%28v=sql.110%29.aspx'
      );
    Severity: Minor
    Found in src/dialects/mssql/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 ensureEnums has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async ensureEnums(tableName, attributes, options, model) {
        const keys = Object.keys(attributes);
        const keyLen = keys.length;
    
        let sql = '';
    Severity: Major
    Found in src/dialects/postgres/query-interface.js - About 4 hrs to fix

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

        createDatabaseQuery(databaseName, options) {
          options = {
            charset: null,
            collate: null,
            ...options
      Severity: Major
      Found in src/dialects/mysql/query-generator.js and 1 other location - About 3 hrs to fix
      src/dialects/mariadb/query-generator.js on lines 5..19

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

      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

        createSchema(schema, options) {
          options = {
            charset: null,
            collate: null,
            ...options
      Severity: Major
      Found in src/dialects/mariadb/query-generator.js and 1 other location - About 3 hrs to fix
      src/dialects/mysql/query-generator.js on lines 38..52

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

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

        async connect(config) {
          const connectionConfig = {
            server: config.host,
            authentication: {
              type: 'default',
      Severity: Minor
      Found in src/dialects/mssql/connection-manager.js - About 3 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 connect has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        async connect(config) {
          config.user = config.username;
          const connectionConfig = _.pick(config, ['user', 'password', 'host', 'database', 'port']);
      
          connectionConfig.types = {
      Severity: Minor
      Found in src/dialects/postgres/connection-manager.js - About 3 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

        static formatBindParameters(sql, values, dialect) {
          const bindParam = [];
          const replacementFunc = (match, key, val) => {
            if (val[key] !== undefined) {
              bindParam.push(val[key]);
      Severity: Major
      Found in src/dialects/mariadb/query.js and 1 other location - About 3 hrs to fix
      src/dialects/mysql/query.js on lines 13..24

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

      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

        static formatBindParameters(sql, values, dialect) {
          const bindParam = [];
          const replacementFunc = (match, key, values) => {
            if (values[key] !== undefined) {
              bindParam.push(values[key]);
      Severity: Major
      Found in src/dialects/mysql/query.js and 1 other location - About 3 hrs to fix
      src/dialects/mariadb/query.js on lines 18..29

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

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

        whereItemQuery(key, value, options = {}) {
          if (value === undefined) {
            throw new Error(`WHERE parameter "${key}" has invalid "undefined" value`);
          }
      
      
      Severity: Major
      Found in src/dialects/abstract/query-generator.js - About 3 hrs to fix

        File has-many.js has 324 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        const Utils = require('./../utils');
        const Helpers = require('./helpers');
        const _ = require('lodash');
        const Association = require('./base');
        const Op = require('../operators');
        Severity: Minor
        Found in src/associations/has-many.js - About 3 hrs to fix

          Function connect has 94 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async connect(config) {
              const connectionConfig = {
                server: config.host,
                authentication: {
                  type: 'default',
          Severity: Major
          Found in src/dialects/mssql/connection-manager.js - About 3 hrs to fix

            Function attributeToSQL has 94 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              attributeToSQL(attribute, options) {
                if (!_.isPlainObject(attribute)) {
                  attribute = {
                    type: attribute
                  };
            Severity: Major
            Found in src/dialects/postgres/query-generator.js - About 3 hrs to fix

              Function query has 93 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async query(sql, options) {
                  options = { ...this.options.query, ...options };
              
                  if (options.instance && !options.model) {
                    options.model = options.instance.constructor;
              Severity: Major
              Found in src/sequelize.js - About 3 hrs to fix

                Function _generateSubQueryFilter has 93 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _generateSubQueryFilter(include, includeAs, topLevelInfo) {
                    if (!topLevelInfo.subQuery || !include.subQueryFilter) {
                      return;
                    }
                
                
                Severity: Major
                Found in src/dialects/abstract/query-generator.js - About 3 hrs to fix

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

                      if (_.isObject(this.options.foreignKey)) {
                        this.foreignKeyAttribute = this.options.foreignKey;
                        this.foreignKey = this.foreignKeyAttribute.name || this.foreignKeyAttribute.fieldName;
                      } else if (this.options.foreignKey) {
                        this.foreignKey = this.options.foreignKey;
                  Severity: Major
                  Found in src/associations/has-one.js and 1 other location - About 3 hrs to fix
                  src/associations/belongs-to.js on lines 32..37

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

                  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 (_.isObject(this.options.foreignKey)) {
                        this.foreignKeyAttribute = this.options.foreignKey;
                        this.foreignKey = this.foreignKeyAttribute.name || this.foreignKeyAttribute.fieldName;
                      } else if (this.options.foreignKey) {
                        this.foreignKey = this.options.foreignKey;
                  Severity: Major
                  Found in src/associations/belongs-to.js and 1 other location - About 3 hrs to fix
                  src/associations/has-one.js on lines 33..38

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

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

                    formatError(err) {
                      switch (err.errno) {
                        case ER_DUP_ENTRY: {
                          const match = err.message.match(/Duplicate entry '([\s\S]*)' for key '?((.|\s)*?)'?\s.*$/);
                  
                  
                  Severity: Minor
                  Found in src/dialects/mariadb/query.js - About 3 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

                  Severity
                  Category
                  Status
                  Source
                  Language