Skip to content

Commit 0fdb556

Browse files
authored
Allow custom cmd option for rubocop (#48)
1 parent d43c44d commit 0fdb556

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ all_on_start: true # Check all files at Guard startup.
6161
cli: '--rails' # Pass arbitrary RuboCop CLI arguments.
6262
# An array or string is acceptable.
6363
# default: nil
64+
cmd: './bin/rubocop' # Pass custom cmd to run rubocop.
65+
# default: rubocop
66+
6467
hide_stdout: false # Do not display console output (in case outputting to file).
6568
# default: false
6669
keep_failed: true # Keep failed files until they pass.

lib/guard/rubocop/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run(paths = [])
2828
end
2929

3030
def build_command(paths)
31-
command = ['rubocop']
31+
command = [@options[:cmd] || 'rubocop']
3232

3333
if should_add_default_formatter_for_console?
3434
command.concat(%w[--format progress]) # Keep default formatter for console.

spec/guard/rubocop/runner_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@
109109
let(:options) { { cli: %w[--debug --rails] } }
110110
let(:paths) { %w[file1.rb file2.rb] }
111111

112+
describe ':cmd option' do
113+
context 'when set' do
114+
let(:options) { { cmd: 'bin/rubocop' } }
115+
116+
it 'uses the supplied :cmd' do
117+
expect(build_command[0]).to eq('bin/rubocop')
118+
end
119+
end
120+
121+
context 'when not set' do
122+
it 'uses the default command' do
123+
expect(build_command[0]).to eq('rubocop')
124+
end
125+
end
126+
end
127+
112128
context 'when :hide_stdout is not set' do
113129
context 'and :cli option includes formatter for console' do
114130
before { options[:cli] = %w[--format simple] }

0 commit comments

Comments
 (0)