stellar/xdrgen

View on GitHub
lib/xdrgen/generators/go.rb

Summary

Maintainability
F
1 wk
Test Coverage

File go.rb has 944 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Xdrgen
  module Generators

    class Go < Xdrgen::Generators::Base

Severity: Major
Found in lib/xdrgen/generators/go.rb - About 2 days to fix

    Method render_encode_to_body has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
    Open

          def render_encode_to_body(out, var, type, self_encode:)
            def check_error(str)
              <<-EOS
      if #{str}; err != nil {
        return err
    Severity: Minor
    Found in lib/xdrgen/generators/go.rb - 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 render_decode_from_body has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

          def render_decode_from_body(out, var, type, declared_variables:, self_encode:)
            tail = <<-EOS
      n += nTmp
      if err != nil {
        return n, fmt.Errorf("decoding #{name type}: %w", err)
    Severity: Minor
    Found in lib/xdrgen/generators/go.rb - About 6 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 render_decode_from_body has 132 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def render_decode_from_body(out, var, type, declared_variables:, self_encode:)
            tail = <<-EOS
      n += nTmp
      if err != nil {
        return n, fmt.Errorf("decoding #{name type}: %w", err)
    Severity: Major
    Found in lib/xdrgen/generators/go.rb - About 5 hrs to fix

      Class Go has 39 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class Go < Xdrgen::Generators::Base
      
            def generate
              @already_rendered = []
              path = "#{@namespace}_generated.go"
      Severity: Minor
      Found in lib/xdrgen/generators/go.rb - About 5 hrs to fix

        Method render_encode_to_body has 100 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def render_encode_to_body(out, var, type, self_encode:)
                def check_error(str)
                  <<-EOS
          if #{str}; err != nil {
            return err
        Severity: Major
        Found in lib/xdrgen/generators/go.rb - About 4 hrs to fix

          Method render_top_matter has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def render_top_matter(out)
                  out.puts <<-EOS.strip_heredoc
                    //lint:file-ignore S1005 The issue should be fixed in xdrgen. Unfortunately, there's no way to ignore a single file in staticcheck.
                    //lint:file-ignore U1000 fmtTest is not needed anywhere, should be removed in xdrgen.
          
          
          Severity: Major
          Found in lib/xdrgen/generators/go.rb - About 2 hrs to fix

            Method reference has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def reference(type)
                    baseReference = case type
                    when AST::Typespecs::Bool
                      "bool"
                    when AST::Typespecs::Double
            Severity: Minor
            Found in lib/xdrgen/generators/go.rb - About 2 hrs to fix

              Method render_union_typedef has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def render_union_typedef(out, typedef, union)
                      out.puts <<-EOS.strip_heredoc
                        // SwitchFieldName returns the field name in which this union's
                        // discriminant is stored
                        func (u #{name typedef}) SwitchFieldName() string {
              Severity: Minor
              Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                Method render_definition has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def render_definition(out, defn)
                        if @already_rendered.include? name(defn)
                
                          unless defn.is_a?(AST::Definitions::Namespace)
                            $stderr.puts "warn: #{name(defn)} is defined twice.  skipping"
                Severity: Minor
                Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                  Method render_union has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def render_union(out, union)
                  
                          out.puts "type #{name union} struct{"
                          out.indent do
                            out.puts "#{name union.discriminant} #{reference union.discriminant.type}"
                  Severity: Minor
                  Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                    Method render_union has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def render_union(out, union)
                    
                            out.puts "type #{name union} struct{"
                            out.indent do
                              out.puts "#{name union.discriminant} #{reference union.discriminant.type}"
                    Severity: Minor
                    Found in lib/xdrgen/generators/go.rb - 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 render_enum has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def render_enum(out, enum)
                            # render the "enum"
                            out.puts "type #{name enum} int32"
                            out.puts "const ("
                            out.indent do
                    Severity: Minor
                    Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                      Method render_union_decode_from_interface has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            def render_union_decode_from_interface(out, union)
                              name = name(union)
                              out.puts "// DecodeFrom decodes this value using the Decoder."
                              out.puts "func (u *#{name}) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) {"
                              out.puts "  if maxDepth == 0 {"
                      Severity: Minor
                      Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                        Method render_typedef_decode_from_interface has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                              def render_typedef_decode_from_interface(out, typedef)
                                name = name(typedef)
                                type = typedef.declaration.type
                                out.puts "// DecodeFrom decodes this value using the Decoder."
                                out.puts "func (s *#{name}) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) {"
                        Severity: Minor
                        Found in lib/xdrgen/generators/go.rb - About 1 hr to fix

                          Method switch_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def switch_for(out, union, ident)
                                  out.puts "switch #{reference union.discriminant.type}(#{ident}) {"
                          
                                  union.normal_arms.each do |arm|
                                    arm.cases.each do |c|
                          Severity: Minor
                          Found in lib/xdrgen/generators/go.rb - 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 render_typedef_decode_from_interface has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def render_typedef_decode_from_interface(out, typedef)
                                  name = name(typedef)
                                  type = typedef.declaration.type
                                  out.puts "// DecodeFrom decodes this value using the Decoder."
                                  out.puts "func (s *#{name}) DecodeFrom(d *xdr.Decoder, maxDepth uint) (int, error) {"
                          Severity: Minor
                          Found in lib/xdrgen/generators/go.rb - About 55 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

                          Method render_typedef has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def render_typedef(out, typedef)
                                  # Typedefs that wrap a pointer type are not well supported in Go because
                                  # Go does not allow pointer types to have methods. This prevents us from
                                  # defining the EncodeTo method on these types which is very inconvenient
                                  # for the render functions that generate structs that contain these
                          Severity: Minor
                          Found in lib/xdrgen/generators/go.rb - About 55 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

                          Avoid deeply nested control flow statements.
                          Open

                                          if type.is_a?(AST::Identifier)
                                            # we are already calling by pointer, so we just need to cast
                                            newvar = "(*#{name type})(#{var})"
                                          else
                                            newvar = "(*#{name type})(&#{var})"
                          Severity: Major
                          Found in lib/xdrgen/generators/go.rb - About 45 mins to fix

                            Method render_definition has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                  def render_definition(out, defn)
                                    if @already_rendered.include? name(defn)
                            
                                      unless defn.is_a?(AST::Definitions::Namespace)
                                        $stderr.puts "warn: #{name(defn)} is defined twice.  skipping"
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb - About 35 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

                            Method reference has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                  def reference(type)
                                    baseReference = case type
                                    when AST::Typespecs::Bool
                                      "bool"
                                    when AST::Typespecs::Double
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb - About 35 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

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

                                  def render_source_comment(out, defn)
                                    return if defn.is_a?(AST::Definitions::Namespace)
                            
                                    out.puts <<-EOS.strip_heredoc
                                      // #{name defn} is an XDR #{defn.class.name.demodulize} defines as:
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb and 1 other location - About 40 mins to fix
                            lib/xdrgen/generators/rust.rb on lines 347..358

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

                            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

                                    when AST::Definitions::Enum ;
                                      render_enum out, defn
                                      render_enum_encode_to_interface out, defn
                                      render_decoder_from_interface out, name(defn)
                                      render_enum_decode_from_interface out, defn
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb and 2 other locations - About 15 mins to fix
                            lib/xdrgen/generators/go.rb on lines 178..184
                            lib/xdrgen/generators/go.rb on lines 192..198

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

                            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

                                    when AST::Definitions::Struct ;
                                      render_struct out, defn
                                      render_struct_encode_to_interface out, defn
                                      render_decoder_from_interface out, name(defn)
                                      render_struct_decode_from_interface out, defn
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb and 2 other locations - About 15 mins to fix
                            lib/xdrgen/generators/go.rb on lines 185..191
                            lib/xdrgen/generators/go.rb on lines 192..198

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

                            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

                                    when AST::Definitions::Union ;
                                      render_union out, defn
                                      render_union_encode_to_interface out, defn
                                      render_decoder_from_interface out, name(defn)
                                      render_union_decode_from_interface out, defn
                            Severity: Minor
                            Found in lib/xdrgen/generators/go.rb and 2 other locations - About 15 mins to fix
                            lib/xdrgen/generators/go.rb on lines 178..184
                            lib/xdrgen/generators/go.rb on lines 185..191

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

                            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