Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with range in RepeatedIncludeExample cop #1867

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix beginless and endless range bug for RepeatedIncludeExample cop. ([@hasghari])

## 2.29.1 (2024-04-05)

- Fix an error in the default configuration. ([@ydah])
Expand Down Expand Up @@ -895,6 +897,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@gsamokovarov]: https://github.com/gsamokovarov
[@harry-graham]: https://github.com/harry-graham
[@harrylewis]: https://github.com/harrylewis
[@hasghari]: https://github.com/hasghari
[@hosamaly]: https://github.com/hosamaly
[@ignaciovillaverde]: https://github.com/ignaciovillaverde
[@jaredbeck]: https://github.com/jaredbeck
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/rspec/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Node
def recursive_literal_or_const?
case type
when :begin, :pair, *AST::Node::COMPOSITE_LITERALS
children.all?(&:recursive_literal_or_const?)
children.compact.all?(&:recursive_literal_or_const?)
else
literal? || const_type?
end
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/rspec/repeated_include_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,23 @@
end
RUBY
end

it 'allows for beginless ranges' do
expect_no_offenses(<<~RUBY)
describe 'foo' do
include_examples 'irange', ..1
it_behaves_like 'irange', ..2
end
RUBY
end

it 'allows for endless ranges' do
expect_no_offenses(<<~RUBY)
describe 'foo' do
include_examples 'erange', (1..)
it_behaves_like 'erange', (2..)
end
RUBY
end
end
end