From af8b5f97fa0df91bb35be9f43061acf52b91330b Mon Sep 17 00:00:00 2001 From: Jason Dougherty Date: Mon, 6 Mar 2023 01:47:54 -0800 Subject: [PATCH] [Fix #11164] Suppress server mode message with -f json (#11668) --- ...ocop_11164_suppress_server_mode_message.md | 1 + lib/rubocop/server/core.rb | 2 +- spec/rubocop/server/rubocop_server_spec.rb | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_fix_rubocop_11164_suppress_server_mode_message.md diff --git a/changelog/fix_fix_rubocop_11164_suppress_server_mode_message.md b/changelog/fix_fix_rubocop_11164_suppress_server_mode_message.md new file mode 100644 index 00000000000..a17cec5a71f --- /dev/null +++ b/changelog/fix_fix_rubocop_11164_suppress_server_mode_message.md @@ -0,0 +1 @@ +* [#11164](https://github.com/rubocop/rubocop/issues/11164): Suppress server mode message with `-f json`. ([@jasondoc3][]) diff --git a/lib/rubocop/server/core.rb b/lib/rubocop/server/core.rb index 66555d4ae2e..2b96e26c98a 100644 --- a/lib/rubocop/server/core.rb +++ b/lib/rubocop/server/core.rb @@ -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] diff --git a/spec/rubocop/server/rubocop_server_spec.rb b/spec/rubocop/server/rubocop_server_spec.rb index 226d875052b..13683421007 100644 --- a/spec/rubocop/server/rubocop_server_spec.rb +++ b/spec/rubocop/server/rubocop_server_spec.rb @@ -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