Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --prevent-empty-failure flag #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def run(args = ARGV)
if [email protected]? && 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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }

Expand Down