Boostport/address

View on GitHub

Showing 33 of 33 total issues

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

    Avoid deeply nested control flow statements.
    Open

                        if !dependentLocalityRegex.MatchString(address.PostCode) {
                            err = multierror.Append(err, ErrInvalidPostCode)
                            return err.ErrorOrNil()
                        }
    Severity: Major
    Found in validate.go - About 45 mins to fix

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

      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

      Function checkSubdivisions has 6 return statements (exceeds 4 allowed).
      Open

      func checkSubdivisions(address Address, administrativeAreaData []administrativeArea) error {
      
          var err *multierror.Error
      
          if address.AdministrativeArea != "" {
      Severity: Major
      Found in validate.go - About 40 mins to fix

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

        func (i FieldName) String() string {
            i -= 1
            if i < 0 || i >= FieldName(len(_FieldName_index)-1) {
                return "FieldName(" + strconv.FormatInt(int64(i+1), 10) + ")"
            }
        Severity: Minor
        Found in constant_string.go and 1 other location - About 40 mins to fix
        constant_string.go on lines 26..32

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

        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

        func (i Field) String() string {
            i -= 1
            if i < 0 || i >= Field(len(_Field_index)-1) {
                return "Field(" + strconv.FormatInt(int64(i+1), 10) + ")"
            }
        Severity: Minor
        Found in constant_string.go and 1 other location - About 40 mins to fix
        constant_string.go on lines 65..71

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

        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 Territory.contains has 5 return statements (exceeds 4 allowed).
        Open

        func (t Territory) contains(address Address) bool {
        
            if t.Country != "" && address.Country != t.Country {
                return false
            }
        Severity: Major
        Found in zone.go - About 35 mins to fix

          Function checkPostCode has 5 return statements (exceeds 4 allowed).
          Open

          func checkPostCode(address Address, regex postCodeRegex) error {
          
              var err *multierror.Error
          
              if address.PostCode != "" && regex.regex != "" {
          Severity: Major
          Found in validate.go - About 35 mins to fix

            Method data.getDependentLocalityName has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
            Open

            func (d data) getDependentLocalityName(countryCode, administrativeAreaID, localityID, dependentLocalityID, language string) string {
            
                data := d.getCountry(countryCode)
            
                lang := d.normalizeLanguage(countryCode, language)
            Severity: Minor
            Found in data.go - About 25 mins 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

            Severity
            Category
            Status
            Source
            Language