Skip to content

Commit 40d8193

Browse files
committed
rubocop linting
1 parent 1e4da8c commit 40d8193

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/react_on_rails/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def internal_rsc_react_component(react_component_name, options = {})
436436
render_options = create_render_options(react_component_name, options)
437437
json_stream = server_rendered_react_component(render_options)
438438
json_stream.transform do |chunk|
439-
(chunk.to_json + "\n").html_safe
439+
"#{chunk.to_json}\n".html_safe
440440
end
441441
end
442442

lib/react_on_rails/packs_generator.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def create_pack(file_path)
4444
puts(Rainbow("Generated Packs: #{output_path}").yellow)
4545
end
4646

47+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
4748
def first_js_statement_in_code(content)
49+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
4850
return "" if content.nil? || content.empty?
4951

5052
start_index = 0
@@ -81,17 +83,18 @@ def first_js_statement_in_code(content)
8183
""
8284
end
8385

84-
def is_client_entrypoint?(file_path)
86+
def client_entrypoint?(file_path)
8587
content = File.read(file_path)
8688
# has "use client" directive. It can be "use client" or 'use client'
8789
first_js_statement_in_code(content).match?(/^["']use client["'](?:;|\s|$)/)
8890
end
8991

9092
def pack_file_contents(file_path)
9193
registered_component_name = component_name(file_path)
92-
load_server_components = ReactOnRails::Utils.react_on_rails_pro? && ReactOnRailsPro.configuration.enable_rsc_support
94+
load_server_components = ReactOnRails::Utils.react_on_rails_pro? &&
95+
ReactOnRailsPro.configuration.enable_rsc_support
9396

94-
if load_server_components && !is_client_entrypoint?(file_path)
97+
if load_server_components && !client_entrypoint?(file_path)
9598
import_statement = ""
9699
rsc_rendering_url_path = ReactOnRailsPro.configuration.rsc_rendering_url_path
97100
register_call = <<~REGISTER_CALL.strip

spec/dummy/spec/packs_generator_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module ReactOnRails
8282
it "generated pack for ComponentWithCommonOnly uses common file for pack" do
8383
pack_content = File.read(component_pack)
8484

85-
expect(pack_content).to include("#{component_namspec / dummy / spec / packs_generator_spec.rbe}.jsx")
85+
expect(pack_content).to include("#{component_name / dummy / spec / packs_generator_spec.rbe}.jsx")
8686
expect(pack_content).not_to include("#{component_name}.client.jsx")
8787
expect(pack_content).not_to include("#{component_name}.server.jsx")
8888
end
@@ -434,7 +434,7 @@ def stub_packer_source_path(packer_source_path:, component_name:)
434434
end
435435

436436
context "with string directive" do
437-
context "on top of the file" do
437+
context "when on top of the file" do
438438
let(:content) do
439439
<<~JS
440440
"use client";
@@ -446,13 +446,13 @@ def stub_packer_source_path(packer_source_path:, component_name:)
446446
it { is_expected.to eq '"use client";' }
447447
end
448448

449-
context "on top of the file and one line comment" do
449+
context "when on top of the file and one line comment" do
450450
let(:content) { '"use client"; // const x = 1' }
451451

452452
it { is_expected.to eq '"use client"; // const x = 1' }
453453
end
454454

455-
context "after some one-line comments" do
455+
context "when after some one-line comments" do
456456
let(:content) do
457457
<<~JS
458458
// First comment
@@ -464,7 +464,7 @@ def stub_packer_source_path(packer_source_path:, component_name:)
464464
it { is_expected.to eq '"use client";' }
465465
end
466466

467-
context "after some multi-line comments" do
467+
context "when after some multi-line comments" do
468468
let(:content) do
469469
<<~JS
470470
/* First comment */
@@ -478,7 +478,7 @@ def stub_packer_source_path(packer_source_path:, component_name:)
478478
it { is_expected.to eq '"use client";' }
479479
end
480480

481-
context "after some mixed comments" do
481+
context "when after some mixed comments" do
482482
let(:content) do
483483
<<~JS
484484
// First comment
@@ -492,7 +492,7 @@ def stub_packer_source_path(packer_source_path:, component_name:)
492492
it { is_expected.to eq '"use client";' }
493493
end
494494

495-
context "after any non-comment code" do
495+
context "when after any non-comment code" do
496496
let(:content) do
497497
<<~JS
498498
// First comment
@@ -506,8 +506,8 @@ def stub_packer_source_path(packer_source_path:, component_name:)
506506
end
507507
end
508508

509-
describe "#is_client_entrypoint?" do
510-
subject { described_class.instance.send(:is_client_entrypoint?, "dummy_path.js") }
509+
describe "#client_entrypoint?" do
510+
subject { described_class.instance.send(:client_entrypoint?, "dummy_path.js") }
511511

512512
before do
513513
allow(File).to receive(:read).with("dummy_path.js").and_return(content)

0 commit comments

Comments
 (0)