sequelize/sequelize-auto

View on GitHub

Showing 40 of 74 total issues

Function getTypeScriptFieldType has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  private getTypeScriptFieldType(fieldObj: TSField, attr: keyof TSField) {
    const rawFieldType = fieldObj[attr] || '';
    const fieldType = String(rawFieldType).toLowerCase();

    let jsType: string;
Severity: Minor
Found in src/auto-generator.ts - 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 constructor has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  constructor(database: string | Sequelize, username: string, password: string, options: AutoOptions) {
    if (options && options.dialect === 'sqlite' && !options.storage && database) {
      options.storage = database as string;
    }
    if (options && options.dialect === 'mssql') {
Severity: Minor
Found in src/auto.ts - About 1 hr to fix

    Function recase has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export function recase(opt: CaseOption | CaseFileOption | undefined, val: string | null, singular = false) {
      if (singular && val) {
        val = singularize(val);
      }
      if (!opt || opt === 'o' || !val) {
    Severity: Minor
    Found in src/types.ts - About 55 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 constructor has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      constructor(database: string | Sequelize, username: string, password: string, options: AutoOptions) {
        if (options && options.dialect === 'sqlite' && !options.storage && database) {
          options.storage = database as string;
        }
        if (options && options.dialect === 'mssql') {
    Severity: Minor
    Found in src/auto.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

    Avoid deeply nested control flow statements.
    Open

            if (this.dialect.name === "mssql" && defaultVal && defaultVal.toLowerCase() === '(newid())') {
              defaultVal = null as any; // disable adding "default value" attribute for UUID fields if generating for MS SQL
            }
    Severity: Major
    Found in src/auto-generator.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

              if (isSerialKey) {
                return true; // value generated in the database
              }
      Severity: Major
      Found in src/auto-generator.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

              } else if (attr === "comment" && (!fieldObj[attr] || this.dialect.name === "mssql")) {
                return true;
              } else {
                let val = (attr !== "type") ? null : this.getSqType(fieldObj, attr);
                if (val == null) {
        Severity: Major
        Found in src/auto-generator.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (this.dialect.name === "postgres" && fieldObj.foreignKey && fieldObj.foreignKey.isPrimaryKey === true && (fieldObj.foreignKey.generation === "ALWAYS" || fieldObj.foreignKey.generation === "BY DEFAULT")) {
                      str += space[3] + "autoIncrementIdentity: true,\n";
                    }
          Severity: Major
          Found in src/auto-generator.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    if (_.isString(defaultVal)) {
                      const field_type = fieldObj.type.toLowerCase();
                      defaultVal = this.escapeSpecial(defaultVal);
            
                      while (defaultVal.startsWith('(') && defaultVal.endsWith(')')) {
            Severity: Major
            Found in src/auto-generator.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      if (this.dialect.name === "mssql" && (["(NULL)", "NULL"].includes(defaultVal) || typeof defaultVal === "undefined")) {
                        defaultVal = null as any; // Override default NULL in MS SQL to javascript null
                      }
              Severity: Major
              Found in src/auto-generator.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                        if (defaultVal === null || defaultVal === undefined) {
                          return true;
                        }
                Severity: Major
                Found in src/auto-generator.ts - About 45 mins to fix

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

                    private getAlias(fkFieldName: string, modelName: string, targetModel: string, isM2M = false) {
                      let name = this.trimId(fkFieldName);
                      if (name === fkFieldName || isM2M) {
                        name = fkFieldName + "_" + modelName;
                      }
                  Severity: Minor
                  Found in src/auto-relater.ts - 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 addSchemaForRelations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private addSchemaForRelations(table: string) {
                      if (!table.includes('.') && !this.relations.some(rel => rel.childTable === table)) {
                        // if no tables match the given table, then assume we need to fix the schema
                        const first = this.relations.find(rel => !!rel.childTable);
                        if (first) {
                  Severity: Minor
                  Found in src/auto-generator.ts - 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 val;
                  Severity: Major
                  Found in src/types.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return _.snakeCase(val).toUpperCase();
                    Severity: Major
                    Found in src/types.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return true;
                      Severity: Major
                      Found in src/auto-generator.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return true;
                        Severity: Major
                        Found in src/auto-generator.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return _.upperFirst(_.camelCase(val));
                          Severity: Major
                          Found in src/types.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return true; // value generated in the database
                            Severity: Major
                            Found in src/auto-generator.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                        return true;
                              Severity: Major
                              Found in src/auto-generator.ts - About 30 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language