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
Layout/ClassStructure and private constants #8366
Comments
@marcandre Note on this issue. Ruby also has class Hello
BAR = 10
private_constant :BAR
private
FOO = 10
public_constant :FOO
end In this case, I think the behavior would be:
Similarly, methods have the same methods, including: class A
class << self
def a_public_class_method; end
private
def a_private_class_method; end
end
public_class_method :a_private_class_method
private_class_method :a_public_class_method
def a_public_method; end
private :a_public_method
def another_public_method; end
private
def a_private_method; end
public :a_private_method
end
A.a_private_class_method
A.new.a_private_method
A.new.another_public_method
A.a_public_class_method # Raise exception
A.new.a_public_method # Raise exception Should we tackle them too? I would love to work on this. |
Sorry I didn't reply earlier, @nguyenquangminh0711
If you want to work on this, I would recommend to first address this current issue, where |
@marcandre - Is this still an issue? I tried to recreate this, but there were no offense generated for the stated code. |
Definitely an issue. I have a big PR that I need to complete, which addresses this: #9575 |
@marcandre Just for my clarity. So this is what i am doing and I am unable to recreate the issue :
class Foo
def foo
end
BAR = 42
private_constant :BAR
def bar
# use BAR
end
end Rubocop output: layout_class_structure.rb:1:1: C: Style/Documentation: Missing top-level class documentation comment.
class Foo
^^^^^
layout_class_structure.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
layout_class_structure.rb:2:3: C: [Correctable] Style/EmptyMethod: Put empty method definitions on a single line.
def foo ...
^^^^^^^ System info: ❯ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19] /0.0s
❯ rubocop -v
1.17.0 |
@thearjunmdas Thanks for checking. I'm not sure what the default is anymore (and too 😴 to check). Probably my example should be updated, but I still believe |
@marcandre - Thanks for the response. I guess your PR should do, I am new to the repo, so was wondering if i was going about it the right way. Thanks again :D Also i decided to give Recognize shareable_constant_value magic comment in Style/MutableConstant a shot as my first issue. |
I believe the following code should not raise an offense:
This is made worse by autocorrection that only moves the constant and not the
private_constant
just following it.The text was updated successfully, but these errors were encountered: