class Danger::DangerTodoist

This is a danger plugin to detect any TODO/FIXME entries left in the code.

@example Ensure, by warning, there are no TODOS left in the modified code

todoist.warn_for_todos

@example Ensure, by failing the build, no TODOS left in the modified code

todoist.fail_for_todos

@example Set custom warning message for warning

todoist.message = "Please fix all TODOS"
todoist.warn_for_todos

@example List every todo item

todoist.warn_for_todos
todoist.print_todos_table

@example Do anything with the todos. Todos have `text` and `file` properties

todoist.todos.each { |todo| puts todo.text }

@see hanneskaeufler/danger-todoist @tags todos, fixme

Constants

DEFAULT_KEYWORDS
DEFAULT_MESSAGE

Attributes

keywords[W]

Keywords to recognize as todos

@attr_writer [Array] keywords Custom array of strings to identify todos @return [void]

message[W]

Message to be shown

@attr_writer [String] message Custom message shown when todos were found @return [void]

Public Instance Methods

fail_for_todos() click to toggle source

Adds an error if there are todos found in the modified code

@return [void]

# File lib/todoist/plugin.rb, line 63
def fail_for_todos
  call_method_for_todos(:fail)
end
print_todos_table() click to toggle source

Adds a list of offending files to the danger comment

@return [void]

todos() click to toggle source

Returns the list of todos in the current diff set

@return [Array of todos]

# File lib/todoist/plugin.rb, line 88
def todos
  find_todos if @todos.nil?
  @todos
end
warn_for_todos() click to toggle source

Adds a warning if there are todos found in the modified code

@return [void]

# File lib/todoist/plugin.rb, line 54
def warn_for_todos
  call_method_for_todos(:warn)
end

Private Instance Methods

call_method_for_todos(method) click to toggle source
# File lib/todoist/plugin.rb, line 102
def call_method_for_todos(method)
  find_todos if @todos.nil?
  public_send(method, message, sticky: false) unless @todos.empty?
end
diffs_of_interest() click to toggle source

for whatever reason nils/false weird things creep into the files_of_interest. We have to make sure to only try to look up diffs for actual filepaths (strings)

# File lib/todoist/plugin.rb, line 132
def diffs_of_interest
  files_of_interest.map do |file|
    diff = EmptyDiff.new
    begin
      diff = git.diff_for_file(file)
    rescue NoMethodError
      log_unable_to_find_diff(file.inspect)
    end
    diff
  end
end
files_of_interest() click to toggle source
# File lib/todoist/plugin.rb, line 125
def files_of_interest
  git.modified_files + git.added_files
end
find_todos() click to toggle source
# File lib/todoist/plugin.rb, line 107
def find_todos
  @todos = []
  return if files_of_interest.empty?

  @todos = finders
           .map { |finder_class| finder_class.new(keywords) }
           .map { |finder| finder.call(diffs_of_interest) }
           .flatten
end
finders() click to toggle source
# File lib/todoist/plugin.rb, line 148
def finders
  [DiffTodoFinder]
end
keywords() click to toggle source
# File lib/todoist/plugin.rb, line 117
def keywords
  @keywords || DEFAULT_KEYWORDS
end
log_unable_to_find_diff(file) click to toggle source
# File lib/todoist/plugin.rb, line 144
def log_unable_to_find_diff(file)
  markdown("* danger-todoist was unable to determine diff for \"#{file}\".")
end
message() click to toggle source
# File lib/todoist/plugin.rb, line 121
def message
  @message || DEFAULT_MESSAGE
end
print_todos_per_file(file, todos) click to toggle source