geminabox/geminabox

View on GitHub
lib/geminabox/server.rb

Summary

Maintainability
C
1 day
Test Coverage
B
83%

Class Server has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Server < Sinatra::Base
    enable :static, :methodoverride
    set :public_folder, Geminabox.public_folder
    set :views, Geminabox.views

Severity: Minor
Found in lib/geminabox/server.rb - About 4 hrs to fix

    File server.rb has 310 lines of code (exceeds 250 allowed). Consider refactoring.
    Confirmed

    require 'reentrant_flock'
    require 'rubygems/util'
    
    module Geminabox
    
    
    Severity: Minor
    Found in lib/geminabox/server.rb - About 3 hrs to fix

      Method reindex has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def reindex(force_rebuild = false)
              fixup_bundler_rubygems!
              force_rebuild = true unless Geminabox.incremental_updates
              if force_rebuild
                indexer.generate_index
      Severity: Minor
      Found in lib/geminabox/server.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

      Use text.start_with?('http://', 'https://') instead of text.start_with?('http://') || text.start_with?('https://').
      Open

              if text && (text.start_with?('http://') || text.start_with?('https://'))
      Severity: Minor
      Found in lib/geminabox/server.rb by rubocop

      This cop checks for double #start_with? or #end_with? calls separated by ||. In some cases such calls can be replaced with an single #start_with?/#end_with? call.

      Example:

      # bad
      str.start_with?("a") || str.start_with?(Some::CONST)
      str.start_with?("a", "b") || str.start_with?("c")
      str.end_with?(var1) || str.end_with?(var2)
      
      # good
      str.start_with?("a", Some::CONST)
      str.start_with?("a", "b", "c")
      str.end_with?(var1, var2)

      Use flat_map instead of map...flatten.
      Open

            query_gems.map{|query_gem| gem_dependencies(query_gem) }.flatten(1)
      Severity: Minor
      Found in lib/geminabox/server.rb by rubocop

      This cop is used to identify usages of

      Example:

      # bad
      [1, 2, 3, 4].map { |e| [e, e] }.flatten(1)
      [1, 2, 3, 4].collect { |e| [e, e] }.flatten(1)
      
      # good
      [1, 2, 3, 4].flat_map { |e| [e, e] }
      [1, 2, 3, 4].map { |e| [e, e] }.flatten
      [1, 2, 3, 4].collect { |e| [e, e] }.flatten

      Do not suppress exceptions.
      Open

            rescue
      Severity: Minor
      Found in lib/geminabox/server.rb by rubocop

      This cop checks for rescue blocks with no body.

      Example:

      # bad
      
      def some_method
        do_something
      rescue
        # do nothing
      end

      Example:

      # bad
      
      begin
        do_something
      rescue
        # do nothing
      end

      Example:

      # good
      
      def some_method
        do_something
      rescue
        handle_exception
      end

      Example:

      # good
      
      begin
        do_something
      rescue
        handle_exception
      end

      Do not suppress exceptions.
      Open

            rescue Gem::SystemExitException
      Severity: Minor
      Found in lib/geminabox/server.rb by rubocop

      This cop checks for rescue blocks with no body.

      Example:

      # bad
      
      def some_method
        do_something
      rescue
        # do nothing
      end

      Example:

      # bad
      
      begin
        do_something
      rescue
        # do nothing
      end

      Example:

      # good
      
      def some_method
        do_something
      rescue
        handle_exception
      end

      Example:

      # good
      
      begin
        do_something
      rescue
        handle_exception
      end

      Use 2 spaces for indentation in a heredoc by using <<~ instead of <<.
      Open

      <html>
        <head><title>Error - #{code}</title></head>
        <body>
          <h1>Error - #{code}</h1>
          <p>#{message}</p>
      Severity: Minor
      Found in lib/geminabox/server.rb by rubocop

      This cops checks the indentation of the here document bodies. The bodies are indented one step. In Ruby 2.3 or newer, squiggly heredocs (<<~) should be used. If you use the older rubies, you should introduce some library to your project (e.g. ActiveSupport, Powerpack or Unindent). Note: When Metrics/LineLength's AllowHeredoc is false(not default), this cop does not add any offenses for long here documents to avoid Metrics/LineLength's offenses.

      Example:

      # bad
      <<-RUBY
      something
      RUBY
      
      # good
      # When EnforcedStyle is squiggly, bad code is auto-corrected to the
      # following code.
      <<~RUBY
        something
      RUBY
      
      # good
      # When EnforcedStyle is active_support, bad code is auto-corrected to
      # the following code.
      <<-RUBY.strip_heredoc
        something
      RUBY

      There are no issues that match your filters.

      Category
      Status