Skip to content

Commit

Permalink
Merge pull request #550 from gjtorikian/new-ruby-issues
Browse files Browse the repository at this point in the history
Fix mysterious new ruby issues
  • Loading branch information
gjtorikian committed Jan 20, 2020
2 parents 9de2624 + a0af214 commit a55e400
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ spec/reports
test/tmp
test/version_tmp
tmp
vendor/cache

Gemfile.lock
out/
Expand Down
3 changes: 0 additions & 3 deletions .rubocop.yml
Expand Up @@ -6,9 +6,6 @@ Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

RequireParentheses:
Enabled: true

Naming/FileName:
Enabled: false

Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -4,6 +4,8 @@ rvm:
- 2.4.3
- 2.5.0
- 2.6.0
- 2.7.0
- ruby-head

git:
depth: 10
Expand All @@ -16,6 +18,8 @@ sudo: false
cache: bundler

matrix:
allow_failures:
- rvm: ruby-head
include:
- script: bundle exec rake rubocop
rvm: 2.6.0
rvm: 2.7.0
2 changes: 1 addition & 1 deletion lib/html-proofer.rb
Expand Up @@ -2,7 +2,7 @@

def require_all(path)
dir = File.join(File.dirname(__FILE__), path)
Dir[File.join(dir, '*.rb')].each do |f|
Dir[File.join(dir, '*.rb')].sort.each do |f|
require f
end
end
Expand Down
26 changes: 15 additions & 11 deletions lib/html-proofer/log.rb
Expand Up @@ -7,16 +7,27 @@ module HTMLProofer
class Log
include Yell::Loggable

STDOUT_LEVELS = %i[debug info warn].freeze
STDERR_LEVELS = %i[error fatal].freeze

def initialize(log_level)
@logger = Yell.new(format: false, \
name: 'HTMLProofer', \
level: "gte.#{log_level}") do |l|
l.adapter :stdout, level: %i[debug info warn]
l.adapter :stderr, level: %i[error fatal]
l.adapter :stdout, level: 'lte.warn'
l.adapter :stderr, level: 'gte.error'
end
end

def log(level, message)
log_with_color(level, message)
end

def log_with_color(level, message)
@logger.send level, colorize(level, message)
end

def colorize(level, message)
color = case level
when :debug
:cyan
Expand All @@ -28,15 +39,8 @@ def log(level, message)
:red
end

log_with_color(level, color, message)
end

def log_with_color(level, color, message)
@logger.send level, colorize(color, message)
end

def colorize(color, message)
if $stdout.isatty && $stderr.isatty
if (STDOUT_LEVELS.include?(level) && $stdout.isatty) || \
(STDERR_LEVELS.include?(level) && $stderr.isatty)
Rainbow(message).send(color)
else
message
Expand Down
4 changes: 2 additions & 2 deletions lib/html-proofer/runner.rb
Expand Up @@ -45,7 +45,7 @@ def run
end

if @failures.empty?
@logger.log_with_color :info, :green, 'HTML-Proofer finished successfully.'
@logger.log :info, 'HTML-Proofer finished successfully.'
else
print_failed_tests
end
Expand Down Expand Up @@ -169,7 +169,7 @@ def print_failed_tests
sorted_failures.sort_and_report
count = @failures.length
failure_text = pluralize(count, 'failure', 'failures')
raise @logger.colorize :red, "HTML-Proofer found #{failure_text}!"
raise @logger.colorize :fatal, "HTML-Proofer found #{failure_text}!"
end
end
end

0 comments on commit a55e400

Please sign in to comment.