sequelize/sequelize-auto

View on GitHub

Showing 74 of 74 total issues

File auto-generator.ts has 680 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from "lodash";
import { ColumnDescription } from "sequelize/types";
import { DialectOptions, FKSpec } from "./dialects/dialect-options";
import { AutoOptions, CaseFileOption, CaseOption, Field, IndexSpec, LangOption, makeIndent, makeTableName, pluralize, qNameJoin, qNameSplit, recase, Relation, singularize, TableData, TSField } from "./types";

Severity: Major
Found in src/auto-generator.ts - About 1 day to fix

    Function getSqType has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

      private getSqType(fieldObj: Field, attr: string): string {
        const attrValue = (fieldObj as any)[attr];
        if (!attrValue.toLowerCase) {
          console.log("attrValue", attr, attrValue);
          return attrValue;
    Severity: Minor
    Found in src/auto-generator.ts - About 1 day 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 addField has 137 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private addField(table: string, field: string): string {
    
        // ignore Sequelize standard fields
        const additional = this.options.additional;
        if (additional && (additional.timestamps !== false) && (this.isTimestampField(field) || this.isParanoidField(field))) {
    Severity: Major
    Found in src/auto-generator.ts - About 5 hrs to fix

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

              if (elementTypes.some(et => et.udt_name === 'geometry') && this.dialect.showGeometryTypeQuery) {
                const gquery = this.dialect.showGeometryTypeQuery(table.table_name, table.table_schema);
                const gtypes = await this.executeQuery<ColumnElementType>(gquery);
                gtypes.forEach(gt => {
                  const fld = fields[gt.column_name] as Field;
      Severity: Major
      Found in src/auto-builder.ts and 1 other location - About 5 hrs to fix
      src/auto-builder.ts on lines 151..160

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

      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 (elementTypes.some(et => et.udt_name === 'geography') && this.dialect.showGeographyTypeQuery) {
                const gquery = this.dialect.showGeographyTypeQuery(table.table_name, table.table_schema);
                const gtypes = await this.executeQuery<ColumnElementType>(gquery);
                gtypes.forEach(gt => {
                  const fld = fields[gt.column_name] as Field;
      Severity: Major
      Found in src/auto-builder.ts and 1 other location - About 5 hrs to fix
      src/auto-builder.ts on lines 162..171

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

      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 (fieldObj[attr] === true && !wroteAutoIncrement) {
                str += space[3] + "autoIncrement: true,\n";
                // Resort to Postgres' GENERATED BY DEFAULT AS IDENTITY instead of SERIAL
                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 and 1 other location - About 4 hrs to fix
      src/auto-generator.ts on lines 278..286

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

      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 (isSerialKey && !wroteAutoIncrement) {
              str += space[3] + "autoIncrement: true,\n";
              // Resort to Postgres' GENERATED BY DEFAULT AS IDENTITY instead of SERIAL
              if (this.dialect.name === "postgres" && fieldObj.foreignKey && fieldObj.foreignKey.isPrimaryKey === true &&
                (fieldObj.foreignKey.generation === "ALWAYS" || fieldObj.foreignKey.generation === "BY DEFAULT")) {
      Severity: Major
      Found in src/auto-generator.ts and 1 other location - About 4 hrs to fix
      src/auto-generator.ts on lines 307..314

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

      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

      Function getSqType has 88 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private getSqType(fieldObj: Field, attr: string): string {
          const attrValue = (fieldObj as any)[attr];
          if (!attrValue.toLowerCase) {
            console.log("attrValue", attr, attrValue);
            return attrValue;
      Severity: Major
      Found in src/auto-generator.ts - About 3 hrs to fix

        AutoGenerator has 28 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export class AutoGenerator {
          dialect: DialectOptions;
          tables: { [tableName: string]: { [fieldName: string]: ColumnDescription; }; };
          foreignKeys: { [tableName: string]: { [fieldName: string]: FKSpec; }; };
          hasTriggerTables: { [tableName: string]: boolean; };
        Severity: Minor
        Found in src/auto-generator.ts - About 3 hrs to fix

          Function addTypeScriptAssociationMixins has 80 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private addTypeScriptAssociationMixins(table: string): Record<string, any> {
              const sp = this.space[1];
              const needed: Record<string, Set<String>> = {};
              let str = '';
          
          
          Severity: Major
          Found in src/auto-generator.ts - About 3 hrs to fix

            Function mapTable has 67 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private async mapTable(table: Table) {
                try {
                  const fields = await this.queryInterface.describeTable(table.table_name, table.table_schema);
                  this.tableData.tables[makeTableQName(table)] = fields;
            
            
            Severity: Major
            Found in src/auto-builder.ts - About 2 hrs to fix

              Function generateText has 63 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                generateText() {
                  const tableNames = _.keys(this.tables);
              
                  const header = this.makeHeaderTemplate();
              
              
              Severity: Major
              Found in src/auto-generator.ts - About 2 hrs to fix

                Function mapTable has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                Open

                  private async mapTable(table: Table) {
                    try {
                      const fields = await this.queryInterface.describeTable(table.table_name, table.table_schema);
                      this.tableData.tables[makeTableQName(table)] = fields;
                
                
                Severity: Minor
                Found in src/auto-builder.ts - About 2 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 addTable has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  private addTable(table: string) {
                
                    const [schemaName, tableNameOrig] = qNameSplit(table);
                    const space = this.space;
                    let timestamps = (this.options.additional && this.options.additional.timestamps === true) || false;
                Severity: Minor
                Found in src/auto-generator.ts - About 1 hr to fix

                  Function mapForeignKeys has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private mapForeignKeys(table: Table) {
                  
                      const tableQname = makeTableQName(table);
                      const sql = this.dialect.getForeignKeysQuery(table.table_name, table.table_schema || this.sequelize.getDatabaseName());
                      const dialect = this.dialect;
                  Severity: Minor
                  Found in src/auto-builder.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

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

                      if (isM2M) {
                        if (this.usedChildNames.has(modelName + "." + singleName)) {
                          name = name + "_" + targetModel;
                        }
                        this.usedChildNames.add(modelName + "." + singularize(name));
                  Severity: Major
                  Found in src/auto-relater.ts and 1 other location - About 1 hr to fix
                  src/auto-relater.ts on lines 119..124

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

                  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

                      else {
                        if (this.usedChildNames.has(targetModel + "." + singleName)){
                          name = name + "_" + modelName;
                        }
                        this.usedChildNames.add(targetModel + "." + singularize(name));
                  Severity: Major
                  Found in src/auto-relater.ts and 1 other location - About 1 hr to fix
                  src/auto-relater.ts on lines 113..118

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

                  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

                  Function addField has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private addField(table: string, field: string): string {
                  
                      // ignore Sequelize standard fields
                      const additional = this.options.additional;
                      if (additional && (additional.timestamps !== false) && (this.isTimestampField(field) || this.isParanoidField(field))) {
                  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 addRelation has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    private addRelation(table: string, fkFieldName: string, spec: FKSpec, fkFields: { [fieldName: string]: FKSpec; }) {
                  
                      const [schemaName, tableName] = qNameSplit(table);
                      const schema = schemaName as string;
                      const modelName = recase(this.caseModel, tableName, this.singularize);
                  Severity: Minor
                  Found in src/auto-relater.ts - About 1 hr to fix

                    Function addIndexes has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      private addIndexes(table: string) {
                        const indexes = this.indexes[table];
                        const space = this.space;
                        let str = "";
                        if (indexes && indexes.length) {
                    Severity: Minor
                    Found in src/auto-generator.ts - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language