diff --git a/lib/erb_lint/cli.rb b/lib/erb_lint/cli.rb index 46c204f6..0e53d279 100644 --- a/lib/erb_lint/cli.rb +++ b/lib/erb_lint/cli.rb @@ -42,6 +42,10 @@ def run(args = ARGV) if !@files.empty? && lint_files.empty? failure!("no files found...\n") elsif lint_files.empty? + if @options[:prevent_empty_failure] + success!('No files found or given, skipping because "--prevent-empty-failure" flag was passed') + end + failure!("no files found or given, specify files or config...\n#{option_parser}") end @@ -280,6 +284,10 @@ def option_parser @options[:autocorrect] = config end + opts.on("--prevent-empty-failure", "Skip the linter check if no files match the given glob [default: #{DEFAULT_LINT_ALL_GLOB}]") do + @options[:prevent_empty_failure] = true + end + opts.on_tail("-h", "--help", "Show this message") do success!(opts) end diff --git a/spec/erb_lint/cli_spec.rb b/spec/erb_lint/cli_spec.rb index 794e0cb7..dd26c863 100644 --- a/spec/erb_lint/cli_spec.rb +++ b/spec/erb_lint/cli_spec.rb @@ -273,6 +273,19 @@ def run(_processed_source) end end + context 'with --prevent-empty-failure' do + let(:args) { ['--prevent-empty-failure'] } + + context 'when there are no files' do + before do + allow(cli).to(receive(:glob).and_return("no/file/glob")) + end + + it { expect { subject }.not_to output(/no files found/).to_stderr } + it { expect { subject }.to output(/No files found or given, skipping because "--prevent-empty-failure" flag was passed/).to_stdout } + end + end + context 'with unknown argument' do let(:args) { ['--foo'] }