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

ConstantName should allow CamelCase constants for class aliases #5053

Closed
marcandre opened this issue Nov 14, 2017 · 6 comments
Closed

ConstantName should allow CamelCase constants for class aliases #5053

marcandre opened this issue Nov 14, 2017 · 6 comments

Comments

@marcandre
Copy link
Contributor

The follow code is flagged by RuboCop:

class Foo
end
Bar = Foo

I believe it shouldn't complain about Bar being camelcase here. Assuming Foo is correctly written, then Bar should actually be CamelCase, and BAR = Foo should actually be an error.

I understand there is rarely a case for such code (but we have nevertheless 14 such cases 😈 )

$ rubocop -V
0.51.0 (using Parser 2.4.0.0, running on ruby 2.3.5 x86_64-darwin15)
@garettarrowood
Copy link
Contributor

garettarrowood commented Nov 14, 2017

This sounds like a fun fix. Happy to take a stab at it over the next few days.


Looks like there is already a note about this in the codebase - https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/naming/constant_name.rb#L27-L30

@garettarrowood
Copy link
Contributor

garettarrowood commented Nov 14, 2017

As that comment suggestions, it looks like the described behavior actually is not flagged by rubocop. I tried to reproduce without success. Adding this spec also passes:

  # spec/rubocop/cop/naming/constant_name_spec.rb
  it 'does not throw offense if rhs is camelCase' do
    expect_no_offenses(<<-RUBY.strip_indent)
      class FooBaz
      end
      BarBaz = FooBaz
    RUBY
  end

@marcandre - Can you provide any additional info about the error?

@marcandre
Copy link
Contributor Author

Indeed, Foo = Bar is ok, but Foo = Bar = Qux is flagged.

@marcandre
Copy link
Contributor Author

Thanks for the fix. On the other hand, this allows Foo = BAR and Bar = FOO, right?

@garettarrowood
Copy link
Contributor

From a quick test, it looks like those examples work just fine. No offenses on my end.

@marcandre
Copy link
Contributor Author

Yeah. Maybe it should be an offense though, at least Foo = BAR. Not sure if FOO = Bar is ok.

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

No branches or pull requests

3 participants