stellar/xdrgen

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

Summary

Maintainability
F
1 wk
Test Coverage

File rust.rb has 870 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Xdrgen
  module Generators

    class Rust < Xdrgen::Generators::Base

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

    Method render_typedef has 156 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def render_typedef(out, typedef)
            if is_builtin_type(typedef.type)
              out.puts "pub type #{name typedef} = #{reference(typedef, typedef.type)};"
            else
              out.puts "#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]"
    Severity: Major
    Found in lib/xdrgen/generators/rust.rb - About 6 hrs to fix

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

            def render_union(out, union)
              if union.default_arm.present?
                $stderr.puts "warn: union #{name union} includes default arms and default arms are not supported in the rust generator"
              end
              discriminant_type = reference(nil, union.discriminant.type)
      Severity: Minor
      Found in lib/xdrgen/generators/rust.rb - 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

      Method render_enum_of_all_types has 132 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def render_enum_of_all_types(out, types)
              out.puts <<-EOS.strip_heredoc
              #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
              #[cfg_attr(
                all(feature = "serde", feature = "alloc"),
      Severity: Major
      Found in lib/xdrgen/generators/rust.rb - About 5 hrs to fix

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

              def render_union(out, union)
                if union.default_arm.present?
                  $stderr.puts "warn: union #{name union} includes default arms and default arms are not supported in the rust generator"
                end
                discriminant_type = reference(nil, union.discriminant.type)
        Severity: Major
        Found in lib/xdrgen/generators/rust.rb - About 4 hrs to fix

          Class Rust has 30 methods (exceeds 20 allowed). Consider refactoring.
          Open

              class Rust < Xdrgen::Generators::Base
          
                def generate
                  $stderr.puts "warn: rust generator is experimental"
          
          
          Severity: Minor
          Found in lib/xdrgen/generators/rust.rb - About 3 hrs to fix

            Method render_enum has 80 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def render_enum(out, enum)
                    out.puts "// enum"
                    out.puts "#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]"
                    out.puts %{#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]}
                    if @options[:rust_types_custom_str_impl].include?(name enum)
            Severity: Major
            Found in lib/xdrgen/generators/rust.rb - About 3 hrs to fix

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

                    def render_typedef(out, typedef)
                      if is_builtin_type(typedef.type)
                        out.puts "pub type #{name typedef} = #{reference(typedef, typedef.type)};"
                      else
                        out.puts "#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]"
              Severity: Minor
              Found in lib/xdrgen/generators/rust.rb - 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 reference_to_call has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

                    def reference_to_call(parent, type)
                      base_ref = base_reference_to_call(type)
              
                      parent_name = name(parent) if parent
                      cyclic = is_type_in_type_field_types(base_ref, parent_name)
              Severity: Minor
              Found in lib/xdrgen/generators/rust.rb - 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 base_reference has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def base_reference(type)
                      case type
                      when AST::Typespecs::Bool
                        'bool'
                      when AST::Typespecs::Double
              Severity: Minor
              Found in lib/xdrgen/generators/rust.rb - About 1 hr to fix

                Method base_reference has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                      def base_reference(type)
                        case type
                        when AST::Typespecs::Bool
                          'bool'
                        when AST::Typespecs::Double
                Severity: Minor
                Found in lib/xdrgen/generators/rust.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 reference has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                      def reference(parent, type)
                        base_ref = base_reference type
                
                        parent_name = name(parent) if parent
                        cyclic = is_type_in_type_field_types(base_ref, parent_name)
                Severity: Minor
                Found in lib/xdrgen/generators/rust.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 base_reference_to_call has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                      def base_reference_to_call(type)
                        case type
                        when AST::Typespecs::String
                          if !type.decl.resolved_size.nil?
                            "StringM::<#{type.decl.resolved_size}>"
                Severity: Minor
                Found in lib/xdrgen/generators/rust.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_struct has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def render_struct(out, struct)
                        out.puts "#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]"
                        out.puts %{#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]}
                        if @options[:rust_types_custom_str_impl].include?(name struct)
                          out.puts %{#[cfg_attr(all(feature = "serde", feature = "alloc"), derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr))]}
                Severity: Minor
                Found in lib/xdrgen/generators/rust.rb - About 1 hr to fix

                  Method reference_to_call has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def reference_to_call(parent, type)
                          base_ref = base_reference_to_call(type)
                  
                          parent_name = name(parent) if parent
                          cyclic = is_type_in_type_field_types(base_ref, parent_name)
                  Severity: Minor
                  Found in lib/xdrgen/generators/rust.rb - About 1 hr to fix

                    Method build_type_field_types has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def build_type_field_types(node)
                            types = Hash.new { |h, k| h[k] = [] }
                            ingest_node = lambda do |n|
                              n.definitions.each{ |nn| ingest_node.call(nn) } if n.respond_to?(:definitions)
                              n.nested_definitions.each{ |nn| ingest_node.call(nn) } if n.respond_to?(:nested_definitions)
                    Severity: Minor
                    Found in lib/xdrgen/generators/rust.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 reference has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def reference(parent, type)
                            base_ref = base_reference type
                    
                            parent_name = name(parent) if parent
                            cyclic = is_type_in_type_field_types(base_ref, parent_name)
                    Severity: Minor
                    Found in lib/xdrgen/generators/rust.rb - About 1 hr to fix

                      Method build_type_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def build_type_list(node)
                              types = Set.new
                              ingest_node = lambda do |n|
                                case n
                                when AST::Definitions::Struct, AST::Definitions::Enum, AST::Definitions::Union, AST::Definitions::Typedef
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb - 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

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

                              ref = case type.sub_type
                              when :simple
                                if cyclic
                                  "Box<#{base_ref}>"
                                else
                      Severity: Major
                      Found in lib/xdrgen/generators/rust.rb and 1 other location - About 2 hrs to fix
                      lib/xdrgen/generators/rust.rb on lines 940..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 77.

                      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

                              case type.sub_type
                              when :simple
                                if cyclic
                                  "Box<#{base_ref}>"
                                else
                      Severity: Major
                      Found in lib/xdrgen/generators/rust.rb and 1 other location - About 2 hrs to fix
                      lib/xdrgen/generators/rust.rb on lines 1018..1042

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

                      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

                            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/rust.rb and 1 other location - About 40 mins to fix
                      lib/xdrgen/generators/go.rb on lines 216..226

                      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::Typespecs::Simple, AST::Definitions::Base, AST::Concerns::NestedDefinition
                                if type.respond_to?(:resolved_type) && AST::Definitions::Typedef === type.resolved_type && is_builtin_type(type.resolved_type.type)
                                  base_reference_to_call(type.resolved_type.type)
                                else
                                  base_reference(type)
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb and 2 other locations - About 30 mins to fix
                      lib/xdrgen/generators/rust.rb on lines 923..928
                      lib/xdrgen/generators/rust.rb on lines 974..979

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

                      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::Typespecs::Simple, AST::Definitions::Base, AST::Concerns::NestedDefinition
                                if type.respond_to?(:resolved_type) && AST::Definitions::Typedef === type.resolved_type && is_builtin_type(type.resolved_type.type)
                                  base_reference(type.resolved_type.type)
                                else
                                  name type
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb and 2 other locations - About 30 mins to fix
                      lib/xdrgen/generators/rust.rb on lines 974..979
                      lib/xdrgen/generators/rust.rb on lines 1001..1006

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

                      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::Typespecs::Simple, AST::Definitions::Base, AST::Concerns::NestedDefinition
                                if type.respond_to?(:resolved_type) && AST::Definitions::Typedef === type.resolved_type && is_builtin_type(type.resolved_type.type)
                                  base_reference(type.resolved_type.type)
                                else
                                  name type
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb and 2 other locations - About 30 mins to fix
                      lib/xdrgen/generators/rust.rb on lines 923..928
                      lib/xdrgen/generators/rust.rb on lines 1001..1006

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

                      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

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

                              when AST::Typespecs::Opaque
                                if type.fixed?
                                  "[u8; #{type.size}]"
                                elsif !type.decl.resolved_size.nil?
                                  "BytesM::<#{type.decl.resolved_size}>"
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb and 1 other location - About 15 mins to fix
                      lib/xdrgen/generators/rust.rb on lines 915..922

                      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

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

                              when AST::Typespecs::Opaque
                                if type.fixed?
                                  "[u8; #{type.size}]"
                                elsif !type.decl.resolved_size.nil?
                                  "BytesM::<#{type.decl.resolved_size}>"
                      Severity: Minor
                      Found in lib/xdrgen/generators/rust.rb and 1 other location - About 15 mins to fix
                      lib/xdrgen/generators/rust.rb on lines 993..1000

                      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