Skip to content

Commit

Permalink
[Fix #11164] Suppress server mode message with -f json (#11668)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondoc3 committed Mar 6, 2023
1 parent 8257ff2 commit af8b5f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
@@ -0,0 +1 @@
* [#11164](https://github.com/rubocop/rubocop/issues/11164): Suppress server mode message with `-f json`. ([@jasondoc3][])
2 changes: 1 addition & 1 deletion lib/rubocop/server/core.rb
Expand Up @@ -100,7 +100,7 @@ def read_socket(socket)

def use_json_format?
return true if ARGV.include?('--format=json') || ARGV.include?('--format=j')
return false unless (index = ARGV.index('--format'))
return false unless (index = ARGV.index('--format') || ARGV.index('-f'))

format = ARGV[index + 1]

Expand Down
28 changes: 28 additions & 0 deletions spec/rubocop/server/rubocop_server_spec.rb
Expand Up @@ -123,6 +123,34 @@
expect(stdout).not_to start_with 'RuboCop server starting on '
end
end

context 'when `-f json`' do
it 'does not display the server start message' do
create_file('example.rb', <<~RUBY)
puts 0
RUBY

stdout, _stderr, _status = Open3.capture3(
'ruby', '-I', '.',
rubocop, '--server', '-f', 'json', '--stdin', 'example.rb', stdin_data: 'puts 0'
)
expect(stdout).not_to start_with 'RuboCop server starting on '
end
end

context 'when `-f j`' do
it 'does not display the server start message' do
create_file('example.rb', <<~RUBY)
puts 0
RUBY

stdout, _stderr, _status = Open3.capture3(
'ruby', '-I', '.',
rubocop, '--server', '-f', 'j', '--stdin', 'example.rb', stdin_data: 'puts 0'
)
expect(stdout).not_to start_with 'RuboCop server starting on '
end
end
end

context 'when using `--server` option after running server and updating configuration' do
Expand Down

0 comments on commit af8b5f9

Please sign in to comment.