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

Naming/ConstantName flags conditional assignments of classes to camel-cased constants #6100

Closed
patbl opened this issue Jul 13, 2018 · 0 comments · Fixed by #6312
Closed

Naming/ConstantName flags conditional assignments of classes to camel-cased constants #6100

patbl opened this issue Jul 13, 2018 · 0 comments · Fixed by #6312
Labels

Comments

@patbl
Copy link

patbl commented Jul 13, 2018

Expected behavior

I expected this not to trigger the Naming/ConstantName cop:

class Foo; end
class Bar; end

Lol = if true then Foo else Bar end

The docs say

To avoid false positives, it ignores cases in which we cannot know for certain the type of value that would be assigned to a constant.

The changelog says

Fix false positive in Naming/ConstantName when using conditional assignment. (@Drenmi)

Actual behavior

That code triggered the Naming/ConstantName cop.

Steps to reproduce the problem

~  ➜ cat foo.rb
class Foo; end
class Bar; end

Lol = if true then Foo else Bar end
~  ➜ rubocop --only Naming/ConstantName foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:4:1: C: Naming/ConstantName: Use SCREAMING_SNAKE_CASE for constants.
Lol = if true then Foo else Bar end
^^^

1 file inspected, 1 offense detected

This isn't a problem without the conditional:

~  ➜ cat bar.rb
class Foo; end
Bar = Foo
~  ➜ rubocop --only Naming/ConstantName bar.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

RuboCop version

~  ➜ rubocop -V
0.58.1 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-darwin17)
@Drenmi Drenmi added the bug label Jul 14, 2018
@Drenmi Drenmi self-assigned this Jul 14, 2018
@Drenmi Drenmi removed their assignment Aug 20, 2018
tatsuyafw added a commit to tatsuyafw/rubocop that referenced this issue Jan 5, 2019
This cop would register an offense when rhs is a conditional expression
like the following code:

```
Lol = if true then Foo else Bar end
```

This change fixes that.
bbatsov pushed a commit that referenced this issue Jan 5, 2019
This cop would register an offense when rhs is a conditional expression
like the following code:

```
Lol = if true then Foo else Bar end
```

This change fixes that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants