Skip to content

Commit

Permalink
Fix a false positive for Style/RequireOrder
Browse files Browse the repository at this point in the history
This PR fixes a false positive for `Style/RequireOrder`
when single-quoted string and double-quoted string are mixed.
  • Loading branch information
koic committed May 30, 2023
1 parent 7259df9 commit db9e469
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_style_require_order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11902](https://github.com/rubocop/rubocop/pull/11902): Fix a false positive for `Style/RequireOrder` when single-quoted string and double-quoted string are mixed. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/require_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ def find_previous_older_sibling(node) # rubocop:disable Metrics
break unless sibling&.send_type? && sibling&.method?(node.method_name)
break unless sibling.arguments? && !sibling.receiver
break unless in_same_section?(sibling, node)
break unless node.first_argument.str_type? && sibling.first_argument.str_type?

node.first_argument.source < sibling.first_argument.source
node.first_argument.value < sibling.first_argument.value
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/style/require_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
require 'b'
RUBY
end

it 'registers no offense when single-quoted string and double-quoted string are mixed' do
expect_no_offenses(<<~RUBY)
require 'a'
require "b"
RUBY
end
end

context 'when only one `require`' do
Expand Down

0 comments on commit db9e469

Please sign in to comment.