sequelize/sequelize

View on GitHub

Showing 804 of 804 total issues

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}`);
      } else {
        joinQueries.subQuery.push(` ${joinQuery.join} ${joinQuery.body} ON ${joinQuery.condition}`);
Severity: Major
Found in lib/dialects/abstract/query-generator.js and 1 other location - About 7 hrs to fix
lib/dialects/abstract/query-generator.js on lines 1536..1546

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}`);
      } else {
        joinQueries.mainQuery.push(` ${joinQuery.join} ${joinQuery.body} ON ${joinQuery.condition}`);
Severity: Major
Found in lib/dialects/abstract/query-generator.js and 1 other location - About 7 hrs to fix
lib/dialects/abstract/query-generator.js on lines 1526..1536

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

  _handleQueryResponse(metaData, columnTypes, benchmark, queryBegin, err, results) {
    debug(`executed(${this.database.uuid || 'default'}) : ${this.sql}`);

    if (benchmark) {
      this.sequelize.log(`Executed (${this.database.uuid || 'default'}): ${this.sql}`, Date.now() - queryBegin, this.options);
Severity: Minor
Found in lib/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 _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 lib/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

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

'use strict';

const _ = require('lodash');
const wkx = require('wkx');
const inherits = require('../../utils/inherits');
Severity: Minor
Found in lib/dialects/postgres/data-types.js - About 7 hrs to fix

    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 lib/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

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

    class MSSQLQueryGenerator extends AbstractQueryGenerator {
      createDatabaseQuery(databaseName, options) {
        options = Object.assign({
          collate: null
        }, options || {});
    Severity: Minor
    Found in lib/dialects/mssql/query-generator.js - About 6 hrs to fix

      Function update has 155 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static update(values, options) {
          options = Utils.cloneDeep(options);
      
          this._injectScope(options);
          this._optionsMustContainWhere(options);
      Severity: Major
      Found in lib/model.js - About 6 hrs to fix

        Function updateQuery has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
        Open

          updateQuery(tableName, attrValueHash, where, options, attributes) {
            options = options || {};
            _.defaults(options, this.options);
        
            attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, options.omitNull, options);
        Severity: Minor
        Found in lib/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

        Function get has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
        Open

          get(key, options) { // testhint options:none
            if (options === undefined && typeof key === 'object') {
              options = key;
              key = undefined;
            }
        Severity: Minor
        Found in lib/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

        File utils.js has 416 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        'use strict';
        
        const DataTypes = require('./data-types');
        const SqlString = require('./sql-string');
        const _ = require('lodash');
        Severity: Minor
        Found in lib/utils.js - About 6 hrs to fix

          Function refreshAttributes has 149 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static refreshAttributes() {
              const attributeManipulation = {};
          
              this.prototype._customGetters = {};
              this.prototype._customSetters = {};
          Severity: Major
          Found in lib/model.js - About 5 hrs to fix

            Function upsertQuery has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
            Open

              upsertQuery(tableName, insertValues, updateValues, where, model) {
                const targetTableAlias = this.quoteTable(`${tableName}_target`);
                const sourceTableAlias = this.quoteTable(`${tableName}_source`);
                const primaryKeysAttrs = [];
                const identityAttrs = [];
            Severity: Minor
            Found in lib/dialects/mssql/query-generator.js - About 5 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 39 (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 lib/sequelize.js - About 5 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 (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
                    values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' })}`);
                  } else {
                    values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' }, bindParam)}`);
                  }
            Severity: Major
            Found in lib/dialects/abstract/query-generator.js and 1 other location - About 5 hrs to fix
            lib/dialects/sqlite/query-generator.js on lines 241..245

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

            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

                this.accessors = {
                  get: `get${plural}`,
                  set: `set${plural}`,
                  addMultiple: `add${plural}`,
                  add: `add${singular}`,
            Severity: Major
            Found in lib/associations/belongs-to-many.js and 1 other location - About 5 hrs to fix
            lib/associations/has-many.js on lines 98..109

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

            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 (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
                    values.push(`${this.quoteIdentifier(key)}=${this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' })}`);
                  } else {
                    values.push(`${this.quoteIdentifier(key)}=${this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' }, bindParam)}`);
                  }
            Severity: Major
            Found in lib/dialects/sqlite/query-generator.js and 1 other location - About 5 hrs to fix
            lib/dialects/abstract/query-generator.js on lines 401..405

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

            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

                this.accessors = {
                  get: `get${plural}`,
                  set: `set${plural}`,
                  addMultiple: `add${plural}`,
                  add: `add${singular}`,
            Severity: Major
            Found in lib/associations/has-many.js and 1 other location - About 5 hrs to fix
            lib/associations/belongs-to-many.js on lines 207..218

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

            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 (options.uniqueKeys) {
                  _.each(options.uniqueKeys, (columns, indexName) => {
                    if (columns.customIndex) {
                      if (typeof indexName !== 'string') {
                        indexName = `uniq_${tableName}_${columns.fields.join('_')}`;
            Severity: Major
            Found in lib/dialects/mssql/query-generator.js and 1 other location - About 5 hrs to fix
            lib/dialects/mysql/query-generator.js on lines 114..123

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

            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 (options.uniqueKeys) {
                  _.each(options.uniqueKeys, (columns, indexName) => {
                    if (columns.customIndex) {
                      if (typeof indexName !== 'string') {
                        indexName = `uniq_${tableName}_${columns.fields.join('_')}`;
            Severity: Major
            Found in lib/dialects/mysql/query-generator.js and 1 other location - About 5 hrs to fix
            lib/dialects/mssql/query-generator.js on lines 156..165

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

            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