mercredi 6 janvier 2016

How to fix rubocop offense for a class class a::b::c

I have following file lib/a/b/c.rb

class a::b::c
  def request(env)
    #some code here
  end
end

Now i am using rubocop style

Style/ClassAndModuleChildren:
  Enabled: true

I am getting rubocop offense for this

lib/a/b/c.rb:1:7: C: Use nested module/class definitions instead of compact style.
class a::b::c

When i update my code to following offence get fixed

Style 1

class a
  class b
    class c
      def request(env)
        #some code here
      end
    end
  end
end

Style 2

module a
  module b
    class c
      def request(env)
        #some code here
      end
    end
  end
end

I think i should use Style 2 as i am using require 'a' in one of my file.

Please let me know how to fix this type & offences and reason for it

Aucun commentaire:

Enregistrer un commentaire