Skip to content

Commit 35eeed5

Browse files
kpumukcodex
andcommitted
Enforce Ruby whitespace layout rules
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
1 parent ac8390f commit 35eeed5

25 files changed

Lines changed: 120 additions & 42 deletions

compiler/cpp/src/thrift/generate/t_rb_generator.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void t_rb_generator::generate_rb_struct(t_rb_ofstream& out,
606606
out << '\n';
607607

608608
out.indent_up();
609-
out.indent() << "include ::Thrift::Struct, ::Thrift::Struct_Union" << '\n';
609+
out.indent() << "include ::Thrift::Struct, ::Thrift::Struct_Union" << '\n' << '\n';
610610

611611
if (is_exception) {
612612
generate_rb_simple_exception_constructor(out, tstruct);
@@ -635,7 +635,7 @@ void t_rb_generator::generate_rb_union(t_rb_ofstream& out,
635635
out.indent() << "class " << type_name(tstruct) << " < ::Thrift::Union" << '\n';
636636

637637
out.indent_up();
638-
out.indent() << "include ::Thrift::Struct_Union" << '\n';
638+
out.indent() << "include ::Thrift::Struct_Union" << '\n' << '\n';
639639

640640
generate_field_constructors(out, tstruct);
641641

@@ -708,7 +708,9 @@ void t_rb_generator::generate_field_constants(t_rb_ofstream& out, t_struct* tstr
708708

709709
out.indent() << field_id_constant_name(field_name) << " = " << (*f_iter)->get_key() << '\n';
710710
}
711-
out << '\n';
711+
if (!fields.empty()) {
712+
out << '\n';
713+
}
712714
}
713715

714716
void t_rb_generator::generate_field_defns(t_rb_ofstream& out, t_struct* tstruct) {
@@ -975,11 +977,14 @@ void t_rb_generator::generate_service_client(t_service* tservice) {
975977
f_service_.indent() << "class Client" << extends_client << '\n';
976978
f_service_.indent_up();
977979

978-
f_service_.indent() << "include ::Thrift::Client" << '\n' << '\n';
979-
980980
// Generate client method implementations
981981
vector<t_function*> functions = tservice->get_functions();
982982
vector<t_function*>::const_iterator f_iter;
983+
f_service_.indent() << "include ::Thrift::Client" << '\n';
984+
if (!functions.empty()) {
985+
f_service_ << '\n';
986+
}
987+
983988
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
984989
t_struct* arg_struct = (*f_iter)->get_arglist();
985990
const vector<t_field*>& fields = arg_struct->get_members();
@@ -1080,7 +1085,11 @@ void t_rb_generator::generate_service_client(t_service* tservice) {
10801085

10811086
// Close function
10821087
f_service_.indent_down();
1083-
f_service_.indent() << "end" << '\n' << '\n';
1088+
f_service_.indent() << "end" << '\n';
1089+
}
1090+
1091+
if (f_iter + 1 != functions.end()) {
1092+
f_service_ << '\n';
10841093
}
10851094
}
10861095

@@ -1110,11 +1119,17 @@ void t_rb_generator::generate_service_server(t_service* tservice) {
11101119
f_service_.indent() << "class Processor" << extends_processor << '\n';
11111120
f_service_.indent_up();
11121121

1113-
f_service_.indent() << "include ::Thrift::Processor" << '\n' << '\n';
1122+
f_service_.indent() << "include ::Thrift::Processor" << '\n';
1123+
if (!functions.empty()) {
1124+
f_service_ << '\n';
1125+
}
11141126

11151127
// Generate the process subfunctions
11161128
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
11171129
generate_process_function(tservice, *f_iter);
1130+
if (f_iter + 1 != functions.end()) {
1131+
f_service_ << '\n';
1132+
}
11181133
}
11191134

11201135
f_service_.indent_down();
@@ -1193,7 +1208,7 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
11931208
if (tfunction->is_oneway()) {
11941209
f_service_.indent() << "return" << '\n';
11951210
f_service_.indent_down();
1196-
f_service_.indent() << "end" << '\n' << '\n';
1211+
f_service_.indent() << "end" << '\n';
11971212
return;
11981213
}
11991214

@@ -1202,7 +1217,7 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
12021217

12031218
// Close function
12041219
f_service_.indent_down();
1205-
f_service_.indent() << "end" << '\n' << '\n';
1220+
f_service_.indent() << "end" << '\n';
12061221
}
12071222

12081223
/**

compiler/cpp/tests/rb/t_rb_generator_functional_tests.cc

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ TEST_CASE("t_rb_generator uses suffixed field id constants to avoid FIELDS colli
9999
std::remove(thrift_path.c_str());
100100
}
101101

102-
TEST_CASE("t_rb_generator emits service arguments as a positional hash", "[functional]")
102+
TEST_CASE("t_rb_generator formats service classes and positional arguments", "[functional]")
103103
{
104104
const string thrift_path = "test_service_arguments.thrift";
105105
const string thrift_source =
106+
"service EmptyService {\n"
107+
"}\n"
106108
"service PingService {\n"
107109
" oneway void ping(1: i32 n)\n"
108110
"}\n";
@@ -123,7 +125,18 @@ TEST_CASE("t_rb_generator emits service arguments as a positional hash", "[funct
123125
REQUIRE_NOTHROW(gen->generate_program());
124126

125127
const string service = read_file("gen-rb/ping_service.rb");
128+
const string expected_empty_result =
129+
" class Ping_result\n"
130+
" include ::Thrift::Struct, ::Thrift::Struct_Union\n"
131+
"\n"
132+
" FIELDS";
126133
REQUIRE(service.find("send_oneway_message(\"ping\", Ping_args, {n: n})") != string::npos);
134+
REQUIRE(service.find(expected_empty_result) != string::npos);
135+
REQUIRE(service.find("\n\n end\n") == string::npos);
136+
137+
const string empty_service = read_file("gen-rb/empty_service.rb");
138+
REQUIRE(!empty_service.empty());
139+
REQUIRE(empty_service.find("\n\n end\n") == string::npos);
127140

128141
std::remove(thrift_path.c_str());
129142
}
@@ -135,6 +148,9 @@ TEST_CASE("t_rb_generator formats multiline Ruby literals, calls, and field meta
135148
"struct Item {\n"
136149
" 1: string value\n"
137150
"}\n"
151+
"union Choice {\n"
152+
" 1: string value\n"
153+
"}\n"
138154
"const Item ITEM = {\"value\": \"one\"}\n"
139155
"const set<i32> IDS = [1, 2]\n"
140156
"struct Defaults {\n"
@@ -157,14 +173,39 @@ TEST_CASE("t_rb_generator formats multiline Ruby literals, calls, and field meta
157173
REQUIRE_NOTHROW(gen->generate_program());
158174

159175
const string constants = read_file("gen-rb/test_multiline_layout_constants.rb");
160-
REQUIRE(constants.find("ITEM = ::Item.new({\n %q\"value\" => %q\"one\",\n})")
161-
!= string::npos);
162-
REQUIRE(constants.find("IDS = Set.new([\n 1,\n 2,\n])") != string::npos);
176+
const string expected_item_constant =
177+
"ITEM = ::Item.new({\n"
178+
" %q\"value\" => %q\"one\",\n"
179+
"})";
180+
const string expected_set_constant =
181+
"IDS = Set.new([\n"
182+
" 1,\n"
183+
" 2,\n"
184+
"])";
185+
REQUIRE(constants.find(expected_item_constant) != string::npos);
186+
REQUIRE(constants.find(expected_set_constant) != string::npos);
163187

164188
const string types = read_file("gen-rb/test_multiline_layout_types.rb");
165-
REQUIRE(types.find("VALUES_FIELD_ID => {\n type: ::Thrift::Types::LIST,\n")
166-
!= string::npos);
167-
REQUIRE(types.find("default: [\n 1,\n 2,\n ],\n") != string::npos);
189+
const string expected_struct =
190+
"class Item\n"
191+
" include ::Thrift::Struct, ::Thrift::Struct_Union\n"
192+
"\n";
193+
const string expected_union =
194+
"class Choice < ::Thrift::Union\n"
195+
" include ::Thrift::Struct_Union\n"
196+
"\n";
197+
const string expected_field_metadata =
198+
" VALUES_FIELD_ID => {\n"
199+
" type: ::Thrift::Types::LIST,\n";
200+
const string expected_default =
201+
" default: [\n"
202+
" 1,\n"
203+
" 2,\n"
204+
" ],\n";
205+
REQUIRE(types.find(expected_struct) != string::npos);
206+
REQUIRE(types.find(expected_union) != string::npos);
207+
REQUIRE(types.find(expected_field_metadata) != string::npos);
208+
REQUIRE(types.find(expected_default) != string::npos);
168209

169210
std::remove(thrift_path.c_str());
170211
}

lib/rb/.rubocop.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Layout/ArgumentAlignment:
1515
Layout/ArrayAlignment:
1616
Enabled: true
1717

18+
Layout/BeginEndAlignment:
19+
Enabled: true
20+
EnforcedStyleAlignWith: start_of_line
21+
1822
Layout/BlockAlignment:
1923
Enabled: true
2024
EnforcedStyleAlignWith: start_of_block
@@ -29,12 +33,42 @@ Layout/ClosingParenthesisIndentation:
2933
Layout/CommentIndentation:
3034
Enabled: true
3135

36+
Layout/EmptyLineBetweenDefs:
37+
Enabled: true
38+
3239
Layout/EmptyLines:
3340
Enabled: true
3441

42+
Layout/EmptyLinesAfterModuleInclusion:
43+
Enabled: true
44+
45+
Layout/EmptyLinesAroundAccessModifier:
46+
Enabled: true
47+
48+
Layout/EmptyLinesAroundArguments:
49+
Enabled: true
50+
51+
Layout/EmptyLinesAroundAttributeAccessor:
52+
Enabled: true
53+
54+
Layout/EmptyLinesAroundBeginBody:
55+
Enabled: true
56+
3557
Layout/EmptyLinesAroundBlockBody:
3658
Enabled: true
3759

60+
Layout/EmptyLinesAroundClassBody:
61+
Enabled: true
62+
63+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
64+
Enabled: true
65+
66+
Layout/EmptyLinesAroundMethodBody:
67+
Enabled: true
68+
69+
Layout/EmptyLinesAroundModuleBody:
70+
Enabled: true
71+
3872
Layout/ElseAlignment:
3973
Enabled: true
4074

@@ -97,6 +131,9 @@ Layout/MultilineMethodCallBraceLayout:
97131
Enabled: true
98132
EnforcedStyle: symmetrical
99133

134+
Layout/RescueEnsureAlignment:
135+
Enabled: true
136+
100137
Layout/SpaceAfterComma:
101138
Enabled: true
102139

@@ -106,6 +143,9 @@ Layout/SpaceAroundKeyword:
106143
Layout/SpaceAroundEqualsInParameterDefault:
107144
Enabled: true
108145

146+
Layout/SpaceBeforeBlockBraces:
147+
Enabled: true
148+
109149
Layout/SpaceBeforeComma:
110150
Enabled: true
111151

lib/rb/ext/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020

2121
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
22-
File.open("Makefile", "w"){ |f| f.puts "all:\n\ninstall:\n" }
22+
File.open("Makefile", "w") { |f| f.puts "all:\n\ninstall:\n" }
2323
else
2424
require "mkmf"
2525

lib/rb/lib/thrift/exceptions.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def initialize(message)
3131
end
3232

3333
class ApplicationException < Exception
34-
3534
UNKNOWN = 0
3635
UNKNOWN_METHOD = 1
3736
INVALID_MESSAGE_TYPE = 2
@@ -87,6 +86,5 @@ def write(oprot, remaining_depth = DEFAULT_RECURSION_DEPTH)
8786
oprot.write_field_stop
8887
oprot.write_struct_end
8988
end
90-
9189
end
9290
end

lib/rb/lib/thrift/multiplexed_processor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def check_default_processor(name)
7171
end
7272

7373
class StoredMessageProtocol < BaseProtocol
74-
7574
include ProtocolDecorator
7675

7776
def initialize(protocol, message_begin)

lib/rb/lib/thrift/protocol/base_protocol.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
module Thrift
2626
class ProtocolException < Exception
27-
2827
UNKNOWN = 0
2928
INVALID_DATA = 1
3029
NEGATIVE_SIZE = 2
@@ -42,7 +41,6 @@ def initialize(type = UNKNOWN, message = nil)
4241
end
4342

4443
class BaseProtocol
45-
4644
MAX_CONTAINER_SIZE = (1 << 31) - 1
4745

4846
attr_reader :trans

lib/rb/lib/thrift/protocol/compact_protocol.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
module Thrift
2222
class CompactProtocol < BaseProtocol
23-
2423
PROTOCOL_ID = [0x82].pack("c").unpack("c").first
2524
VERSION = 1
2625
VERSION_MASK = 0x1f

lib/rb/lib/thrift/protocol/json_protocol.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def escapeNum
111111

112112
# Context class for lists
113113
class JSONListContext < JSONContext
114-
115114
def initialize
116115
@first = true
117116
end
@@ -134,7 +133,6 @@ def read(reader)
134133
end
135134

136135
class JsonProtocol < BaseProtocol
137-
138136
@@kJSONObjectStart = "{"
139137
@@kJSONObjectEnd = "}"
140138
@@kJSONArrayStart = "["

lib/rb/lib/thrift/protocol/multiplexed_protocol.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
module Thrift
2323
class MultiplexedProtocol < BaseProtocol
24-
2524
include ProtocolDecorator
2625

2726
def initialize(protocol, service_name)

0 commit comments

Comments
 (0)