Boostport/address

View on GitHub
generator/generate.go

Summary

Maintainability
F
1 wk
Test Coverage
F
0%

Method worker.start has a Cognitive Complexity of 172 (exceeds 20 allowed). Consider refactoring.
Open

func (w *worker) start() {
    go func() {
        for {
        exit:
            select {
Severity: Minor
Found in generator/generate.go - About 3 days 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

File generate.go has 949 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package main

import (
    "encoding/json"
    "errors"
Severity: Major
Found in generator/generate.go - About 1 day to fix

    Function processAdministrativeAreas has a Cognitive Complexity of 75 (exceeds 20 allowed). Consider refactoring.
    Open

    func processAdministrativeAreas(countryJSON countryJSON, language string) (map[string][]administrativeArea, map[string]postCodeRegex, error) {
    
        result := map[string][]administrativeArea{}
        postCodeResult := map[string]postCodeRegex{}
    
    
    Severity: Minor
    Found in generator/generate.go - 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

    Method worker.start has 172 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (w *worker) start() {
        go func() {
            for {
            exit:
                select {
    Severity: Major
    Found in generator/generate.go - About 5 hrs to fix

      Function processLocalities has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring.
      Open

      func processLocalities(administrativeAreaJSON subdivisionJSON, language string) (map[string][]locality, map[string]postCodeRegex, error) {
      
          result := map[string][]locality{}
          postCodeResult := map[string]postCodeRegex{}
      
      
      Severity: Minor
      Found in generator/generate.go - About 5 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 processAdministrativeAreas has 122 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func processAdministrativeAreas(countryJSON countryJSON, language string) (map[string][]administrativeArea, map[string]postCodeRegex, error) {
      
          result := map[string][]administrativeArea{}
          postCodeResult := map[string]postCodeRegex{}
      
      
      Severity: Major
      Found in generator/generate.go - About 3 hrs to fix

        Method country.toCode has 111 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c country) toCode() string {
        
            str := fmt.Sprintf(`{
            ID: "%s",
            Name: "%s",`, c.ID, c.Name)
        Severity: Major
        Found in generator/generate.go - About 3 hrs to fix

          Method country.toCode has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
          Open

          func (c country) toCode() string {
          
              str := fmt.Sprintf(`{
              ID: "%s",
              Name: "%s",`, c.ID, c.Name)
          Severity: Minor
          Found in generator/generate.go - 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 processLocalities has 87 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func processLocalities(administrativeAreaJSON subdivisionJSON, language string) (map[string][]locality, map[string]postCodeRegex, error) {
          
              result := map[string][]locality{}
              postCodeResult := map[string]postCodeRegex{}
          
          
          Severity: Major
          Found in generator/generate.go - About 2 hrs to fix

            Function main has 72 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func main() {
            
                fmt.Printf("Downloading address data from %s. This may take a few minutes.\n", rootURL)
            
                start := time.Now()
            Severity: Minor
            Found in generator/generate.go - About 1 hr to fix

              Function processAdministrativeAreas has 9 return statements (exceeds 4 allowed).
              Open

              func processAdministrativeAreas(countryJSON countryJSON, language string) (map[string][]administrativeArea, map[string]postCodeRegex, error) {
              
                  result := map[string][]administrativeArea{}
                  postCodeResult := map[string]postCodeRegex{}
              
              
              Severity: Major
              Found in generator/generate.go - About 55 mins to fix

                Function processLocalities has 9 return statements (exceeds 4 allowed).
                Open

                func processLocalities(administrativeAreaJSON subdivisionJSON, language string) (map[string][]locality, map[string]postCodeRegex, error) {
                
                    result := map[string][]locality{}
                    postCodeResult := map[string]postCodeRegex{}
                
                
                Severity: Major
                Found in generator/generate.go - About 55 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if err != nil {
                                              w.result <- workerResult{
                                                  Error: fmt.Errorf("error processing admin areas in the default language for country %s: %s", countryJSON.Key, err),
                                              }
                  
                  
                  Severity: Major
                  Found in generator/generate.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                if language != countryJSON.Lang {
                    
                                                    countryData, err := http.Get(url + "--" + language)
                    
                                                    if err != nil {
                    Severity: Major
                    Found in generator/generate.go - About 45 mins to fix

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

                              switch field {
                      
                              case "%N":
                                  allowed[address.Name] = struct{}{}
                              case "%O":
                      Severity: Major
                      Found in generator/generate.go and 1 other location - About 1 hr to fix
                      generator/generate.go on lines 1207..1224

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

                      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

                              switch string(field) {
                              case "N":
                                  upper[address.Name] = struct{}{}
                              case "O":
                                  upper[address.Organization] = struct{}{}
                      Severity: Major
                      Found in generator/generate.go and 1 other location - About 1 hr to fix
                      generator/generate.go on lines 1238..1256

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

                      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 len(latinizedAdministrativeAreas) > 0 {
                      
                              // Sanity check
                              if len(latinizedAdministrativeAreas) != len(processedAdministrativeAreas) {
                                  return result, postCodeResult, fmt.Errorf("number of latinized admin areas (%d) does not match number of admin areas (%d) for %s", len(latinizedAdministrativeAreas), len(processedAdministrativeAreas), countryJSON.ID)
                      Severity: Minor
                      Found in generator/generate.go and 1 other location - About 55 mins to fix
                      generator/generate.go on lines 1083..1095

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

                      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 len(latinizedLocalities) > 0 {
                      
                              // Sanity check
                              if len(latinizedLocalities) != len(processedLocalities) {
                                  return result, postCodeResult, fmt.Errorf("number of latinized localities (%d) does not match number of localities (%d) for %s", len(latinizedLocalities), len(processedLocalities), administrativeAreaJSON.ID)
                      Severity: Minor
                      Found in generator/generate.go and 1 other location - About 55 mins to fix
                      generator/generate.go on lines 952..964

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

                      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 len(c.AllowedFields) > 0 {
                      
                              // Generate fields in order to avoid huge diffs when updating the data
                              var fields []string
                      
                      
                      Severity: Major
                      Found in generator/generate.go and 2 other locations - About 45 mins to fix
                      generator/generate.go on lines 255..276
                      generator/generate.go on lines 278..299

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

                      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 len(c.RequiredFields) > 0 {
                      
                              // Generate fields in order to avoid huge diffs when updating the data
                              var fields []string
                      
                      
                      Severity: Major
                      Found in generator/generate.go and 2 other locations - About 45 mins to fix
                      generator/generate.go on lines 232..253
                      generator/generate.go on lines 278..299

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

                      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 len(c.Upper) > 0 {
                      
                              // Generate fields in order to avoid huge diffs when updating the data
                              var fields []string
                      
                      
                      Severity: Major
                      Found in generator/generate.go and 2 other locations - About 45 mins to fix
                      generator/generate.go on lines 232..253
                      generator/generate.go on lines 255..276

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

                      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 administrativeAreaJSON.SubZips != "" && administrativeAreaJSON.SubZipExs != "" && subZips[i] != "" && subZipExs[i] != "" {
                                  err := checkPostalCodeRegex("^"+subZips[i], strings.Split(subZipExs[i], ","))
                      
                                  if err != nil {
                                      return result, postCodeResult, fmt.Errorf("error checking default locality post code regex for %s against sample: %s", administrativeAreaJSON.ID, err)
                      Severity: Minor
                      Found in generator/generate.go and 1 other location - About 40 mins to fix
                      generator/generate.go on lines 1115..1121

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

                      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 localityJSON.SubZips != "" && localityJSON.SubZipExs != "" && subZips[i] != "" && subZipExs[i] != "" {
                                  err := checkPostalCodeRegex("^"+subZips[i], strings.Split(subZipExs[i], ","))
                      
                                  if err != nil {
                                      return result, postCodeReg, fmt.Errorf("error checking dependent locality post code regex for %s against sample: %s", localityJSON.ID, err)
                      Severity: Minor
                      Found in generator/generate.go and 1 other location - About 40 mins to fix
                      generator/generate.go on lines 988..994

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status