Skip to content

Commit

Permalink
Merge pull request #270 from leighhalliday/allow-no-files
Browse files Browse the repository at this point in the history
Option to allow for no files
  • Loading branch information
rafaelfranca authored Aug 18, 2022
2 parents bbfed93 + ee6366e commit 13517f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def run(args = ARGV)
load_config

if !@files.empty? && lint_files.empty?
failure!("no files found...\n")
if allow_no_files?
success!("no files found...\n")
else
failure!("no files found...\n")
end
elsif lint_files.empty?
failure!("no files found or given, specify files or config...\n#{option_parser}")
end
Expand Down Expand Up @@ -302,6 +306,10 @@ def option_parser
@options[:autocorrect] = config
end

opts.on("--allow-no-files", "When no matching files found, exit successfully (default: false)") do |config|
@options[:allow_no_files] = config
end

opts.on(
"-sFILE",
"--stdin FILE",
Expand Down Expand Up @@ -333,5 +341,9 @@ def invalid_format_error_message(given_format)
def stdin?
@options[:stdin].present?
end

def allow_no_files?
@options[:allow_no_files]
end
end
end
16 changes: 16 additions & 0 deletions spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,22 @@ def run(processed_source)
expect { subject }.to(output(/no files found\.\.\./).to_stderr)
expect(subject).to(be(false))
end

context "allowing for no matching files" do
let(:args) do
[
"--config", config_file,
"--enable-linter", "linter_with_errors,final_newline",
"--stdin", linted_file,
"--allow-no-files",
]
end

it "exits with success status" do
expect { subject }.to(output(/no files found\.\.\./).to_stdout)
expect(subject).to(be(true))
end
end
end
end
end
Expand Down

0 comments on commit 13517f3

Please sign in to comment.