rubygems/rubygems

View on GitHub
lib/rubygems/specification.rb

Summary

Maintainability
F
1 wk
Test Coverage

Class Specification has 176 methods (exceeds 20 allowed). Consider refactoring.
Open

class Gem::Specification < Gem::BasicSpecification
  extend Gem::Deprecate

  # REFACTOR: Consider breaking out this version stuff into a separate
  # module. There's enough special stuff around it that it may justify
Severity: Major
Found in lib/rubygems/specification.rb - About 3 days to fix

    File specification.rb has 1322 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative "deprecate"
    require_relative "basic_specification"
    require_relative "stub_specification"
    require_relative "platform"
    require_relative "specification_record"
    Severity: Major
    Found in lib/rubygems/specification.rb - About 3 days to fix

      Method _load has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def self._load(str)
          Gem.load_yaml
          Gem.load_safe_marshal
      
          yaml_set = false
      Severity: Minor
      Found in lib/rubygems/specification.rb - 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

      Method to_ruby has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def to_ruby
          result = []
          result << "# -*- encoding: utf-8 -*-"
          result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}"
          result << "#{Gem::StubSpecification::PREFIX}#{extensions.join "\0"}" unless
      Severity: Minor
      Found in lib/rubygems/specification.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 _load has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self._load(str)
          Gem.load_yaml
          Gem.load_safe_marshal
      
          yaml_set = false
      Severity: Major
      Found in lib/rubygems/specification.rb - About 2 hrs to fix

        Method to_ruby has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def to_ruby
            result = []
            result << "# -*- encoding: utf-8 -*-"
            result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}"
            result << "#{Gem::StubSpecification::PREFIX}#{extensions.join "\0"}" unless
        Severity: Major
        Found in lib/rubygems/specification.rb - About 2 hrs to fix

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

            def pretty_print(q) # :nodoc:
              q.group 2, "Gem::Specification.new do |s|", "end" do
                q.breakable
          
                attributes = @@attributes - [:name, :version]
          Severity: Minor
          Found in lib/rubygems/specification.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 traverse has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def traverse(trail = [], visited = {}, &block)
              trail.push(self)
              begin
                runtime_dependencies.each do |dep|
                  dep.matching_specs(true).each do |dep_spec|
          Severity: Minor
          Found in lib/rubygems/specification.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 activate_dependencies has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def activate_dependencies
              unresolved = Gem::Specification.unresolved_deps
          
              runtime_dependencies.each do |spec_dep|
                if loaded = Gem.loaded_specs[spec_dep.name]
          Severity: Minor
          Found in lib/rubygems/specification.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 load has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.load(file)
              return unless file
          
              spec = @load_cache_mutex.synchronize { @load_cache[file] }
              return spec if spec
          Severity: Minor
          Found in lib/rubygems/specification.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 load has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.load(file)
              return unless file
          
              spec = @load_cache_mutex.synchronize { @load_cache[file] }
              return spec if spec
          Severity: Minor
          Found in lib/rubygems/specification.rb - About 1 hr to fix

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

              def initialize_copy(other_spec)
                self.class.array_attributes.each do |name|
                  name = :"@#{name}"
                  next unless other_spec.instance_variable_defined? name
            
            
            Severity: Minor
            Found in lib/rubygems/specification.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 build_extensions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def build_extensions # :nodoc:
                return if extensions.empty?
                return if default_gem?
                # we need to fresh build when same name and version of default gems
                return if self.class.find_by_full_name(full_name)&.default_gem?
            Severity: Minor
            Found in lib/rubygems/specification.rb - About 45 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 normalize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def normalize
                if defined?(@extra_rdoc_files) && @extra_rdoc_files
                  @extra_rdoc_files.uniq!
                  @files ||= []
                  @files.concat(@extra_rdoc_files)
            Severity: Minor
            Found in lib/rubygems/specification.rb - About 45 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 dependent_gems has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def dependent_gems(check_dev=true)
                out = []
                Gem::Specification.each do |spec|
                  deps = check_dev ? spec.dependencies : spec.runtime_dependencies
                  deps.each do |dep|
            Severity: Minor
            Found in lib/rubygems/specification.rb - About 45 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 required_ruby_version= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def required_ruby_version=(req)
                @required_ruby_version = Gem::Requirement.create req
            
                @required_ruby_version.requirements.map! do |op, v|
                  if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4
            Severity: Minor
            Found in lib/rubygems/specification.rb - About 45 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 ruby_code has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def ruby_code(obj)
                case obj
                when String             then obj.dump + ".freeze"
                when Array              then "[" + obj.map {|x| ruby_code x }.join(", ") + "]"
                when Hash               then
            Severity: Minor
            Found in lib/rubygems/specification.rb - About 45 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 conflicts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def conflicts
                conflicts = {}
                runtime_dependencies.each do |dep|
                  spec = Gem.loaded_specs[dep.name]
                  if spec && !spec.satisfies_requirement?(dep)
            Severity: Minor
            Found in lib/rubygems/specification.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

            Avoid too many return statements within this method.
            Open

                return unless File.exist?(File.join(base_dir, "extensions"))
            Severity: Major
            Found in lib/rubygems/specification.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return unless File.writable?(base_dir)
              Severity: Major
              Found in lib/rubygems/specification.rb - About 30 mins to fix

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

                  def self.reset
                    @@dirs = nil
                    Gem.pre_reset_hooks.each(&:call)
                    @specification_record = nil
                    clear_load_cache
                Severity: Minor
                Found in lib/rubygems/specification.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

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

                  def method_missing(sym, *a, &b) # :nodoc:
                    if REMOVED_METHODS.include?(sym)
                      removed_method_calls << sym
                      return
                    end
                Severity: Minor
                Found in lib/rubygems/specification.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

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

                  def self._resort!(specs) # :nodoc:
                    specs.sort! do |a, b|
                      names = a.name <=> b.name
                      next names if names.nonzero?
                      versions = b.version <=> a.version
                Severity: Minor
                Found in lib/rubygems/specification.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

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

                  def add_bindir(executables)
                    return nil if executables.nil?
                
                    if @bindir
                      Array(executables).map {|e| File.join(@bindir, e) }
                Severity: Minor
                Found in lib/rubygems/specification.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

                HACK found
                Open

                        dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK
                Severity: Minor
                Found in lib/rubygems/specification.rb by fixme

                TODO found
                Open

                    # TODO: maybe we should switch to rubygems' version service?
                Severity: Minor
                Found in lib/rubygems/specification.rb by fixme

                HACK found
                Open

                    # HACK: the #to_s is in here because RSpec has an Array of Arrays of
                Severity: Minor
                Found in lib/rubygems/specification.rb by fixme

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

                    @required_ruby_version.requirements.map! do |op, v|
                      if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4
                        [op == "~>" ? "=" : op, Gem::Version.new(v.segments.tap {|s| s.delete_at(3) }.join("."))]
                      else
                        [op, v]
                Severity: Minor
                Found in lib/rubygems/specification.rb and 1 other location - About 45 mins to fix
                bundler/lib/bundler/rubygems_ext.rb on lines 97..102

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

                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