Description
I propose a rule change which would allow visual grouping of oneline methods, which can convey semantic meaning.
The relevant setting AllowAdjacentOneLineDefs
is under Layout/EmptyLineBetweenDefs
This setting appears to have been part of a large import of default Rubocop settings and not an explicitly decided and a settled matter. It also sounds like this was at one time a rubocop default, and that does not appear to be the case today when I ran standardrb and rubocop autofixing over the same code. It may be that the default changed upstream.
A contrived example of what happens today:
Given this code:
def isbn = lookup(“isbn”)
def barcode = lookup(“barcode”)
def sku = Skus.find(isbn)
def title = lookup(“title”) || “unknown”
def author = lookup(“author”)
standardrb would format it today as:
def isbn = lookup(“isbn”)
def barcode = lookup(“barcode”)
def sku = Skus.find(isbn)
def title = lookup(“title”) || “unknown”
def author = lookup(“author”)
Not only does this double spacing make the code longer - and you'd expect single-line methods to be used for terseness - but the method grouping is lost, which conveys less information to the developer. My example is contrived, but I have seen this formatting make real, production code harder to read also.
The proposed rule change would have kept the original code the same.