diff --git a/compiler/cpp/src/thrift/generate/t_rb_generator.cc b/compiler/cpp/src/thrift/generate/t_rb_generator.cc index 4e91a3ec43..4e7920db42 100644 --- a/compiler/cpp/src/thrift/generate/t_rb_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_rb_generator.cc @@ -1009,9 +1009,6 @@ void t_rb_generator::generate_service_client(t_service* tservice) { if (!(*f_iter)->is_oneway()) { f_service_.indent(); - if (!(*f_iter)->get_returntype()->is_void()) { - f_service_ << "return "; - } f_service_ << "recv_" << funname << "()" << '\n'; } f_service_.indent_down(); @@ -1075,7 +1072,7 @@ void t_rb_generator::generate_service_client(t_service* tservice) { // Careful, only return _result if not a void function if ((*f_iter)->get_returntype()->is_void()) { - f_service_.indent() << "return" << '\n'; + f_service_.indent() << "nil" << '\n'; } else { f_service_.indent() << "raise " "::Thrift::ApplicationException.new(::Thrift::ApplicationException::" @@ -1206,7 +1203,7 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function* // Shortcut out here for oneway functions if (tfunction->is_oneway()) { - f_service_.indent() << "return" << '\n'; + f_service_.indent() << "nil" << '\n'; f_service_.indent_down(); f_service_.indent() << "end" << '\n'; return; diff --git a/compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc b/compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc index a97689e742..9675702ebf 100644 --- a/compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc +++ b/compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc @@ -107,6 +107,7 @@ TEST_CASE("t_rb_generator formats service classes and positional arguments", "[f "}\n" "service PingService {\n" " oneway void ping(1: i32 n)\n" + " i32 pong()\n" "}\n"; { @@ -131,6 +132,8 @@ TEST_CASE("t_rb_generator formats service classes and positional arguments", "[f "\n" " FIELDS"; REQUIRE(service.find("send_oneway_message(\"ping\", Ping_args, {n: n})") != string::npos); + REQUIRE(service.find("def pong()\n send_pong()\n recv_pong()\n end") + != string::npos); REQUIRE(service.find(expected_empty_result) != string::npos); REQUIRE(service.find("\n\n end\n") == string::npos); diff --git a/lib/rb/.rubocop.yml b/lib/rb/.rubocop.yml index 6c20f3678a..f9cab6dbb8 100644 --- a/lib/rb/.rubocop.yml +++ b/lib/rb/.rubocop.yml @@ -327,6 +327,9 @@ Style/RedundantInterpolation: Style/RedundantParentheses: Enabled: true +Style/RedundantReturn: + Enabled: true + Style/RedundantSelf: Enabled: true diff --git a/lib/rb/lib/thrift/protocol/binary_protocol.rb b/lib/rb/lib/thrift/protocol/binary_protocol.rb index 441e19f103..9447c2d989 100644 --- a/lib/rb/lib/thrift/protocol/binary_protocol.rb +++ b/lib/rb/lib/thrift/protocol/binary_protocol.rb @@ -285,7 +285,7 @@ def write_i32_size(size) class BinaryProtocolFactory < BaseProtocolFactory def get_protocol(trans) - return Thrift::BinaryProtocol.new(trans) + Thrift::BinaryProtocol.new(trans) end def to_s diff --git a/lib/rb/lib/thrift/protocol/json_protocol.rb b/lib/rb/lib/thrift/protocol/json_protocol.rb index 17ec422059..e2052815b1 100644 --- a/lib/rb/lib/thrift/protocol/json_protocol.rb +++ b/lib/rb/lib/thrift/protocol/json_protocol.rb @@ -34,7 +34,7 @@ def read @data = @trans.read(1) end - return @data + @data end def peek @@ -42,7 +42,7 @@ def peek @data = @trans.read(1) end @hasData = true - return @data + @data end end @@ -69,7 +69,7 @@ def read(reader) # Default behavior is to return false. # def escapeNum - return false + false end end @@ -105,7 +105,7 @@ def read(reader) # Numbers must be turned into strings if they are the key part of a pair def escapeNum - return @colon + @colon end end @@ -219,9 +219,9 @@ def self.read_syntax_char(reader, ch) def is_json_numeric(ch) case ch when "+", "-", ".", "0".."9", "E", "e" - return true + true else - return false + false end end @@ -563,7 +563,7 @@ def read_json_numeric_chars ch = @reader.read str << ch end - return str + str end # Reads a sequence of characters and assembles them into a number, @@ -585,7 +585,7 @@ def read_json_integer read_json_syntax_char(@@kJSONStringDelimiter) end - return num + num end # Reads a JSON number or string and interprets it as a double. @@ -624,7 +624,7 @@ def read_json_double raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected numeric value; got \"#{str}\"") end end - return num + num end def read_json_object_start @@ -821,7 +821,7 @@ def invalid_unicode!(message) class JsonProtocolFactory < BaseProtocolFactory def get_protocol(trans) - return Thrift::JsonProtocol.new(trans) + Thrift::JsonProtocol.new(trans) end def to_s diff --git a/lib/rb/lib/thrift/transport/base_transport.rb b/lib/rb/lib/thrift/transport/base_transport.rb index c971a33524..f1bad6b359 100644 --- a/lib/rb/lib/thrift/transport/base_transport.rb +++ b/lib/rb/lib/thrift/transport/base_transport.rb @@ -73,7 +73,7 @@ def read(sz) # Returns an unsigned byte as a Integer in the range (0..255). def read_byte buf = read_all(1) - return Bytes.get_string_byte(buf, 0) + Bytes.get_string_byte(buf, 0) end # Reads size bytes and copies them into buffer[0..size]. @@ -129,7 +129,7 @@ def to_s class BaseTransportFactory def get_transport(trans) - return trans + trans end def to_s diff --git a/lib/rb/lib/thrift/transport/buffered_transport.rb b/lib/rb/lib/thrift/transport/buffered_transport.rb index 9d1897401e..11abc8d822 100644 --- a/lib/rb/lib/thrift/transport/buffered_transport.rb +++ b/lib/rb/lib/thrift/transport/buffered_transport.rb @@ -31,7 +31,7 @@ def initialize(transport) end def open? - return @transport.open? + @transport.open? end def open @@ -66,7 +66,7 @@ def read_byte # The read buffer has some data now, read a single byte. Using get_string_byte() avoids # allocating a temp string of size 1 unnecessarily. @index += 1 - return Bytes.get_string_byte(@rbuf, @index - 1) + Bytes.get_string_byte(@rbuf, @index - 1) end # Reads a number of bytes from the transport into the buffer passed. @@ -113,7 +113,7 @@ def to_s class BufferedTransportFactory < BaseTransportFactory def get_transport(transport) - return BufferedTransport.new(transport) + BufferedTransport.new(transport) end def to_s diff --git a/lib/rb/lib/thrift/transport/framed_transport.rb b/lib/rb/lib/thrift/transport/framed_transport.rb index 85c3749086..bac745d20e 100644 --- a/lib/rb/lib/thrift/transport/framed_transport.rb +++ b/lib/rb/lib/thrift/transport/framed_transport.rb @@ -61,7 +61,7 @@ def read_byte # The read buffer has some data now, read a single byte. Using get_string_byte() avoids # allocating a temp string of size 1 unnecessarily. @index += 1 - return Bytes.get_string_byte(@rbuf, @index - 1) + Bytes.get_string_byte(@rbuf, @index - 1) end def read_into_buffer(buffer, size) @@ -116,7 +116,7 @@ def read_frame class FramedTransportFactory < BaseTransportFactory def get_transport(transport) - return FramedTransport.new(transport) + FramedTransport.new(transport) end def to_s diff --git a/lib/rb/lib/thrift/transport/memory_buffer_transport.rb b/lib/rb/lib/thrift/transport/memory_buffer_transport.rb index 4f5d1766fb..862c61e8d1 100644 --- a/lib/rb/lib/thrift/transport/memory_buffer_transport.rb +++ b/lib/rb/lib/thrift/transport/memory_buffer_transport.rb @@ -30,7 +30,7 @@ def initialize(buffer = nil) end def open? - return true + true end def open diff --git a/test/rb/integration/TestServer.rb b/test/rb/integration/TestServer.rb index 24a60c61c6..f037bf8ab9 100755 --- a/test/rb/integration/TestServer.rb +++ b/test/rb/integration/TestServer.rb @@ -47,7 +47,7 @@ def testVoid() end def testInsanity(thing) - return { + { 1 => { 2 => thing, 3 => thing, @@ -59,7 +59,7 @@ def testInsanity(thing) end def testMapMap(thing) - return { + { -4 => { -4 => -4, -3 => -3, @@ -76,7 +76,7 @@ def testMapMap(thing) end def testMulti(arg0, arg1, arg2, arg3, arg4, arg5) - return Thrift::Test::Xtruct.new({ + Thrift::Test::Xtruct.new({ "string_thing" => "Hello2", "byte_thing" => arg0, "i32_thing" => arg1, @@ -100,7 +100,7 @@ def testMultiException(arg0, arg1) elsif arg0 == "Xception" raise Thrift::Test::Xception, {errorCode: 1001, message: "This is an Xception"} else - return ::Thrift::Test::Xtruct.new({"string_thing" => arg1}) + ::Thrift::Test::Xtruct.new({"string_thing" => arg1}) end end diff --git a/tutorial/rb/RubyServer.rb b/tutorial/rb/RubyServer.rb index 7b64470a79..1cc47ff735 100755 --- a/tutorial/rb/RubyServer.rb +++ b/tutorial/rb/RubyServer.rb @@ -38,7 +38,7 @@ def ping() def add(n1, n2) print "add(", n1, ",", n2, ")\n" - return n1 + n2 + n1 + n2 end def calculate(logid, work) @@ -69,12 +69,12 @@ def calculate(logid, work) entry.value = val.to_s @log[logid] = entry - return val + val end def getStruct(key) print "getStruct(", key, ")\n" - return @log[key] + @log[key] end def zip()