Class: RuboCop::Cop::Obsession::NoTodos

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/obsession/no_todos.rb

Overview

This cop checks for TODO/FIXME/etc comments.

Avoid TODO comments, instead create tasks for them in your project management software, and assign them to the right person. Half of the TODOs usually never get done, and the code is then polluted with old stale TODOs. Sometimes developers really mean to work on their TODOs soon, but then Product re-prioritizes their work, or the developer leaves the company, and never gets a chance to tackle them.

Examples:


# bad
# TODO: remove this method when we ship the new signup flow
def my_method
  ...
end

# good
def my_method
  ...
end

Constant Summary collapse

MSG =
'Avoid TODO comment, create a task in your project management tool instead.'
KEYWORD_REGEX =
/(^|[^\w])(TODO|FIXME|OPTIMIZE|HACK)($|[^\w])/i

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



31
32
33
34
35
# File 'lib/rubocop/cop/obsession/no_todos.rb', line 31

def on_new_investigation
  processed_source.comments.each do |comment|
    add_offense(comment) if comment.text.match?(KEYWORD_REGEX)
  end
end