yoyo-project/yoyo

View on GitHub

Showing 52 of 52 total issues

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

func (r *PersonRepository) Delete(query person.Query) (err error) {
    var stmt *sql.Stmt
    // ensure the *sql.Stmt is closed after we're done with it
    defer func() {
        if stmt != nil && r.tx == nil {
Severity: Major
Found in example/mysql/yoyo/repositories/repository_person.go and 1 other location - About 1 hr to fix
example/mysql/yoyo/repositories/repository_city.go on lines 168..186

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

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

const EntityFile = `package ` + PackageName + `

import (
    "database/sql"
    "fmt"
Severity: Major
Found in internal/repository/template/entity.go and 1 other location - About 1 hr to fix
internal/repository/template/repository.go on lines 132..180

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

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

const RepositoryFile = `package ` + PackageName + `

import (
    "database/sql"
    "fmt"
Severity: Major
Found in internal/repository/template/repository.go and 1 other location - About 1 hr to fix
internal/repository/template/entity.go on lines 9..76

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

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

        err = func() error {
            fName := filepath.Join(repositoriesPath, "/query/node.go")
            f, err := create(fName)
            defer func() {
                if f != nil {
Severity: Major
Found in internal/repository/generate.go and 1 other location - About 1 hr to fix
internal/repository/generate.go on lines 146..164

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

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

        err = func() error {
            fName := filepath.Join(repositoriesPath, "/nullable/types.go")
            f, err := create(fName)
            defer func() {
                if f != nil {
Severity: Major
Found in internal/repository/generate.go and 1 other location - About 1 hr to fix
internal/repository/generate.go on lines 126..144

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

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 GenerateQueryLogic has 58 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func GenerateQueryLogic(col string, column schema.Column) (methods, functions, imports []string) {
    var (
        ops    []operation
        goType string
    )
Severity: Minor
Found in internal/repository/template/query.go - About 1 hr to fix

    Method Table.validate has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
    Open

    func (t *Table) validate() (err error) {
        if err = validateName(t.Name); err != nil {
            return err
        }
    
    
    Severity: Minor
    Found in internal/schema/schema_validate.go - 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

    Method Datatype.String has 55 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (dt Datatype) String() (s string) {
        switch dt {
        case Integer:
            s = integer
        case TinyInt:
    Severity: Minor
    Found in internal/datatype/datatypes.go - About 1 hr to fix

      Function FromString has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func FromString(in string) (dt Datatype, err error) {
          switch strings.ToUpper(strings.Split(in, "(")[0]) {
          case integer, sint:
              dt = Integer
          case bigint:
      Severity: Minor
      Found in internal/datatype/datatypes.go - About 1 hr to fix

        Function InitDatabaseReader has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func InitDatabaseReader(loadAdapter AdapterLoader) DatabaseReader {
            return func(config yoyo.Config) (db schema.Database, err error) {
                var adapter Adapter
                adapter, err = loadAdapter(config.Schema.Dialect)
                if err != nil {
        Severity: Minor
        Found in internal/reverse/schema.go - About 1 hr to fix

          Function NewQueryFileGenerator has 53 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func NewQueryFileGenerator(reposPath string, findPackagePath Finder, db schema.Database) EntityGenerator {
              return func(t schema.Table, w io.StringWriter) error {
                  var methods, functions, imports []string
          
                  // We always need fmt
          Severity: Minor
          Found in internal/repository/generate_query.go - About 1 hr to fix

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

                    case "references":
                        refsNode := value.Content[i+1]
                        for ri, rn := range refsNode.Content {
                            if rn.Tag == "!!str" {
                                r := Reference{}
            Severity: Major
            Found in internal/schema/schema_unmarshal.go and 2 other locations - About 1 hr to fix
            internal/schema/schema_unmarshal.go on lines 19..31
            internal/schema/schema_unmarshal.go on lines 45..57

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

            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 3 locations. Consider refactoring.
            Open

                    case "columns":
                        colsNode := value.Content[i+1]
                        for ci, cn := range colsNode.Content {
                            if cn.Tag == "!!str" {
                                c := Column{}
            Severity: Major
            Found in internal/schema/schema_unmarshal.go and 2 other locations - About 1 hr to fix
            internal/schema/schema_unmarshal.go on lines 19..31
            internal/schema/schema_unmarshal.go on lines 69..81

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

            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 3 locations. Consider refactoring.
            Open

                    case "tables":
                        tabsNode := value.Content[i+1]
                        for ti, tn := range tabsNode.Content {
                            if tn.Tag == "!!str" {
                                t := Table{}
            Severity: Major
            Found in internal/schema/schema_unmarshal.go and 2 other locations - About 1 hr to fix
            internal/schema/schema_unmarshal.go on lines 45..57
            internal/schema/schema_unmarshal.go on lines 69..81

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

            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 NewEntityGenerator has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func NewEntityGenerator(packageName string, db schema.Database, packagePath Finder, reposPath string) EntityGenerator {
                return func(t schema.Table, w io.StringWriter) error {
                    var fields, referenceFields, scanFields, imports []string
                    nullPackagePath, err := packagePath(reposPath + "/nullable")
                    if err != nil {
            Severity: Minor
            Found in internal/repository/generate_entity.go - About 1 hr to fix

              Function NewGenerator has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  generateEntity EntityGenerator,
                  generateRepository EntityGenerator,
                  generateQueryFile EntityGenerator,
                  generateRepositoriesFile WriteGenerator,
                  generateQueryNodeFile SimpleWriteGenerator,
              Severity: Major
              Found in internal/repository/generate.go - About 50 mins to fix

                Function NewGenerator has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    createTable TableGenerator,
                    addMissingColumns TableGenerator,
                    addMissingIndices TableGenerator,
                    addAllIndices TableGenerator,
                    hasTable StringSearcher,
                Severity: Major
                Found in internal/migration/generator.go - About 50 mins to fix

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

                                  if references, err = adapter.ListReferences(tableName); err == nil {
                                      for _, ftName := range references {
                                          if reference, err := adapter.GetReference(tableName, ftName); err == nil {
                                              reference.TableName = ftName
                                              table.References = append(table.References, reference)
                  Severity: Major
                  Found in internal/reverse/schema.go and 2 other locations - About 50 mins to fix
                  internal/reverse/schema.go on lines 22..33
                  internal/reverse/schema.go on lines 34..45

                  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 3 locations. Consider refactoring.
                  Open

                                  if indices, err = adapter.ListIndices(tableName); err == nil {
                                      for _, indexName := range indices {
                                          if index, err := adapter.GetIndex(tableName, indexName); err == nil {
                                              index.Name = indexName
                                              table.Indices = append(table.Indices, index)
                  Severity: Major
                  Found in internal/reverse/schema.go and 2 other locations - About 50 mins to fix
                  internal/reverse/schema.go on lines 22..33
                  internal/reverse/schema.go on lines 46..57

                  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

                  Method Table.validate has 8 return statements (exceeds 4 allowed).
                  Open

                  func (t *Table) validate() (err error) {
                      if err = validateName(t.Name); err != nil {
                          return err
                      }
                  
                  
                  Severity: Major
                  Found in internal/schema/schema_validate.go - About 50 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language