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 an error for Style/YodaCondition #12009

Merged
merged 1 commit into from Jul 1, 2023

Conversation

koic
Copy link
Member

@koic koic commented Jun 30, 2023

This PR fixes an error for Style/YodaCondition when equality check method is used without the first argument:

foo.==
% rubocop /tmp/example.rb --only Style/YodaCondition -d
(snip)

For /tmp: An error occurred while Style/YodaCondition cop was inspecting /tmp/example.rb:1:0.
undefined method `literal?' for nil:NilClass
An error occurred while Style/YodaCondition cop was inspecting /tmp/example.rb:1:0.
undefined method `literal?' for nil
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.53.1/lib/
rubocop/cop/style/yoda_condition.rb:144:in `constant_portion?'
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.53.1/lib/
rubocop/cop/style/yoda_condition.rb:126:in `valid_yoda?'

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -324,6 +324,10 @@
expect_no_offenses('bar === "foo"')
end

it 'accepts equality check method is used without RHSl' do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RHSl? Perhaps argument is the better term here.

Copy link
Member Author

@koic koic Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I've updated this PR.

This PR fixes an error for `Style/YodaCondition` when
equality check method is used without the first argument:

```ruby
foo.==
```

```console
% rubocop /tmp/example.rb --only Style/YodaCondition -d
(snip)

For /tmp: An error occurred while Style/YodaCondition cop was inspecting /tmp/example.rb:1:0.
undefined method `literal?' for nil:NilClass
An error occurred while Style/YodaCondition cop was inspecting /tmp/example.rb:1:0.
undefined method `literal?' for nil
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.53.1/lib/
rubocop/cop/style/yoda_condition.rb:144:in `constant_portion?'
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.53.1/lib/
rubocop/cop/style/yoda_condition.rb:126:in `valid_yoda?'
```
@koic koic force-pushed the fix_an_error_for_style_yoda_condition branch from 585c6f4 to 757737b Compare July 1, 2023 05:48
@bbatsov bbatsov merged commit a60b19d into rubocop:master Jul 1, 2023
28 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 1, 2023

Thanks!

@koic koic deleted the fix_an_error_for_style_yoda_condition branch July 1, 2023 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants