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";
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;
- Read upRead up
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))) {
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;
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; };
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 = '';
Function generateText
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
generateText() {
const tableNames = _.keys(this.tables);
const header = this.makeHeaderTemplate();
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;
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))) {
- Read upRead up
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 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) {
Function makeHeaderTemplate
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
makeHeaderTemplate() {
let header = "";
const sp = this.space[1];
if (this.options.lang === 'ts') {
Function addTable
has a Cognitive Complexity of 11 (exceeds 5 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;
- Read upRead up
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 makeHeaderTemplate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
makeHeaderTemplate() {
let header = "";
const sp = this.space[1];
if (this.options.lang === 'ts') {
- Read upRead up
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 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;
- Read upRead up
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
}
Avoid deeply nested control flow statements. Open
if (isSerialKey) {
return true; // value generated in the database
}
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) {
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";
}
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(')')) {
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
}
Avoid deeply nested control flow statements. Open
if (defaultVal === null || defaultVal === undefined) {
return true;
}
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) {
- Read upRead up
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 true;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return true; // value generated in the database
Avoid too many return
statements within this function. Open
return true;
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";
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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")) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
str += `export type #TABLE#Pk = ${primaryKeys.map((k) => `"${recase(this.options.caseProp, k)}"`).join(' | ')};\n`;
- Read upRead up
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 58.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
str += `export type #TABLE#OptionalAttributes = ${creationOptionalFields.map((k) => `"${recase(this.options.caseProp, k)}"`).join(' | ')};\n`;
- Read upRead up
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 58.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else if (type.match(/^geometry/)) {
const gtype = fieldObj.elementType ? `(${fieldObj.elementType})` : '';
val = `DataTypes.GEOMETRY${gtype}`;
} else if (type.match(/^geography/)) {
const gtype = fieldObj.elementType ? `(${fieldObj.elementType})` : '';
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else if (type.match(/^geography/)) {
const gtype = fieldObj.elementType ? `(${fieldObj.elementType})` : '';
val = `DataTypes.GEOGRAPHY${gtype}`;
} else if (type.match(/^array/)) {
const eltype = this.getSqType(fieldObj, "elementType");
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76