Class: RuboCop::Cop::MessageAnnotator
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/cop/message_annotator.rb |
Overview
Message Annotator class annotates a basic offense message based on params passed into initializer.
#=> 'Cop/CopName: message (http://example.org/styleguide)'
Class Attribute Summary
- .style_guide_urls readonly
Class Method Summary
Instance Attribute Summary
- #config readonly
- #cop_config readonly
- #cop_name readonly
- #options readonly
- #debug? ⇒ Boolean readonly private
- #display_cop_names? ⇒ Boolean readonly private
- #display_style_guide? ⇒ Boolean readonly private
- #extra_details? ⇒ Boolean readonly private
Instance Method Summary
-
#annotate(message) ⇒ String
Returns the annotated message, based on params passed into initializer.
- #urls
- #details private
- #reference_urls private
-
#style_guide_base_url ⇒ String
private
Returns the base style guide URL from AllCops or the specific department.
- #style_guide_url private
Constructor Details
.new(config, cop_name, cop_config, options) ⇒ MessageAnnotator
# File 'lib/rubocop/cop/message_annotator.rb', line 47
def initialize(config, cop_name, cop_config, ) @config = config @cop_name = cop_name @cop_config = cop_config || {} @options = end
Class Attribute Details
.style_guide_urls (readonly)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 21
attr_reader :style_guide_urls
Instance Attribute Details
#config (readonly)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 16
attr_reader :, :config, :cop_name, :cop_config
#cop_config (readonly)
[ GitHub ]#cop_name (readonly)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 16
attr_reader :, :config, :cop_name, :cop_config
#debug? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/message_annotator.rb', line 111
def debug? [:debug] end
#display_cop_names? ⇒ Boolean
(readonly, private)
[ GitHub ]
#display_style_guide? ⇒ Boolean
(readonly, private)
[ GitHub ]
#extra_details? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/message_annotator.rb', line 107
def extra_details? [:extra_details] || config.for_all_cops['ExtraDetails'] end
#options (readonly)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 16
attr_reader :, :config, :cop_name, :cop_config
Instance Method Details
#annotate(message) ⇒ String
Returns the annotated message, based on params passed into initializer
# File 'lib/rubocop/cop/message_annotator.rb', line 58
def annotate( ) = "#{cop_name}: #{}" if display_cop_names? += " #{details}" if extra_details? && details if display_style_guide? links = urls.join(', ') = "#{} (#{links})" end end
#details (private)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 124
def details details = cop_config && cop_config['Details'] details.nil? || details.empty? ? nil : details end
#reference_urls (private)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 102
def reference_urls urls = Array(cop_config['Reference']) urls.nil? || urls.empty? ? nil : urls.reject(&:empty?) end
#style_guide_base_url ⇒ String (private)
Returns the base style guide URL from AllCops or the specific department
#style_guide_url (private)
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 74
def style_guide_url url = cop_config['StyleGuide'] return nil if url.nil? || url.empty? self.class.style_guide_urls[url] ||= begin base_url = style_guide_base_url if base_url.nil? || base_url.empty? url else URI.join(base_url, url).to_s end end end
#urls
[ GitHub ]# File 'lib/rubocop/cop/message_annotator.rb', line 68
def urls [style_guide_url, *reference_urls].compact end