-
-
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
Differentiate between empty lines at beginning and end #4812
Comments
I consider the Rubocop rule and behaviour of EmptyLinesAroundClassBody to be correct and sensible. But I also agree that, for whatever reason, if someone really really wants to use the above, then why not? I assume it may be trivial to add, since one could use the existing cop rule, and just not add a newline to the bottom part. You may probably have to convince bbatsov either way. PS: I think it may be easier if you just focus on one suggestion in this issue request; the other three could be added at a later time. Sometimes it takes a little while for things to change. What name would you give the new rule by the way? Coming up with a new name is often difficult; old name is EmptyLInesAroundClassBody (probably misspelled? EmptyLinesAroundClassBody .. but let's ignore the typo anyway) |
Thanks for the quick reply! I also tend to use the above style in specs, because it helps the file to be more readable without the end getting too spaced out. describe "MyAwesomeClass" do
describe "#my_awesome_method" do
context "when it's awesome" do
context "and when the parameter is awesome" do
it "returns something else that's awesome" do
...
end
end
end
end
end But I totally understand I might be in the minority in liking this coding style. As far as naming suggestions, you could split this property into |
I like the idea of adding configurations to |
I've spiked out a solution, by adding an additional Layout/EmptyLinesAroundClassBody:
EnforcedStyle: no_empty_lines
SupportedStyles:
- empty_lines
- empty_lines_except_namespace
- empty_lines_special
- no_empty_lines
- beginning_only I originally also had The actual changes would happen in This is a middle-ground approach compared to 1) splitting into 2 cops, and 2) introducing another config option(s) like WDYT? |
That works for me! It solves my problem. |
👍 |
@LandonSchropp I don't think the solution as proposed will work for RSpecs (describe, etc) |
Late to the party, but as long as we're considering modifying this Cop, I'd love it if I could exclude Example: class MyThing
extend Forwardable
attr_reader :thing
delegate %i( a b c ) => :thing
def initialize(thing)
@thing = thing
end
end I don't know if other class methods should also be excluded from the cop, like Also happy to open a separate issue about it if that is preferred. |
Nevermind, now I see that was added as |
@jmks If you have a solution ready, a PR would be welcome. |
Sorry, this fell off my radar. I'll make the PR in the next couple days. |
…Layout/EmptyLinesAroundClassBody`
To me, the spacing between the class definition and the first method makes this a little difficult to read.
Rubocop provides the
Layout/EmptyLInesAroundClassBody
style, which allows me to add spaces inside the class.However, that extra space at the bottom feels unnecessary to me. At the top, it helps with the readability of the method name and lets me group those two things together. At the bottom, it's just inserting extra whitespace.
What I really want to do is set the line spacing separately for the top and bottom of the class. My ideal would look like this:
I could also see adding these types of options for other
Layout/EmptyLine
styles as well, such asLayout/EmptyLineAroundBlockBody
orLayout/EmptyLineAroundModuleBody
.The text was updated successfully, but these errors were encountered: