Skip to content
Closed
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: 5 additions & 1 deletion lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than introducing a new option, can we just assume that when the 'none' reporter is being used, we ignore the header?

puts file_content
end

Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/erb_lint/reporters/none_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module ERBLint
module Reporters
class NoneReporter < Reporter
def preview
end

def show
end
end
end
end
45 changes: 44 additions & 1 deletion spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -532,6 +532,7 @@ def run(processed_source)
- json
- junit
- multiline
- none
EOF
end

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down