sequelize/sequelize

View on GitHub
src/sequelize.js

Summary

Maintainability
F
6 days
Test Coverage

File sequelize.js has 580 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const url = require('url');
const path = require('path');
const retry = require('retry-as-promised');
const _ = require('lodash');

Severity: Major
Found in src/sequelize.js - About 1 day to fix

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

      constructor(database, username, password, options) {
        let config;
    
        if (arguments.length === 1 && typeof database === 'object') {
          // new Sequelize({ ... options })
    Severity: Major
    Found in src/sequelize.js - About 6 hrs to fix

      Function query has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

        async query(sql, options) {
          options = { ...this.options.query, ...options };
      
          if (options.instance && !options.model) {
            options.model = options.instance.constructor;
      Severity: Minor
      Found in src/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

      Sequelize has 36 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Sequelize {
        /**
         * Instantiate sequelize with name of database, username and password.
         *
         * @example
      Severity: Minor
      Found in src/sequelize.js - About 4 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 normalizeAttribute has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            normalizeAttribute(attribute) {
              if (!_.isPlainObject(attribute)) {
                attribute = { type: attribute };
              }
          
          
          Severity: Minor
          Found in src/sequelize.js - About 1 hr 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 log has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            log(...args) {
              let options;
          
              const last = _.last(args);
          
          
          Severity: Minor
          Found in src/sequelize.js - About 1 hr 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 sync has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async sync(options) {
              options = {
                ...this.options,
                ...this.options.sync,
                ...options,
          Severity: Minor
          Found in src/sequelize.js - About 1 hr to fix

            Function sync has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              async sync(options) {
                options = {
                  ...this.options,
                  ...this.options.sync,
                  ...options,
            Severity: Minor
            Found in src/sequelize.js - About 1 hr 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 normalizeAttribute has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              normalizeAttribute(attribute) {
                if (!_.isPlainObject(attribute)) {
                  attribute = { type: attribute };
                }
            
            
            Severity: Minor
            Found in src/sequelize.js - About 1 hr to fix

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

                normalizeDataType(Type) {
                  let type = typeof Type === 'function' ? new Type() : Type;
                  const dialectTypes = this.dialect.DataTypes || {};
              
                  if (dialectTypes[type.key]) {
              Severity: Minor
              Found in src/sequelize.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

              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

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

                      if (sql.bind !== undefined) {
                        if (options.bind !== undefined) {
                          throw new Error('Both `sql.bind` and `options.bind` cannot be set at the same time');
                        }
                        options.bind = sql.bind;
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 50 mins to fix
                src/sequelize.js on lines 559..564

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

                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 (this.options.logging === true) {
                      deprecations.noTrueLogging();
                      // eslint-disable-next-line no-console
                      this.options.logging = console.log;
                    }
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 50 mins to fix
                src/dialects/abstract/query.js on lines 125..129

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

                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 (sql.values !== undefined) {
                        if (options.replacements !== undefined) {
                          throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time');
                        }
                        options.replacements = sql.values;
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 50 mins to fix
                src/sequelize.js on lines 566..571

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

                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.modelManager.forEachModel(
                      model => {
                        if (model) {
                          models.push(model);
                        }
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 35 mins to fix
                src/sequelize.js on lines 820..827

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

                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.modelManager.forEachModel(
                      model => {
                        if (model) {
                          models.push(model);
                        }
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 35 mins to fix
                src/sequelize.js on lines 851..858

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

                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

                        (attribute.defaultValue === DataTypes.NOW ||
                          attribute.defaultValue === DataTypes.UUIDV1 ||
                          attribute.defaultValue === DataTypes.UUIDV4)
                Severity: Minor
                Found in src/sequelize.js and 1 other location - About 30 mins to fix
                src/instance-validator.js on lines 375..377

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

                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

                There are no issues that match your filters.

                Category
                Status