From 5315f45c08e42b9649e140efafea1254b9717a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Rothenberger?= Date: Thu, 5 Sep 2024 23:09:44 +0200 Subject: [PATCH 1/3] Add NoneReporter --- lib/erb_lint/reporters/none_reporter.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/erb_lint/reporters/none_reporter.rb diff --git a/lib/erb_lint/reporters/none_reporter.rb b/lib/erb_lint/reporters/none_reporter.rb new file mode 100644 index 0000000..5bdc06e --- /dev/null +++ b/lib/erb_lint/reporters/none_reporter.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module ERBLint + module Reporters + class NoneReporter < Reporter + def preview + end + + def show + end + end + end +end From a8892c05a7384ec9ffcec55ef486ca43bd4a4b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Rothenberger?= Date: Fri, 6 Sep 2024 23:25:18 +0200 Subject: [PATCH 2/3] Add option to hide file header from stdin/autocorrect flow --- lib/erb_lint/cli.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/erb_lint/cli.rb b/lib/erb_lint/cli.rb index 34b847a..79225ab 100644 --- a/lib/erb_lint/cli.rb +++ b/lib/erb_lint/cli.rb @@ -102,7 +102,7 @@ def run(args = ARGV) if stdin? && autocorrect? # When running from stdin, we only lint a single file - puts "================ #{lint_files.first} ==================\n" + puts "================ #{lint_files.first} ==================\n" unless @options[:no_file_header] puts file_content end @@ -403,6 +403,10 @@ def option_parser @options[:stdin] = [file] end + opts.on("--no-file-header", "Disable file header while reading from stding for autocorrect.") do + @options[:no_file_header] = true + end + opts.on_tail("-h", "--help", "Show this message") do success!(opts) end From 52e2af6542139c58c40492122408ea83eae92d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Rothenberger?= Date: Fri, 6 Sep 2024 23:25:45 +0200 Subject: [PATCH 3/3] Add specs --- spec/erb_lint/cli_spec.rb | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/spec/erb_lint/cli_spec.rb b/spec/erb_lint/cli_spec.rb index 40e1678..f8da8a8 100644 --- a/spec/erb_lint/cli_spec.rb +++ b/spec/erb_lint/cli_spec.rb @@ -93,7 +93,7 @@ def run(processed_source) it "shows format instructions" do expect { subject }.to( output(Regexp.new("Report offenses in the given format: " \ - "\\(compact, gitlab, json, junit, multiline\\) " \ + "\\(compact, gitlab, json, junit, multiline, none\\) " \ "\\(default: multiline\\)")).to_stdout, ) end @@ -532,6 +532,7 @@ def run(processed_source) - json - junit - multiline + - none EOF end @@ -654,6 +655,8 @@ def run(processed_source) ["--enable-linter", "final_newline,linter_with_errors", "--stdin", linted_file, "--autocorrect"] end + let(:full_linted_file_path) { "#{Dir.pwd}/#{linted_file}" } + it "tells the user it is autocorrecting" do expect { subject }.to(output(/Linting and autocorrecting/).to_stdout) end @@ -662,9 +665,49 @@ def run(processed_source) expect { subject }.to(output(/2 linters \(1 autocorrectable\)/).to_stdout) end + it "outputs file header" do + expect { subject }.to(output(/#{linted_file} ==================\n/).to_stdout) + end + it "outputs the corrected ERB" do expect { subject }.to(output(/#{file_content}\n/).to_stdout) end + + context "when file header was turned of" do + let(:args) do + [ + "--enable-linter", + "final_newline,linter_with_errors", + "--stdin", + linted_file, + "--autocorrect", + "--no-file-header", + ] + end + + it "does not output file header" do + expect { subject }.not_to(output(/#{linted_file} ==================\n/).to_stdout) + end + + context "when format is none" do + let(:args) do + [ + "--enable-linter", + "final_newline,linter_with_errors", + "--stdin", + linted_file, + "--autocorrect", + "--no-file-header", + "--format", + "none", + ] + end + + it "outputs only the corrected ERB" do + expect { subject }.to(output("#{file_content}\n").to_stdout) + end + end + end end context "when autocorrecting and caching are turned on" do