Class: RuboCop::Cop::Style::CommentAnnotation
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/style/comment_annotation.rb
Overview
Checks that comment annotation keywords are written according to guidelines.
Annotation keywords can be specified by overriding the cop’s ‘Keywords` configuration. Keywords are allowed to be single words or phrases.
NOTE: With a multiline comment block (where each line is only a comment), only the first line will be able to register an offense, even if an annotation keyword starts another line. This is done to prevent incorrect registering of keywords (eg. ‘review`) inside a paragraph as an annotation.
Constant Summary collapse
- MSG_COLON_STYLE =
'Annotation keywords like `%<keyword>s` should be all ' \ 'upper case, followed by a colon, and a space, ' \ 'then a note describing the problem.'
- MSG_SPACE_STYLE =
'Annotation keywords like `%<keyword>s` should be all ' \ 'upper case, followed by a space, ' \ 'then a note describing the problem.'
- MISSING_NOTE =
'Annotation comment, with keyword `%<keyword>s`, is missing a note.'
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods included from AutoCorrector
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, callbacks_needed, #callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #parser_engine, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#on_new_investigation ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubocop/cop/style/comment_annotation.rb', line 73 def on_new_investigation processed_source.comments.each_with_index do |comment, index| next unless first_comment_line?(processed_source.comments, index) || inline_comment?(comment) annotation = AnnotationComment.new(comment, keywords) next unless annotation.annotation? && !annotation.correct?(colon: requires_colon?) register_offense(annotation) end end |