Sha256: 988e9b86b9875e0ef094b79f82add91d0fe623814fe3e50f19059ee8c0b4d570
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
module TodoLint # Here we bring together all the pieces and see if it comes together # TODO: test this class somehow class Cli # Startup the thing that actually checks the files for todos! # @example # Cli.new([".rb", ".js"]) # @api public def initialize(extensions = []) @path = File.expand_path(".") @extensions = extensions end # @example # Cli.new([".rb"]).run! # @return exit code 0 for success, 1 for failure # @api public # rubocop:disable Metrics/AbcSize def run! # rubocop:disable Metrics/MethodLength finder = FileFinder.new(File.expand_path(".")) files = finder.list(*extensions) files_count = files.count reports = files.map do |file| Todo.within(File.open(file)).map do |todo| reporter = Reporter.new(todo, :path => file, :judge => Judge.new(todo)) reporter.report.tap do |report| print Rainbow(".").public_send(report.nil? ? :green : :red) end end end.flatten.compact if reports.any? reports.each do |report| puts report end puts "\nFound #{pluralize('problematic todo', reports.count)} in " \ "#{pluralize('file', files_count)}" exit 1 else puts "\nGreat job! No overdue todos in " \ "#{pluralize('file', files_count)}" exit 0 end end private # Which file extensions are we checking? # @return [Array<String>] # @api private attr_reader :extensions # Where are we looking for files? # @return [String] # @api private attr_reader :path # Pluralize a word based on the count # @return [String] # @api private def pluralize(word, count) s = count == 1 ? "" : "s" "#{count} #{word + s}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
todo_lint-0.1.1 | lib/todo_lint/cli.rb |