Boostport/address

View on GitHub

Showing 33 of 33 total issues

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

          Function checkRequiredFields has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
          Open

          func checkRequiredFields(address Address, requiredFields map[Field]struct{}) error {
          
              errors := ErrMissingRequiredFields{
                  country: address.Country,
              }
          Severity: Minor
          Found in validate.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

          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

              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

                      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

              Function checkSubdivisions has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
              Open

              func checkSubdivisions(address Address, administrativeAreaData []administrativeArea) error {
              
                  var err *multierror.Error
              
                  if address.AdministrativeArea != "" {
              Severity: Minor
              Found in 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

              Function checkPostCode has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
              Open

              func checkPostCode(address Address, regex postCodeRegex) error {
              
                  var err *multierror.Error
              
                  if address.PostCode != "" && regex.regex != "" {
              Severity: Minor
              Found in 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

              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

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

                  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
                    Severity
                    Category
                    Status
                    Source
                    Language