Class: RuboCop::Cop::CopStore
- Inherits:
-
Array
- Object
- Array
- RuboCop::Cop::CopStore
- Defined in:
- lib/rubocop/cop/cop.rb
Overview
Store for all cops with helper functions
Instance Method Summary collapse
- #cop_name_with_namespace(name, origin, basename, found_ns) ⇒ Object
- #qualified_cop_name(name, origin) ⇒ Object
-
#types ⇒ Array<String>
List of types for current cops.
-
#with_type(type) ⇒ Array<Cop>
Cops for that specific type.
-
#without_type(type) ⇒ Array<Cop>
Cops not for a specific type.
Instance Method Details
#cop_name_with_namespace(name, origin, basename, found_ns) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rubocop/cop/cop.rb', line 41 def cop_name_with_namespace(name, origin, basename, found_ns) if name != basename && found_ns != File.dirname(name).to_sym warn "#{origin}: #{name} has the wrong namespace - should be " \ "#{found_ns}" end "#{found_ns}/#{basename}" end |
#qualified_cop_name(name, origin) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/cop.rb', line 25 def qualified_cop_name(name, origin) @cop_names ||= Set.new(map(&:cop_name)) basename = File.basename(name) found_ns = types.map(&:capitalize).select do |ns| @cop_names.include?("#{ns}/#{basename}") end case found_ns.size when 0 then name # No namespace found. Deal with it later in caller. when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0]) else raise AmbiguousCopName, "Ambiguous cop name `#{basename}` used in" \ "#{origin} needs namespace qualifier." end end |
#types ⇒ Array<String>
Returns list of types for current cops.
11 12 13 |
# File 'lib/rubocop/cop/cop.rb', line 11 def types @types ||= map(&:cop_type).uniq! end |