Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/erb_lint/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(config, cache_dir = nil)
@cache_dir = cache_dir || CACHE_DIRECTORY
@hits = []
@new_results = []
puts "Cache mode is on"
$stderr.puts "Cache mode is on"
end

def get(filename, file_content)
Expand Down Expand Up @@ -44,7 +44,7 @@ def close

def prune_cache
if hits.empty?
puts "Cache being created for the first time, skipping prune"
$stderr.puts "Cache being created for the first time, skipping prune"
return
end

Expand All @@ -63,7 +63,7 @@ def cache_dir_exists?
def clear
return unless cache_dir_exists?

puts "Clearing cache by deleting cache directory"
$stderr.puts "Clearing cache by deleting cache directory"
FileUtils.rm_r(@cache_dir)
end

Expand Down
22 changes: 11 additions & 11 deletions lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def run(args = ARGV)
file_content = run_on_file(runner, filename)
rescue => e
@stats.exceptions += 1
puts "Exception occurred when processing: #{relative_filename(filename)}"
puts "If this file cannot be processed by erb_lint, " \
$stderr.puts "Exception occurred when processing: #{relative_filename(filename)}"
$stderr.puts "If this file cannot be processed by erb_lint, " \
"you can exclude it in your configuration file."
puts e.message
puts Rainbow(e.backtrace.join("\n")).red
puts
$stderr.puts e.message
$stderr.puts Rainbow(e.backtrace.join("\n")).red
$stderr.puts
end
end

Expand All @@ -102,19 +102,19 @@ def run(args = ARGV)

if stdin? && autocorrect?
# When running from stdin, we only lint a single file
puts "================ #{lint_files.first} ==================\n"
$stderr.puts "================ #{lint_files.first} =================="
puts file_content
end

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

Expand Down Expand Up @@ -218,11 +218,11 @@ def load_config
deprecation_message = "The config file has been renamed to `#{DEFAULT_CONFIG_FILENAME}` and " \
"`#{DEPRECATED_CONFIG_FILENAME}` is deprecated. " \
"Please rename your config file to `#{DEFAULT_CONFIG_FILENAME}`."
warn(Rainbow(deprecation_message).yellow)
$stderr.puts(Rainbow(deprecation_message).yellow)
config = RunnerConfig.new(file_loader.yaml(DEPRECATED_CONFIG_FILENAME), file_loader)
@config = RunnerConfig.default_for(config)
else
warn(Rainbow("#{config_filename} not found: using default config").yellow)
$stderr.puts(Rainbow("#{config_filename} not found: using default config").yellow)
@config = RunnerConfig.default
end
rescue Psych::SyntaxError => e
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linter_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_custom_linters(directory = CUSTOM_LINTERS_DIR)
if deprecated_ruby_files.any?
deprecation_message = "The '#{DEPRECATED_CUSTOM_LINTERS_DIR}' directory for custom linters is deprecated. " \
"Please rename it to '#{CUSTOM_LINTERS_DIR}'"
warn(Rainbow(deprecation_message).yellow)
$stderr.puts(Rainbow(deprecation_message).yellow)
ruby_files.concat(deprecated_ruby_files)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/erb_lint/reporters/compact_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module ERBLint
module Reporters
class CompactReporter < Reporter
def preview
puts "#{linting} #{stats.files} files with #{linters}..."
$stderr.puts "#{linting} #{stats.files} files with #{linters}..."
end

def show
processed_files.each do |filename, offenses|
offenses.each do |offense|
puts format_offense(filename, offense)
$stderr.puts format_offense(filename, offense)
end
end

Expand Down Expand Up @@ -45,14 +45,14 @@ def summary
report_corrected_offenses
elsif stats.ignored > 0 || stats.found > 0
if stats.ignored > 0
warn(Rainbow("#{stats.ignored} error(s) were ignored in ERB files").yellow)
$stderr.puts(Rainbow("#{stats.ignored} error(s) were ignored in ERB files").yellow)
end

if stats.found > 0
warn(Rainbow("#{stats.found} error(s) were found in ERB files").red)
$stderr.puts(Rainbow("#{stats.found} error(s) were found in ERB files").red)
end
else
puts Rainbow("No errors were found in ERB files").green
$stderr.puts Rainbow("No errors were found in ERB files").green
end
end

Expand All @@ -64,9 +64,9 @@ def report_corrected_offenses
"#{stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files",
).red

warn(message)
$stderr.puts(message)
else
puts Rainbow("#{stats.corrected} error(s) corrected in ERB files").green
$stderr.puts Rainbow("#{stats.corrected} error(s) corrected in ERB files").green
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/reporters/multiline_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def format_offense(filename, offense)
end

def footer
puts
$stderr.puts
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/erb_lint/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
it "skips prune if no cache hits" do
allow(cache).to(receive(:hits).and_return([]))

expect { cache.prune_cache }.to(output(/Cache being created for the first time, skipping prune/).to_stdout)
expect { cache.prune_cache }.to(output(/Cache being created for the first time, skipping prune/).to_stderr)
end

it "does not prune actual cache hits" do
Expand Down
51 changes: 26 additions & 25 deletions spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ def run(processed_source)

context "with --version" do
let(:args) { ["--version"] }
it { expect { subject }.to(output("#{ERBLint::VERSION}\n").to_stdout) }
it { expect { subject }.to(output("#{ERBLint::VERSION}\n").to_stderr) }
end

context "with --help" do
let(:args) { ["--help"] }

it "shows usage" do
expect { subject }.to(output(/erblint \[options\] \[file1, file2, ...\]/).to_stdout)
expect { subject }.to(output(/erblint \[options\] \[file1, file2, ...\]/).to_stderr)
end

it "shows format instructions" do
expect { subject }.to(
output(Regexp.new("Report offenses in the given format: " \
"\\(compact, gitlab, json, junit, multiline\\) " \
"\\(default: multiline\\)")).to_stdout,
"\\(default: multiline\\)")).to_stderr,
)
end

Expand Down Expand Up @@ -143,7 +143,7 @@ def run(processed_source)
end

it "shows all errors regardless of inline disables " do
expect { subject }.to(output(/ERBLint::Linters::FakeLinter error/).to_stdout)
expect { subject }.to(output(/ERBLint::Linters::FakeLinter error/).to_stderr)
end
end

Expand All @@ -163,7 +163,8 @@ def run(processed_source)
it {
expect do
subject
end.to(output(<<~EOF).to_stdout)
end.to(output(<<~EOF).to_stderr)
#{Rainbow(".erb_lint.yml not found: using default config").yellow}
Cache mode is on
Clearing cache by deleting cache directory
cache directory cleared
Expand Down Expand Up @@ -217,7 +218,7 @@ def run(processed_source)
end

it "uses the specified directory" do
expect { subject }.to(output(/cache directory cleared/).to_stdout)
expect { subject }.to(output(/cache directory cleared/).to_stderr)
end
end

Expand Down Expand Up @@ -247,12 +248,12 @@ def run(processed_source)
end

it "shows how many files and linters are used" do
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stdout)
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stderr)
end

context "when errors are found" do
it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake message from a fake linter
In file: /app/views/template.html.erb:1
Expand All @@ -276,7 +277,7 @@ def run(processed_source)
let(:args) { ["--enable-linter", "linter_with_info_errors", linted_file] }

it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake info message from a fake linter
In file: /app/views/template.html.erb:1
Expand All @@ -297,7 +298,7 @@ def run(processed_source)
let(:args) { ["--enable-linter", "linter_without_errors", linted_file] }

it "shows that no errors were found to stdout" do
expect { subject }.to(output(/No errors were found in ERB files/).to_stdout)
expect { subject }.to(output(/No errors were found in ERB files/).to_stderr)
end

it "is successful" do
Expand Down Expand Up @@ -327,7 +328,7 @@ def run(processed_source)
it "lints the file and adds it to the cache" do
expect(Dir[ERBLint::Cache::CACHE_DIRECTORY].length).to(be(0))

expect { subject }.to(output(/Cache mode is on/).to_stdout)
expect { subject }.to(output(/Cache mode is on/).to_stderr)
expect(subject).to(be(true))

expect(Dir[ERBLint::Cache::CACHE_DIRECTORY].length).to(be(1))
Expand All @@ -350,7 +351,7 @@ def run(processed_source)
context "with the default glob" do
it "shows how many files and linters are used" do
allow(cli).to(receive(:glob).and_return(cli.class::DEFAULT_LINT_ALL_GLOB))
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stdout)
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stderr)
end
end

Expand All @@ -377,7 +378,7 @@ def run(processed_source)

context "with the default glob" do
it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake info message from a fake linter
In file: /app/views/template.html.erb:1
Expand All @@ -400,7 +401,7 @@ def run(processed_source)

context "with the default glob" do
it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake info message from a fake linter
In file: /app/views/template.html.erb:1
Expand Down Expand Up @@ -464,12 +465,12 @@ def run(processed_source)
end

it "shows how many files and linters are used" do
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stdout)
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stderr)
end

context "when errors are found" do
it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake message from a fake linter
In file: /app/views/template.html.erb:1
Expand Down Expand Up @@ -501,7 +502,7 @@ def run(processed_source)
end

it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)
/app/views/template.html.erb:1:1: fake message from a fake linter
/app/views/template.html.erb:1:19: Missing a trailing newline at the end of the file.
EOF
Expand Down Expand Up @@ -543,7 +544,7 @@ def run(processed_source)
let(:args) { ["--enable-linter", "linter_without_errors", linted_dir] }

it "shows that no errors were found to stdout" do
expect { subject }.to(output(/No errors were found in ERB files/).to_stdout)
expect { subject }.to(output(/No errors were found in ERB files/).to_stderr)
end

it "is successful" do
Expand All @@ -556,7 +557,7 @@ def run(processed_source)
it "lints the file and adds it to the cache" do
expect(Dir[ERBLint::Cache::CACHE_DIRECTORY].length).to(be(0))

expect { subject }.to(output(/Cache mode is on/).to_stdout)
expect { subject }.to(output(/Cache mode is on/).to_stderr)
expect(subject).to(be(true))

expect(Dir[ERBLint::Cache::CACHE_DIRECTORY].length).to(be(1))
Expand Down Expand Up @@ -623,12 +624,12 @@ def run(processed_source)
end

it "shows how many files and linters are used" do
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stdout)
expect { subject }.to(output(/Linting 1 files with 2 linters/).to_stderr)
end

context "when errors are found" do
it "shows all error messages and line numbers" do
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stdout)
expect { subject }.to(output(Regexp.new(Regexp.escape(<<~EOF))).to_stderr)

fake message from a fake linter
In file: /app/views/template.html.erb:1
Expand All @@ -654,11 +655,11 @@ def run(processed_source)
end

it "tells the user it is autocorrecting" do
expect { subject }.to(output(/Linting and autocorrecting/).to_stdout)
expect { subject }.to(output(/Linting and autocorrecting/).to_stderr)
end

it "shows how many total and autocorrectable linters are used" do
expect { subject }.to(output(/2 linters \(1 autocorrectable\)/).to_stdout)
expect { subject }.to(output(/2 linters \(1 autocorrectable\)/).to_stderr)
end

it "outputs the corrected ERB" do
Expand All @@ -682,7 +683,7 @@ def run(processed_source)
let(:args) { ["--enable-linter", "linter_without_errors", "--stdin", linted_file] }

it "shows that no errors were found to stdout" do
expect { subject }.to(output(/No errors were found in ERB files/).to_stdout)
expect { subject }.to(output(/No errors were found in ERB files/).to_stderr)
end

it "is successful" do
Expand Down Expand Up @@ -721,7 +722,7 @@ def run(processed_source)
end

it "exits with success status" do
expect { subject }.to(output(/no files found\.\.\./).to_stdout)
expect { subject }.to(output(/no files found\.\.\./).to_stderr)
expect(subject).to(be(true))
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/erb_lint/linter_registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class FakeLinter < ERBLint::Linter
stub_const("ERBLint::LinterRegistry::DEPRECATED_CUSTOM_LINTERS_DIR", custom_directory)

expected_warning = Rainbow("The '#{custom_directory}' directory for custom linters is deprecated. " \
"Please rename it to '.erb_linters'").yellow
expect(described_class).to(receive(:warn).with(expected_warning).once)
described_class.load_custom_linters
"Please rename it to '.erb_linters'").yellow + "\n"
expect { described_class.load_custom_linters }.to(output(expected_warning).to_stderr)
end
end
end
Loading
Loading