Skip to content

Commit 9999f7e

Browse files
committed
Run rubocop -A for all touched files
1 parent 6459ea8 commit 9999f7e

File tree

5 files changed

+84
-138
lines changed

5 files changed

+84
-138
lines changed

.rubocop_todo.yml

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --exclude-limit 10000`
3-
# on 2025-03-04 09:53:10 UTC using RuboCop version 1.73.2.
3+
# on 2025-04-01 18:59:20 UTC using RuboCop version 1.75.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -44,29 +44,12 @@ Layout/ExtraSpacing:
4444
- 'spec/inertia/request_spec.rb'
4545
- 'spec/inertia/response_spec.rb'
4646

47-
# Offense count: 1
48-
# This cop supports safe autocorrection (--autocorrect).
49-
# Configuration parameters: EnforcedStyle, IndentationWidth.
50-
# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
51-
Layout/FirstArgumentIndentation:
52-
Exclude:
53-
- 'spec/inertia/ssr_spec.rb'
54-
5547
# Offense count: 2
5648
# This cop supports safe autocorrection (--autocorrect).
57-
# Configuration parameters: EnforcedStyle, IndentationWidth.
49+
# Configuration parameters: IndentationWidth.
5850
# SupportedStyles: special_inside_parentheses, consistent, align_braces
5951
Layout/FirstHashElementIndentation:
60-
Exclude:
61-
- 'spec/inertia/rspec_helper_spec.rb'
62-
63-
# Offense count: 4
64-
# This cop supports safe autocorrection (--autocorrect).
65-
# Configuration parameters: EnforcedStyle, IndentationWidth.
66-
# SupportedStyles: aligned, indented, indented_relative_to_receiver
67-
Layout/MultilineMethodCallIndentation:
68-
Exclude:
69-
- 'spec/inertia/ssr_spec.rb'
52+
EnforcedStyle: consistent
7053

7154
# Offense count: 6
7255
# This cop supports safe autocorrection (--autocorrect).
@@ -99,24 +82,20 @@ Layout/SpaceInsideBlockBraces:
9982
- 'spec/inertia/error_sharing_spec.rb'
10083
- 'spec/inertia/request_spec.rb'
10184

102-
# Offense count: 106
85+
# Offense count: 56
10386
# This cop supports safe autocorrection (--autocorrect).
10487
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
10588
# SupportedStyles: space, no_space, compact
10689
# SupportedStylesForEmptyBraces: space, no_space
10790
Layout/SpaceInsideHashLiteralBraces:
10891
Exclude:
10992
- 'lib/inertia_rails/controller.rb'
110-
- 'lib/inertia_rails/middleware.rb'
11193
- 'spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb'
11294
- 'spec/dummy/app/controllers/inertia_share_test_controller.rb'
11395
- 'spec/inertia/conditional_sharing_spec.rb'
114-
- 'spec/inertia/middleware_spec.rb'
11596
- 'spec/inertia/rails_mimic_spec.rb'
11697
- 'spec/inertia/request_spec.rb'
11798
- 'spec/inertia/rspec_helper_spec.rb'
118-
- 'spec/inertia/sharing_spec.rb'
119-
- 'spec/inertia/ssr_spec.rb'
12099

121100
# Offense count: 2
122101
# This cop supports safe autocorrection (--autocorrect).
@@ -164,14 +143,6 @@ Lint/SymbolConversion:
164143
Exclude:
165144
- 'spec/inertia/rails_mimic_spec.rb'
166145

167-
# Offense count: 1
168-
# This cop supports safe autocorrection (--autocorrect).
169-
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
170-
# NotImplementedExceptions: NotImplementedError
171-
Lint/UnusedMethodArgument:
172-
Exclude:
173-
- 'lib/patches/mapper.rb'
174-
175146
# Offense count: 1
176147
Naming/AccessorMethodName:
177148
Exclude:
@@ -190,12 +161,12 @@ Naming/FileName:
190161
# Offense count: 2
191162
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
192163
# SupportedStyles: snake_case, normalcase, non_integer
193-
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
164+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
194165
Naming/VariableNumber:
195166
Exclude:
196167
- 'spec/dummy/app/controllers/inertia_test_controller.rb'
197168

198-
# Offense count: 10
169+
# Offense count: 7
199170
# This cop supports safe autocorrection (--autocorrect).
200171
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
201172
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
@@ -210,12 +181,13 @@ Style/BlockDelimiters:
210181
- 'spec/inertia/rails_mimic_spec.rb'
211182
- 'spec/inertia/request_spec.rb'
212183
- 'spec/inertia/rspec_helper_spec.rb'
213-
- 'spec/inertia/sharing_spec.rb'
214184

215185
# Offense count: 1
216186
# This cop supports unsafe autocorrection (--autocorrect-all).
217-
# Configuration parameters: EnforcedStyle.
187+
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
218188
# SupportedStyles: nested, compact
189+
# SupportedStylesForClasses: , nested, compact
190+
# SupportedStylesForModules: , nested, compact
219191
Style/ClassAndModuleChildren:
220192
Exclude:
221193
- 'lib/inertia_rails/helper.rb'
@@ -255,7 +227,7 @@ Style/ExpandPathArguments:
255227
Exclude:
256228
- 'spec/rails_helper.rb'
257229

258-
# Offense count: 69
230+
# Offense count: 65
259231
# This cop supports unsafe autocorrection (--autocorrect-all).
260232
# Configuration parameters: EnforcedStyle.
261233
# SupportedStyles: always, always_true, never
@@ -321,15 +293,11 @@ Style/FrozenStringLiteralComment:
321293
- 'spec/inertia/conditional_sharing_spec.rb'
322294
- 'spec/inertia/error_sharing_spec.rb'
323295
- 'spec/inertia/lazy_prop_spec.rb'
324-
- 'spec/inertia/middleware_spec.rb'
325296
- 'spec/inertia/rails_mimic_spec.rb'
326297
- 'spec/inertia/request_spec.rb'
327298
- 'spec/inertia/response_spec.rb'
328299
- 'spec/inertia/rspec_helper_spec.rb'
329-
- 'spec/inertia/sharing_spec.rb'
330-
- 'spec/inertia/ssr_spec.rb'
331300
- 'spec/rails_helper.rb'
332-
- 'spec/spec_helper.rb'
333301
- 'spec/support/shared_examples.rb'
334302

335303
# Offense count: 1
@@ -399,11 +367,6 @@ Style/NestedModifier:
399367
Exclude:
400368
- 'lib/inertia_rails/controller.rb'
401369

402-
# Offense count: 1
403-
Style/OpenStructUse:
404-
Exclude:
405-
- 'spec/inertia/ssr_spec.rb'
406-
407370
# Offense count: 2
408371
# This cop supports safe autocorrection (--autocorrect).
409372
Style/RedundantBegin:
@@ -456,7 +419,6 @@ Style/StringLiterals:
456419
- 'lib/inertia_rails/controller.rb'
457420
- 'lib/inertia_rails/engine.rb'
458421
- 'lib/inertia_rails/helper.rb'
459-
- 'lib/inertia_rails/middleware.rb'
460422
- 'lib/inertia_rails/rspec.rb'
461423
- 'lib/inertia_rails/version.rb'
462424
- 'lib/patches/better_errors.rb'
@@ -476,7 +438,6 @@ Style/StringLiterals:
476438
- 'spec/inertia/response_spec.rb'
477439
- 'spec/inertia/rspec_helper_spec.rb'
478440
- 'spec/rails_helper.rb'
479-
- 'spec/spec_helper.rb'
480441

481442
# Offense count: 2
482443
# This cop supports safe autocorrection (--autocorrect).
@@ -511,15 +472,7 @@ Style/TrailingCommaInHashLiteral:
511472
- 'spec/inertia/response_spec.rb'
512473
- 'spec/inertia/rspec_helper_spec.rb'
513474

514-
# Offense count: 1
515-
# This cop supports safe autocorrection (--autocorrect).
516-
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
517-
# SupportedStyles: percent, brackets
518-
Style/WordArray:
519-
Exclude:
520-
- 'lib/inertia_rails/middleware.rb'
521-
522-
# Offense count: 17
475+
# Offense count: 24
523476
# This cop supports safe autocorrection (--autocorrect).
524477
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
525478
# URISchemes: http, https

lib/inertia_rails/renderer.rb

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
module InertiaRails
88
class Renderer
9-
KEEP_PROP = :keep
10-
DONT_KEEP_PROP = :dont_keep
11-
129
attr_reader(
1310
:component,
1411
:configuration,
@@ -82,31 +79,17 @@ def shared_data
8279
#
8380
# Functionally, this permits using either string or symbol keys in the controller. Since the results
8481
# is cast to json, we should treat string/symbol keys as identical.
85-
def merge_props(shared_data, props)
82+
def merge_props(shared_props, props)
8683
if @deep_merge
87-
shared_data.deep_symbolize_keys.deep_merge!(props.deep_symbolize_keys)
84+
shared_props.deep_symbolize_keys.deep_merge!(props.deep_symbolize_keys)
8885
else
89-
shared_data.symbolize_keys.merge(props.symbolize_keys)
86+
shared_props.symbolize_keys.merge(props.symbolize_keys)
9087
end
9188
end
9289

9390
def computed_props
9491
merged_props = merge_props(shared_data, props)
95-
96-
deep_transform_props merged_props do |prop, path|
97-
next [DONT_KEEP_PROP] unless keep_prop?(prop, path)
98-
99-
transformed_prop = case prop
100-
when BaseProp
101-
prop.call(controller)
102-
when Proc
103-
controller.instance_exec(&prop)
104-
else
105-
prop
106-
end
107-
108-
[KEEP_PROP, transformed_prop]
109-
end
92+
deep_transform_props(merged_props)
11093
end
11194

11295
def page
@@ -128,16 +111,23 @@ def page
128111
default_page
129112
end
130113

131-
def deep_transform_props(props, parent_path = [], &block)
114+
def deep_transform_props(props, parent_path = [])
132115
props.each_with_object({}) do |(key, prop), transformed_props|
133116
current_path = parent_path + [key]
134117

135118
if prop.is_a?(Hash) && prop.any?
136-
nested = deep_transform_props(prop, current_path, &block)
137-
transformed_props.merge!(key => nested) unless nested.empty?
138-
else
139-
action, transformed_prop = block.call(prop, current_path)
140-
transformed_props.merge!(key => transformed_prop) if action == KEEP_PROP
119+
nested = deep_transform_props(prop, current_path)
120+
transformed_props[key] = nested unless nested.empty?
121+
elsif keep_prop?(prop, current_path)
122+
transformed_props[key] =
123+
case prop
124+
when BaseProp
125+
prop.call(controller)
126+
when Proc
127+
controller.instance_exec(&prop)
128+
else
129+
prop
130+
end
141131
end
142132
end
143133
end

spec/inertia/sharing_spec.rb

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1+
# frozen_string_literal: true
2+
13
RSpec.describe 'using inertia share when rendering views', type: :request do
24
subject { JSON.parse(response.body)['props'].deep_symbolize_keys }
35

46
context 'using inertia share' do
5-
let(:props) { {name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works'} }
6-
before { get share_path, headers: {'X-Inertia' => true} }
7+
let(:props) { { name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works' } }
8+
before { get share_path, headers: { 'X-Inertia' => true } }
79

810
it { is_expected.to eq props }
911
end
1012

1113
context 'inertia share across requests' do
1214
before do
13-
get share_path, headers: {'X-Inertia' => true}
14-
get empty_test_path, headers: {'X-Inertia' => true}
15+
get share_path, headers: { 'X-Inertia' => true }
16+
get empty_test_path, headers: { 'X-Inertia' => true }
1517
end
1618

1719
it { is_expected.to eq({}) }
1820
end
1921

2022
context 'using inertia share in subsequent requests' do
21-
let(:props) { {name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works'} }
23+
let(:props) { { name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works' } }
2224

2325
before do
24-
get share_path, headers: {'X-Inertia' => true}
25-
get share_path, headers: {'X-Inertia' => true}
26+
get share_path, headers: { 'X-Inertia' => true }
27+
get share_path, headers: { 'X-Inertia' => true }
2628
end
2729

2830
it { is_expected.to eq props }
2931
end
3032

3133
context 'using inertia share with inheritance' do
32-
let(:props) { {name: 'No Longer Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works'} }
34+
let(:props) { { name: 'No Longer Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works' } }
3335

3436
before do
35-
get share_with_inherited_path, headers: {'X-Inertia' => true}
37+
get share_with_inherited_path, headers: { 'X-Inertia' => true }
3638
end
3739

3840
it { is_expected.to eq props }
3941
end
4042

4143
context 'with errors' do
42-
let(:props) { {name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works'} }
44+
let(:props) { { name: 'Brandon', sport: 'hockey', position: 'center', number: 29, a_hash: 'also works' } }
4345
let(:errors) { 'rearview mirror is present' }
44-
before {
46+
before do
4547
allow_any_instance_of(ActionDispatch::Request).to receive(:session) {
4648
spy(ActionDispatch::Request::Session).tap do |spy|
4749
allow(spy).to receive(:[])
4850
allow(spy).to receive(:[]).with(:inertia_errors).and_return(errors)
4951
end
5052
}
51-
get share_path, headers: {'X-Inertia' => true}
52-
}
53+
get share_path, headers: { 'X-Inertia' => true }
54+
end
5355

5456
it { is_expected.to eq props.merge({ errors: errors }) }
5557
end
@@ -58,13 +60,13 @@
5860
context 'with default settings (shallow merge)' do
5961
describe 'shallow merging by default' do
6062
let(:props) { { nested: { assists: 200 } } }
61-
before { get merge_shared_path, headers: {'X-Inertia' => true} }
63+
before { get merge_shared_path, headers: { 'X-Inertia' => true } }
6264
it { is_expected.to eq props }
6365
end
6466

6567
context 'with deep merge added to the renderer' do
6668
let(:props) { { nested: { goals: 100, assists: 300 } } }
67-
before { get deep_merge_shared_path, headers: {'X-Inertia' => true} }
69+
before { get deep_merge_shared_path, headers: { 'X-Inertia' => true } }
6870
it { is_expected.to eq props }
6971
end
7072
end
@@ -74,20 +76,20 @@
7476

7577
describe 'deep merging by default' do
7678
let(:props) { { nested: { goals: 100, assists: 200 } } }
77-
before { get merge_shared_path, headers: {'X-Inertia' => true} }
79+
before { get merge_shared_path, headers: { 'X-Inertia' => true } }
7880
it { is_expected.to eq props }
7981
end
8082

8183
describe 'overriding deep merge in a specific action' do
8284
let(:props) { { nested: { assists: 200 } } }
83-
before { get shallow_merge_shared_path, headers: {'X-Inertia' => true} }
85+
before { get shallow_merge_shared_path, headers: { 'X-Inertia' => true } }
8486
it { is_expected.to eq props }
8587
end
8688
end
8789

8890
context 'merging with instance props' do
8991
let(:props) { { nested: { points: 100, rebounds: 10 } } }
90-
before { get merge_instance_props_path, headers: {'X-Inertia' => true} }
92+
before { get merge_instance_props_path, headers: { 'X-Inertia' => true } }
9193
it { is_expected.to eq props }
9294
end
9395
end

0 commit comments

Comments
 (0)