sequelize/sequelize

View on GitHub

Showing 503 of 787 total issues

Avoid deeply nested control flow statements.
Open

            if (i < length - 1) {
              parentHash = itemHash;
            }
Severity: Major
Found in src/dialects/abstract/query.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

              if (includeMap[prevKey].association.isSingleAssociation) {
                if ($parent) {
                  $parent[$lastKeyPrefix] = resultMap[itemHash] = values;
                }
              } else {
    Severity: Major
    Found in src/dialects/abstract/query.js - About 45 mins to fix

      Function _createForeignAndOtherKeys has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        _createForeignAndOtherKeys() {
          /*
           * Default/generated foreign/other keys
           */
          if (_.isObject(this.options.foreignKey)) {
      Severity: Minor
      Found in src/associations/belongs-to-many.js - About 45 mins 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

      Avoid deeply nested control flow statements.
      Open

                  if (_.isObject(dep)) {
                    deps.push(`${dep.schema}.${dep.tableName}`);
                  } else {
                    deps.push(dep);
                  }
      Severity: Major
      Found in src/model-manager.ts - About 45 mins to fix

        Function create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          async create(sourceInstance, values, options) {
            values = values || {};
            options = options || {};
        
            if (this.scope) {
        Severity: Minor
        Found in src/associations/has-one.js - About 45 mins 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 getValidatorKey has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          getValidatorKey(useTypeAsNS: boolean, NSSeparator: string): string {
            const useTANS = useTypeAsNS === undefined || !!useTypeAsNS;
            const NSSep = NSSeparator === undefined ? '.' : NSSeparator;
        
            const type = this.origin;
        Severity: Minor
        Found in src/errors/validation-error.ts - About 45 mins 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

        Consider simplifying this complex logical expression.
        Open

            } else if (
              (arguments.length === 1 && typeof database === 'string') ||
              (arguments.length === 2 && typeof username === 'object')
            ) {
              // new Sequelize(URI, { ... options })
        Severity: Major
        Found in src/sequelize.js - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                if (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
                  values.push(
                    `${this.quoteIdentifier(key)}=${this.escape(
                      value,
                      (modelAttributeMap && modelAttributeMap[key]) || undefined,
          Severity: Major
          Found in src/dialects/abstract/query-generator.js - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                if (topLevelInfo.subQuery && !include.subQuery && include.parent.subQuery && !parentIsTop) {
                  // If we are minifying aliases and our JOIN target has been minified, we need to use the alias instead of the original column name
                  const joinSource =
                    this._getAliasForField(tableSource, `${tableSource}.${attrSource}`, topLevelInfo.options) ||
                    `${tableSource}.${attrSource}`;
            Severity: Major
            Found in src/dialects/abstract/query-generator.js - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                        if (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
                          values.push(
                            this.escape(value, (modelAttributeMap && modelAttributeMap[key]) || undefined, { context: 'INSERT' })
                          );
                        } else {
              Severity: Major
              Found in src/dialects/abstract/query-generator.js - About 40 mins to fix

                Consider simplifying this complex logical expression.
                Open

                      if (Object.prototype.hasOwnProperty.call(definition, 'unique') && definition.unique) {
                        let idxName;
                        if (typeof definition.unique === 'object' && Object.prototype.hasOwnProperty.call(definition.unique, 'name')) {
                          idxName = definition.unique.name;
                        } else if (typeof definition.unique === 'string') {
                Severity: Major
                Found in src/model.js - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                      if (!tableName.schema && (options.schema || (!!model && model._schema))) {
                        tableName = this.queryGenerator.addSchema({
                          tableName,
                          _schema: (!!model && model._schema) || options.schema
                        });
                  Severity: Major
                  Found in src/dialects/abstract/query-interface.js - About 40 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                          if (value instanceof Utils.SequelizeMethod || options.bindParam === false) {
                            values.push(
                              `${this.quoteIdentifier(key)}=${this.escape(
                                value,
                                (modelAttributeMap && modelAttributeMap[key]) || undefined,
                    Severity: Major
                    Found in src/dialects/sqlite/query-generator.js - About 40 mins to fix

                      Consider simplifying this complex logical expression.
                      Open

                          if (
                            originalValue &&
                            !!value &&
                            (value === originalValue ||
                              (value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()))
                      Severity: Major
                      Found in src/data-types.js - About 40 mins to fix

                        Function addForeignKeyConstraints has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function addForeignKeyConstraints(newAttribute, source, target, options, key) {
                        Severity: Minor
                        Found in src/associations/helpers.js - About 35 mins to fix

                          Function changeColumnQuery has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            changeColumnQuery(tableName, attributes) {
                              const attrString = [],
                                constraintString = [];
                              let commentString = '';
                          
                          
                          Severity: Minor
                          Found in src/dialects/mssql/query-generator.js - About 35 mins 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 dataTypeMapping has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            dataTypeMapping(tableName, attr, dataType) {
                              if (dataType.includes('PRIMARY KEY')) {
                                dataType = dataType.replace('PRIMARY KEY', '');
                              }
                          
                          
                          Severity: Minor
                          Found in src/dialects/postgres/query-generator.js - About 35 mins 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 mapValueFieldNames has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function mapValueFieldNames(dataValues, fields, Model) {
                            const values = {};
                          
                            for (const attr of fields) {
                              if (dataValues[attr] !== undefined && !Model._virtualAttributes.has(attr)) {
                          Severity: Minor
                          Found in src/utils.js - About 35 mins 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 upsert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            async upsert(tableName, insertValues, updateValues, where, options) {
                              const model = options.model;
                              const wheres = [];
                          
                              options = { ...options };
                          Severity: Minor
                          Found in src/dialects/mssql/query-interface.js - About 35 mins 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 deleteQuery has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            deleteQuery(tableName, where, options = {}, model) {
                              const table = this.quoteTable(tableName);
                              let whereClause = this.getWhereConditions(where, null, model, options);
                              const limit = options.limit ? ` LIMIT ${this.escape(options.limit)}` : '';
                              let primaryKeys = '';
                          Severity: Minor
                          Found in src/dialects/postgres/query-generator.js - About 35 mins 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