sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

Avoid deeply nested control flow statements.
Open

            if (dataType.includes(' REFERENCES')) {
              dataTypeString += dataType.substr(dataType.indexOf(' REFERENCES'));
            }
Severity: Major
Found in src/dialects/sqlite/query-generator.js - About 45 mins to fix

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

      static _addDefaultAttributes() {
        const tail = {};
        let head = {};
    
        // Add id if no primary key was manually added to definition
    Severity: Minor
    Found in src/model.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 (values[k] === undefined) {
                    continue;
                  }
    Severity: Major
    Found in src/model.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if (!all.includes(types[j])) {
                    all.unshift(types[j]);
                    i++;
                  }
      Severity: Major
      Found in src/model.js - About 45 mins to fix

        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

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

            _loadDialectModule(moduleName) {
              try {
                if (this.sequelize.config.dialectModulePath) {
                  return require(this.sequelize.config.dialectModulePath);
                }
          Severity: Minor
          Found in src/dialects/abstract/connection-manager.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 (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

            Avoid deeply nested control flow statements.
            Open

                        for (const foreignKeyReference of foreignKeyReferences) {
                          const constraintName = foreignKeyReference.constraintName;
                          if (
                            !!constraintName &&
                            foreignKeyReference.tableCatalog === database &&
            Severity: Major
            Found in src/model.js - 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 _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

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

                  if (options.individualHooks) {
                    await Promise.all(instances.map(instance => this.runHooks('afterDestroy', instance, options)));
                  }
              Severity: Minor
              Found in src/model.js and 1 other location - About 45 mins to fix
              src/model.js on lines 3193..3195

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

              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

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

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

                    if (options.individualHooks) {
                      await Promise.all(instances.map(instance => this.runHooks('afterRestore', instance, options)));
                    }
                Severity: Minor
                Found in src/model.js and 1 other location - About 45 mins to fix
                src/model.js on lines 3119..3121

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

                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

                  validate(value) {
                    if (!_.isPlainObject(value)) {
                      throw new sequelizeErrors.ValidationError(util.format('%j is not a valid hstore', value));
                    }
                    return true;
                Severity: Minor
                Found in src/data-types.js and 1 other location - About 40 mins to fix
                src/data-types.js on lines 763..768

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

                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

                  validate(value) {
                    if (!Array.isArray(value)) {
                      throw new sequelizeErrors.ValidationError(util.format('%j is not a valid array', value));
                    }
                    return true;
                Severity: Minor
                Found in src/data-types.js and 1 other location - About 40 mins to fix
                src/data-types.js on lines 503..508

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

                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 (value[Op.and]) {
                      return this._whereBind(this.OperatorMap[Op.and], key, value[Op.and], options);
                    }
                Severity: Minor
                Found in src/dialects/abstract/query-generator.js and 1 other location - About 40 mins to fix
                src/dialects/abstract/query-generator.js on lines 2487..2489

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

                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 (value[Op.or]) {
                      return this._whereBind(this.OperatorMap[Op.or], key, value[Op.or], options);
                    }
                Severity: Minor
                Found in src/dialects/abstract/query-generator.js and 1 other location - About 40 mins to fix
                src/dialects/abstract/query-generator.js on lines 2491..2493

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

                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

                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
                    Severity
                    Category
                    Status
                    Source
                    Language