-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rails-compatible indentation of private and protected methods #1342
Comments
Isn't the Rails convention actually: class MyClass
def a_public_method
end
private
def a_private_method
end
end |
The guide isn't clear. It just says Indent after private/protected. I just browsed the Rails source code a little bit and it uses all three styles: indent, dedent and the one I described in the issue. An example of the last one is https://github.com/rails/rails/blob/master/activerecord/lib/active_record/aggregations.rb#L230. Either way I'd like to enforce this style in my project and it'd be great if Rubocop gave me a hand. |
I wouldn't want to call your preferred style the "rails" style for the reasons below. I can't think of a good name though. (Naming things is hard.)
|
Absolutely agree, @mikegee. Initially I assumed that this is the style used in Rails source code but in reality it's very inconsistent. I must admit that I don't have an idea for a nice name. |
I would like to implement this. In my style guide it may looks like:
Example: class Cat
def meow
puts('Meow!')
end
protected
def can_we_be_friends?(another_cat)
# some logic
end
private
def meow_at_3am?
rand < 0.8
end
end As I understand changes could affect Style/IndentationConsistency:
AllowProtectedAndPrivateMethodsBeIndented: true but is it ok if I will check this config in @bbatsov can you please help me? Will it be merged? |
@mikegee. I thought that Rails source code was inconsistent because they could not use Rubocop goodness to solve it 😌 |
I'm OK with adding support for the suggested style. Not sure what'd be best regarding |
@jonas054 What do you think about it? |
@jonas054 is on vacation. He'll be back in about a month. |
Oh, ok. Thank you for response, Bozhidar @bbatsov.
|
@Proghat Go ahead and start coding if you like. I'll try to review your work if you submit a PR. Some thoughts:
|
Hello. |
Rubocop doesn't (yet) support the Rails style of private method indentation (see rubocop/rubocop#1342).
Rubocop doesn't (yet) support the Rails style of private method indentation (see rubocop/rubocop#1342).
Rubocop doesn't (yet) support the Rails style of private method indentation (see rubocop/rubocop#1342).
[Fix #1342] Support rails indentation style
Rubocop doesn't (yet) support the Rails style of private method indentation (see rubocop/rubocop#1342).
Rubocop doesn't (yet) support the Rails style of private method indentation (see rubocop/rubocop#1342).
This rubocop is designed for pure Ruby. Rails is a full framework and uses different style guides all together. Just use Rail generator and you will see the style is different, which will not change for 1000 years and same goes for the community. For Rails please use the gem "rubocop-rails" instead with will work with the '.rubocop.yml' file. For more visit https://github.com/bbatsov/rubocop |
Internally they can use whatever code style they want, but no framework defines the code style of a project. |
For those who came here looking for a solution (noobs like me), just use:
EDIT 2019/08/01: |
Since Rubocop v0.72
|
As mentioned here: rubocop/rubocop#1342 (comment) this setting is now updated to use a different value to enforce the intended style
Problem
Currently Rubocop can check the indentation of
private
,protected
andpublic
modifiers. Unfortunately it isn't able to check whether the code that follows uses the Rails convention of indenting private and protected methods with respect toprivate
andprotected
. For example the styleshould be supported.
Solution
The
Style/AccessModifierIndentation
cop could support a newEnforcedStyle
calledrails
that would use the Rails convention.rubocop -V
returnsThe text was updated successfully, but these errors were encountered: