Skip to content

Commit

Permalink
Use Rainbow instead of Colorize
Browse files Browse the repository at this point in the history
Colorize monkey-patches String, which Rainbow doesn't.
  • Loading branch information
bquorning committed Sep 5, 2018
1 parent 577dae2 commit 75361ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ PATH
erb_lint (0.0.26)
activesupport
better_html (~> 1.0.7)
colorize
html_tokenizer
rainbow
rubocop (~> 0.51)
smart_properties

Expand Down Expand Up @@ -33,7 +33,6 @@ GEM
parser (>= 2.4)
smart_properties
builder (3.2.3)
colorize (0.8.1)
concurrent-ruby (1.0.5)
crass (1.0.4)
diff-lcs (1.3)
Expand Down
2 changes: 1 addition & 1 deletion erb_lint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency 'rubocop', '~> 0.51'
s.add_dependency 'activesupport'
s.add_dependency 'smart_properties'
s.add_dependency 'colorize'
s.add_dependency 'rainbow'

s.add_development_dependency 'rspec'
s.add_development_dependency 'rubocop'
Expand Down
22 changes: 12 additions & 10 deletions lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'optparse'
require 'psych'
require 'yaml'
require 'colorize'
require 'rainbow'

module ERBLint
class CLI
Expand Down Expand Up @@ -57,33 +57,35 @@ def run(args = ARGV)
rescue => e
puts "Exception occured when processing: #{relative_filename(filename)}"
puts e.message
puts e.backtrace.join("\n").red
puts Rainbow(e.backtrace.join("\n")).red
puts
end
end

if @stats.corrected > 0
corrected_found_diff = @stats.found - @stats.corrected
if corrected_found_diff > 0
warn "#{@stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files".red
warn Rainbow(
"#{@stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files"
).red
else
puts "#{@stats.corrected} error(s) corrected in ERB files".green
puts Rainbow("#{@stats.corrected} error(s) corrected in ERB files").green
end
elsif @stats.found > 0
warn "#{@stats.found} error(s) were found in ERB files".red
warn Rainbow("#{@stats.found} error(s) were found in ERB files").red
else
puts "No errors were found in ERB files".green
puts Rainbow("No errors were found in ERB files").green
end

@stats.found == 0
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, ExitWithFailure => e
warn e.message.red
warn Rainbow(e.message).red
false
rescue ExitWithSuccess => e
puts e.message
true
rescue => e
warn "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}".red
warn Rainbow("#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}").red
false
end

Expand Down Expand Up @@ -120,7 +122,7 @@ def run_with_corrections(filename)
@stats.found += runner.offenses.size
runner.offenses.each do |offense|
puts <<~EOF
#{offense.message}#{' (not autocorrected)'.red if autocorrect?}
#{offense.message}#{Rainbow(' (not autocorrected)').red if autocorrect?}
In file: #{relative_filename(filename)}:#{offense.line_range.begin}
EOF
Expand All @@ -142,7 +144,7 @@ def load_config
config = RunnerConfig.new(file_loader.yaml(config_filename))
@config = RunnerConfig.default.merge(config)
else
warn "#{config_filename} not found: using default config".yellow
warn Rainbow("#{config_filename} not found: using default config").yellow
@config = RunnerConfig.default
end
@config.merge!(runner_config_override)
Expand Down

0 comments on commit 75361ab

Please sign in to comment.