opencontrol/compliance-masonry

View on GitHub

Showing 33 of 33 total issues

Function flattenNormalize has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
Open

func flattenNormalize(config *Config, flattened *map[string]interface{}) error {
    // discover all controls
    var allControls []string

    // create the regex expressions we will use
Severity: Minor
Found in pkg/cli/export/export_flatten.go - About 3 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 flattenArray has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
Open

func flattenArray(config *Config, value interface{}, key string, flattened *map[string]interface{}) (bool, error) {
    // are we an array?
    input, okArray := value.([]interface{})
    if !okArray {
        return false, nil
Severity: Minor
Found in pkg/cli/export/export_flatten.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

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

func TestGetStandard(t *testing.T) {
    // Setup map
    m := newStandards()
    // Get nil component.
    standard, found := m.get("test")
Severity: Major
Found in pkg/lib/standards_test.go and 1 other location - About 1 hr to fix
pkg/lib/components_test.go on lines 16..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 155.

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 TestAddComponent(t *testing.T) {
    // Setup map
    m := newComponents()
    // Get nil component.
    component, found := m.get("test")
Severity: Major
Found in pkg/lib/components_test.go and 1 other location - About 1 hr to fix
pkg/lib/standards_test.go on lines 14..30

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

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

func flattenNormalize(config *Config, flattened *map[string]interface{}) error {
    // discover all controls
    var allControls []string

    // create the regex expressions we will use
Severity: Minor
Found in pkg/cli/export/export_flatten.go - About 1 hr to fix

    Function flattenArray has 58 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func flattenArray(config *Config, value interface{}, key string, flattened *map[string]interface{}) (bool, error) {
        // are we an array?
        input, okArray := value.([]interface{})
        if !okArray {
            return false, nil
    Severity: Minor
    Found in pkg/cli/export/export_flatten.go - About 1 hr to fix

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

      func (s Satisfies) GetControlOrigins() []string {
          controlOrigins := set.New(set.ThreadSafe)
          for i := range s.ControlOrigins {
              controlOrigins.Add(s.ControlOrigins[i])
          }
      Severity: Major
      Found in pkg/lib/components/versions/3_1_0/component.go and 1 other location - About 1 hr to fix
      pkg/lib/components/versions/3_1_0/component.go on lines 153..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 134.

      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 (s Satisfies) GetImplementationStatuses() []string {
          implementationStatuses := set.New(set.ThreadSafe)
          for i := range s.ImplementationStatuses {
              implementationStatuses.Add(s.ImplementationStatuses[i])
          }
      Severity: Major
      Found in pkg/lib/components/versions/3_1_0/component.go and 1 other location - About 1 hr to fix
      pkg/lib/components/versions/3_1_0/component.go on lines 134..145

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

      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(p.Standards) > 0 {
              buffer.WriteString(",\"standards\":[")
              for i, v := range p.Standards {
                  bytesJSON, err := json.Marshal(v)
                  if err != nil {
      Severity: Minor
      Found in pkg/cli/export/export_config.go and 1 other location - About 50 mins to fix
      pkg/cli/export/export_config.go on lines 52..65

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

      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(p.Components) > 0 {
              buffer.WriteString(",\"components\":[")
              for i, v := range p.Components {
                  bytesJSON, err := json.Marshal(v)
                  if err != nil {
      Severity: Minor
      Found in pkg/cli/export/export_config.go and 1 other location - About 50 mins to fix
      pkg/cli/export/export_config.go on lines 68..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 118.

      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

      /*
       Copyright (C) 2018 OpenControl Contributors. See LICENSE.md for license.
      */
      
      package version
      Severity: Minor
      Found in pkg/cli/version/version.go and 1 other location - About 45 mins to fix
      pkg/cli/validate/validate.go on lines 1..20

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

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

      func flattenDriver(config *Config, value interface{}, key string, flattened *map[string]interface{}) (bool, error) {
          // account for unset value - just ignore (?)
          if value == nil {
              log.Printf("flatten: No value for %s\n", key)
              return true, nil
      Severity: Major
      Found in pkg/cli/export/export_flatten.go - About 45 mins to fix

        Method vcsAndLocalFSGetter.GetLocalResources has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func (g *vcsAndLocalFSGetter) GetLocalResources(source string, resources []string, destination string,
            subfolder string, recursively bool, resourceType constants.ResourceType) error {
        Severity: Minor
        Found in pkg/cli/get/resources/getter.go - About 45 mins to fix

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

          package validate
          
          import (
              "io"
          
          
          Severity: Minor
          Found in pkg/cli/validate/validate.go and 1 other location - About 45 mins to fix
          pkg/cli/version/version.go on lines 1..24

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

          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 vcsAndLocalFSGetter.GetRemoteResources has 6 return statements (exceeds 4 allowed).
          Open

          func (g *vcsAndLocalFSGetter) GetRemoteResources(destination string, subfolder string,
              entries []common.RemoteSource) error {
              // Create the temporary directory for where to clone all the remote resources.
              tempResourcesDir, err := g.FSUtil.TempDir("", "opencontrol-resources")
              if err != nil {
          Severity: Major
          Found in pkg/cli/get/resources/getter.go - About 40 mins to fix

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

                    Context("When there are controls specified in the certification but some controls have been documented", func() {
                        It("should return a subset of the full list of controls", func() {
                            config := Config{
                                OpencontrolDir: filepath.Join(workingDir, "..", "..", "..", "test", "fixtures", "opencontrol_fixtures"),
                                Certification:  "LATO",
            Severity: Minor
            Found in pkg/cli/diff/inventory_test.go and 1 other location - About 40 mins to fix
            pkg/cli/diff/inventory_test.go on lines 54..64

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

            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

                    Context("When there are controls specified in the certification and we have documented them", func() {
                        It("should return no missing controls", func() {
                            config := Config{
                                OpencontrolDir: filepath.Join(workingDir, "..", "..", "..", "test", "fixtures", "opencontrol_fixtures_complete"),
                                Certification:  "LATO",
            Severity: Minor
            Found in pkg/cli/diff/inventory_test.go and 1 other location - About 40 mins to fix
            pkg/cli/diff/inventory_test.go on lines 43..53

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

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

            func (parser YAMLParser) Parse(data []byte) (common.OpenControl, error) {
                if data == nil || len(data) == 0 {
                    return nil, common.ErrNoDataToParse
                }
                b := Base{}
            Severity: Major
            Found in pkg/lib/opencontrol/parse.go - About 35 mins to fix

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

              func TestComponentSetters(t *testing.T) {
                  component := Component{}
                  // Test the setters.
                  // Change the version.
                  component.SetVersion(semver.MustParse("3.0.0"))
              Severity: Minor
              Found in pkg/lib/components/versions/2_0_0/component_test.go and 2 other locations - About 35 mins to fix
              pkg/lib/components/versions/3_0_0/component_test.go on lines 55..64
              pkg/lib/components/versions/3_1_0/component_test.go on lines 66..75

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

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

              func exportJSON(config *Config, workspace common.Workspace, output *exportOutput, writer io.Writer) []error {
                  // result
                  var errors []error
              
                  // work vars
              Severity: Major
              Found in pkg/cli/export/exportFormat.go - About 35 mins to fix
                Severity
                Category
                Status
                Source
                Language