class TodoLint::Reporter

We want to be able to report to users about the todos in their code, and the Reporter is responsible for passing judgment and generating output

Attributes

judge[R]

The object responsible for charging the todo with a crime, or not @return [Judge] @api private

path[R]

The path to the file containing the todo @return [String] @api private

todo[R]

The todo being reported on @return [Todo] @api private

Public Class Methods

new(todo, judge: RequiredArg.new) click to toggle source

Accept a todo and a path to check for problems @example

Reporter.new(todo,
  judge: Judge.new(todo))

@api public

# File lib/todo_lint/reporter.rb, line 10
def initialize(todo, judge: RequiredArg.new)
  @todo = todo
  @path = todo.path
  @judge = judge
end

Public Instance Methods

report() click to toggle source

Generate the output to show the user about their todo @example

reporter.report

@return [String] if the todo is problematic @return [NilClass] if the todo is fine @api public

# File lib/todo_lint/reporter.rb, line 22
def report
  return if judge.charge.nil?

  "#{todo_location} #{problem}\n" \
  "#{todo.line.chomp.lstrip}\n" \
  "#{spaces}#{carets}"
end

Private Instance Methods

carets() click to toggle source

Generate the ^^^^ characters to point at the flag @return [String] @api private

# File lib/todo_lint/reporter.rb, line 78
def carets
  "^" * todo.flag.length
end
number_of_spaces() click to toggle source

How many spaces before the carets should there be? @return [Fixnum] @api private

# File lib/todo_lint/reporter.rb, line 71
def number_of_spaces
  todo.character_number - 1 - (todo.line.length - todo.line.lstrip.length)
end
problem() click to toggle source

The reason we are reporting on this todo @return [String] @api private

# File lib/todo_lint/reporter.rb, line 57
def problem
  Rainbow(judge.charge).red
end
spaces() click to toggle source

Generate the indentation before the carets @return [String] @api private

# File lib/todo_lint/reporter.rb, line 64
def spaces
  " " * number_of_spaces
end
todo_location() click to toggle source

Which file, line, and character can the todo be found at? @return [String] @api private

# File lib/todo_lint/reporter.rb, line 50
def todo_location
  Rainbow(path).green + ":#{todo.line_number}:#{todo.character_number}"
end