Skip to content

Commit

Permalink
Fix shadowing outer local variable and other warnings (#1274)
Browse files Browse the repository at this point in the history
* Fix shadowing outer local variable warnings

* Fix other warnings

* Add CHANGELOG entry

* Lint

* Add config for new Layout/SpaceBeforeBrackets cop
  • Loading branch information
Spone authored Feb 14, 2022
1 parent ccede32 commit 18c27ad
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ Layout/DotPosition:
Layout/LineLength:
Max: 120
Enabled: true

Layout/SpaceBeforeBrackets:
Enabled: true
4 changes: 2 additions & 2 deletions app/helpers/preview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def find_template_data(lookup_context:, template_identifier:)
end.flatten

# Search for templates the contain `html`.
matching_templates = all_template_paths.find_all do |template|
template =~ /#{template_identifier}*.(html)/
matching_templates = all_template_paths.find_all do |path|
path =~ /#{template_identifier}*.(html)/
end

# In-case of a conflict due to multiple template files with
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ title: Changelog

## main

* Fix Ruby warnings.

*Hans Lemuet*

* Place all generator options under `config.generate` namespace.

*Simon Fish*
Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def layout(layout_name)
# Returns the relative path (from preview_path) to the preview example template if the template exists
def preview_example_template_path(example)
preview_path =
Array(preview_paths).detect do |preview_path|
Dir["#{preview_path}/#{preview_name}_preview/#{example}.html.*"].first
Array(preview_paths).detect do |path|
Dir["#{path}/#{preview_name}_preview/#{example}.html.*"].first
end

if preview_path.nil?
Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/slotable_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def set_slot(slot_name, slot_definition = nil, *args, &block)
renderable_function = slot_definition[:renderable_function].bind(self)
renderable_value =
if block_given?
renderable_function.call(*args) do |*args|
view_context.capture(*args, &block)
renderable_function.call(*args) do |*rargs|
view_context.capture(*rargs, &block)
end
else
renderable_function.call(*args)
Expand Down
4 changes: 2 additions & 2 deletions test/view_component/slotable_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ def test_component_delegation_slots_work_with_helpers
PartialHelper::State.reset

assert_nothing_raised do
render_inline WrapperComponent.new do |c|
c.render(PartialSlotHelperComponent.new) do |c|
render_inline WrapperComponent.new do |w|
w.render(PartialSlotHelperComponent.new) do |c|
c.header {}
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/view_component/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TasksTest < ActiveSupport::TestCase

test "adds components to rails stats" do
Dir.chdir(Rails.root) do
assert_output /ViewComponents/ do
assert_output(/ViewComponents/) do
Rake::Task["stats"].invoke
end
end
Expand Down

0 comments on commit 18c27ad

Please sign in to comment.