Class: RuboCop::Cop::SmartTodo::SmartTodoCommentFormatCop

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/smart_todo_comment_format_cop.rb

Overview

A RuboCop cop to enforce proper formatting of SmartTodo comments. SmartTodo comments must have their description on separate lines, indented by 2 spaces.

Bad:

# TODO(on: date('2024-03-29'), to: '[email protected]'): Remove this
# TODO(on: date('2024-03-29'), to: '[email protected]') Remove this
# TODO(on: date('2024-03-29'), to: '[email protected]')
# Remove this (not indented)

Good:

# TODO(on: date('2024-03-29'), to: '[email protected]')
#   Remove this (indented by 2 extra spaces)

Constant Summary collapse

MSG_INLINE =
"SmartTodo comment must not be on the same line as the TODO. " \
"For more info please look at https://github.com/Shopify/smart_todo/wiki/Syntax"
MSG_INDENT =
"SmartTodo continuation line must be indented by 2 spaces. " \
"For more info please look at https://github.com/Shopify/smart_todo/wiki/Syntax"
SMART_TODO_PATTERN =
/\A\s*#\s*(TODO|FIXME|OPTIMIZE)\(on:/
INLINE_TEXT_PATTERN =
/\A(\s*#\s*(?:TODO|FIXME|OPTIMIZE)\(.+\))\s*:?\s+(.+)/

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



33
34
35
36
37
38
39
40
# File 'lib/smart_todo_comment_format_cop.rb', line 33

def on_new_investigation
  processed_source.comments.each_with_index do |comment, index|
    next unless smart_todo_comment?(comment)

    check_inline_text(comment)
    check_continuation_indent(comment, processed_source.comments[index + 1])
  end
end