sequelize/sequelize

View on GitHub
src/utils.js

Summary

Maintainability
C
1 day
Test Coverage

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

const DataTypes = require('./data-types');
const SqlString = require('./sql-string');
const _ = require('lodash');
const baseIsNative = require('lodash/_baseIsNative');
const uuidv1 = require('uuid').v1;
Severity: Minor
Found in src/utils.js - About 5 hrs to fix

    Function mapWhereFieldNames has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function mapWhereFieldNames(attributes, Model) {
      if (attributes) {
        getComplexKeys(attributes).forEach(attribute => {
          const rawAttribute = Model.rawAttributes[attribute];
    
    
    Severity: Minor
    Found in src/utils.js - About 1 hr to fix

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

      function toDefaultValue(value, dialect) {
        if (typeof value === 'function') {
          const tmp = value();
          if (tmp instanceof DataTypes.ABSTRACT) {
            return tmp.toSql();
      Severity: Minor
      Found in src/utils.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 mapOptionFieldNames has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function mapOptionFieldNames(options, Model) {
        if (Array.isArray(options.attributes)) {
          options.attributes = options.attributes.map(attr => {
            // Object lookups will force any variable to strings, we don't want that for special objects etc
            if (typeof attr !== 'string') return attr;
      Severity: Minor
      Found in src/utils.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 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

      Avoid too many return statements within this function.
      Open

          return value.slice();
      Severity: Major
      Found in src/utils.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return { ...value };
        Severity: Major
        Found in src/utils.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return now(dialect);
          Severity: Major
          Found in src/utils.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return value;
            Severity: Major
            Found in src/utils.js - About 30 mins to fix

              Function nameIndex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function nameIndex(index, tableName) {
                if (tableName.tableName) tableName = tableName.tableName;
              
                if (!Object.prototype.hasOwnProperty.call(index, 'name')) {
                  const fields = index.fields.map(field => (typeof field === 'string' ? field : field.name || field.attribute));
              Severity: Minor
              Found in src/utils.js - About 25 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

              There are no issues that match your filters.

              Category
              Status