Class: RuboCop::Cop::SmartTodo::SmartTodoCop
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::SmartTodo::SmartTodoCop
- Defined in:
- lib/smart_todo_cop.rb
Overview
A RuboCop used to restrict the usage of regular TODO comments in code. This Cop does not run by default. It should be added to the RuboCop host’s configuration file.
Constant Summary collapse
- HELP =
"For more info please look at https://github.com/Shopify/smart_todo/wiki/Syntax"
- MSG =
"Don't write regular TODO comments. Write SmartTodo compatible syntax comments. #{HELP}"
- INVESTIGATED_TAGS =
::SmartTodo::CommentParser::SUPPORTED_TAGS + ::SmartTodo::CommentParser::SUPPORTED_TAGS.map(&:downcase)
- TODO_PATTERN =
/^#\s@?(#{INVESTIGATED_TAGS.join("|")})\b/
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ void
This method returns an undefined value.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/smart_todo_cop.rb', line 22 def on_new_investigation processed_source.comments.each do |comment| next unless (match = TODO_PATTERN.match(comment.text)) if match[1] != match[1].upcase add_offense(comment) next end = (comment.text) if .errors.any? add_offense(comment, message: "Invalid TODO format: #{.errors.join(", ")}. #{HELP}") elsif !smart_todo?() add_offense(comment) elsif invalid_assignees(.assignees).any? add_offense(comment, message: "Invalid event assignee. This method only accepts strings. #{HELP}") elsif (invalid_events = validate_events(.events)).any? add_offense(comment, message: "#{invalid_events.join(". ")}. #{HELP}") end end end |