sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

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

                  if (instance[include.association.through.model.name]) {
                    for (const attr of Object.keys(include.association.through.model.rawAttributes)) {
                      if (
                        include.association.through.model.rawAttributes[attr]._autoGenerated ||
                        attr === include.association.foreignKey ||
Severity: Major
Found in src/model.js and 1 other location - About 1 day to fix
src/model.js on lines 2942..2954

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

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

  async ensureEnums(tableName, attributes, options, model) {
    const keys = Object.keys(attributes);
    const keyLen = keys.length;

    let sql = '';
Severity: Minor
Found in src/dialects/postgres/query-interface.js - About 7 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

PostgresQueryGenerator has 55 functions (exceeds 20 allowed). Consider refactoring.
Open

class PostgresQueryGenerator extends AbstractQueryGenerator {
  setSearchPath(searchPath) {
    return `SET search_path to ${searchPath};`;
  }

Severity: Major
Found in src/dialects/postgres/query-generator.js - About 7 hrs to fix

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

        if (include.subQuery && topLevelInfo.subQuery) {
          if (requiredMismatch && subChildIncludes.length > 0) {
            joinQueries.subQuery.push(
              ` ${joinQuery.join} ( ${joinQuery.body}${subChildIncludes.join('')} ) ON ${joinQuery.condition}`
            );
    Severity: Major
    Found in src/dialects/abstract/query-generator.js and 1 other location - About 7 hrs to fix
    src/dialects/abstract/query-generator.js on lines 1702..1714

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

    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

        } else {
          if (requiredMismatch && mainChildIncludes.length > 0) {
            joinQueries.mainQuery.push(
              ` ${joinQuery.join} ( ${joinQuery.body}${mainChildIncludes.join('')} ) ON ${joinQuery.condition}`
            );
    Severity: Major
    Found in src/dialects/abstract/query-generator.js and 1 other location - About 7 hrs to fix
    src/dialects/abstract/query-generator.js on lines 1690..1702

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

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

      insertQuery(table, valueHash, modelAttributes, options) {
        options = options || {};
        _.defaults(options, this.options);
    
        const modelAttributeMap = {};
    Severity: Minor
    Found in src/dialects/abstract/query-generator.js - About 7 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 _expandIncludeAllElement has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

      static _expandIncludeAllElement(includes, include) {
        // check 'all' attribute provided is valid
        let all = include.all;
        delete include.all;
    
    
    Severity: Minor
    Found in src/model.js - About 7 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 constructor has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

      constructor(database, username, password, options) {
        let config;
    
        if (arguments.length === 1 && typeof database === 'object') {
          // new Sequelize({ ... options })
    Severity: Minor
    Found in src/sequelize.js - About 7 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 whereItemQuery has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

      whereItemQuery(key, value, options = {}) {
        if (value === undefined) {
          throw new Error(`WHERE parameter "${key}" has invalid "undefined" value`);
        }
    
    
    Severity: Minor
    Found in src/dialects/abstract/query-generator.js - About 7 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

    QueryInterface has 52 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class QueryInterface {
      constructor(sequelize, queryGenerator) {
        this.sequelize = sequelize;
        this.queryGenerator = queryGenerator;
      }
    Severity: Major
    Found in src/dialects/abstract/query-interface.js - About 7 hrs to fix

      Function _handleQueryResponse has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
      Open

        _handleQueryResponse(metaData, columnTypes, err, results) {
          if (err) {
            err.sql = this.sql;
            throw this.formatError(err);
          }
      Severity: Minor
      Found in src/dialects/sqlite/query.js - About 7 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 179 lines of code (exceeds 25 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: Major
      Found in src/dialects/mssql/data-types.js - About 7 hrs to fix

        Function handleSequelizeMethod has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
        Open

          handleSequelizeMethod(smth, tableName, factory, options, prepend) {
            let result;
        
            if (Object.prototype.hasOwnProperty.call(this.OperatorMap, smth.comparator)) {
              smth.comparator = this.OperatorMap[smth.comparator];
        Severity: Minor
        Found in src/dialects/abstract/query-generator.js - About 7 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 175 lines of code (exceeds 25 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: Major
        Found in src/dialects/sqlite/data-types.js - About 7 hrs to fix

          Function attributeToSQL has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
          Open

            attributeToSQL(attribute, options) {
              if (!_.isPlainObject(attribute)) {
                attribute = {
                  type: attribute
                };
          Severity: Minor
          Found in src/dialects/postgres/query-generator.js - About 6 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

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

          const _ = require('lodash');
          const Utils = require('../../utils');
          const AbstractQueryGenerator = require('../abstract/query-generator');
          const util = require('util');
          const Op = require('../../operators');
          Severity: Minor
          Found in src/dialects/mysql/query-generator.js - About 6 hrs to fix

            File data-types.js has 445 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            const _ = require('lodash');
            const wkx = require('wkx');
            
            module.exports = BaseTypes => {
              const warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'http://www.postgresql.org/docs/9.4/static/datatype.html');
            Severity: Minor
            Found in src/dialects/postgres/data-types.js - About 6 hrs to fix

              MSSQLQueryGenerator has 47 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class MSSQLQueryGenerator extends AbstractQueryGenerator {
                createDatabaseQuery(databaseName, options) {
                  options = { collate: null, ...options };
              
                  const collation = options.collate ? `COLLATE ${this.escape(options.collate)}` : '';
              Severity: Minor
              Found in src/dialects/mssql/query-generator.js - About 6 hrs to fix

                Function update has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
                Open

                  static async update(values, options) {
                    options = Utils.cloneDeep(options);
                
                    this._injectScope(options);
                    this._optionsMustContainWhere(options);
                Severity: Minor
                Found in src/model.js - About 6 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 addIndexQuery has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                Open

                  addIndexQuery(tableName, attributes, options, rawTablename) {
                    options = options || {};
                
                    if (!Array.isArray(attributes)) {
                      options = attributes;
                Severity: Minor
                Found in src/dialects/abstract/query-generator.js - About 6 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