-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathno_todos.rb
39 lines (37 loc) · 1.22 KB
/
no_todos.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module RuboCop
module Cop
module Obsession
# 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.
#
# @example
#
# # bad
# # TODO: remove this method when we ship the new signup flow
# def my_method
# ...
# end
#
# # good
# def my_method
# ...
# end
class NoTodos < Base
MSG = 'Avoid TODO comment, create a task in your project management tool instead.'
KEYWORD_REGEX = /(^|[^\w])(TODO|FIXME|OPTIMIZE|HACK)($|[^\w])/i
def on_new_investigation
processed_source.comments.each do |comment|
add_offense(comment) if comment.text.match?(KEYWORD_REGEX)
end
end
end
end
end
end