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

allow custom cmd option for rubocop #48

Merged
merged 2 commits into from
Aug 27, 2021
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ all_on_start: true # Check all files at Guard startup.
cli: '--rails' # Pass arbitrary RuboCop CLI arguments.
# An array or string is acceptable.
# default: nil
cmd: './bin/rubocop' # Pass custom cmd to run rubocop.
# default: rubocop

hide_stdout: false # Do not display console output (in case outputting to file).
# default: false
keep_failed: true # Keep failed files until they pass.
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(paths = [])
end

def build_command(paths)
command = ['rubocop']
command = [@options[:cmd] || 'rubocop']

if should_add_default_formatter_for_console?
command.concat(%w[--format progress]) # Keep default formatter for console.
Expand Down
16 changes: 16 additions & 0 deletions spec/guard/rubocop/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@
let(:options) { { cli: %w[--debug --rails] } }
let(:paths) { %w[file1.rb file2.rb] }

describe ':cmd option' do
context 'when set' do
let(:options) { { cmd: 'bin/rubocop' } }

it 'uses the supplied :cmd' do
expect(build_command[0]).to eq('bin/rubocop')
end
end

context 'when not set' do
it 'uses the default command' do
expect(build_command[0]).to eq('rubocop')
end
end
end

context 'when :hide_stdout is not set' do
context 'and :cli option includes formatter for console' do
before { options[:cli] = %w[--format simple] }
Expand Down