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

Add AllowAdjacentOneLineDefs: true to Layout/EmptyLineBetweenDefs #695

Open
soulcutter opened this issue Feb 18, 2025 · 0 comments
Open

Comments

@soulcutter
Copy link

soulcutter commented Feb 18, 2025

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:

def isbn = lookup(“isbn”)
def barcode = lookup(“barcode”)
def sku = Skus.find(isbn)

def title = lookup(“title”) || “unknown”
def author = lookup(“author”)

which would get formatted by standardrb 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.

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

No branches or pull requests

1 participant