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

A semicolon in the same line as the method signature is allowed #4252

Closed
bquorning opened this issue Apr 8, 2017 · 5 comments
Closed

A semicolon in the same line as the method signature is allowed #4252

bquorning opened this issue Apr 8, 2017 · 5 comments
Labels

Comments

@bquorning
Copy link
Contributor

A semicolon in the same line as the method signature isn’t violating any existing cop.

Expected behavior

I expect RuboCop (Style/Semicolon) to complain about having a semicolon after def foo.

Actual behavior

No offenses detected.

Steps to reproduce the problem

Run rubocop on this file:

# frozen_string_literal: true

def foo; nil
end

RuboCop version

$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin15)
@bbatsov bbatsov added the bug label Apr 11, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 11, 2017

Likely a bug in the detection of one-line methods.

@Drenmi
Copy link
Collaborator

Drenmi commented Apr 11, 2017

Hm. I don't particularly like the suggested behaviour. I am more inclined to consider this a case of a misnamed cop. Perhaps it should be RedundantSemicolon? Disallowing semicolons completely contradicts the Style Guide on things like empty classes, e.g. class Foo; end, and opens a can of worms with semantic changes.

Perhaps SingleLineMethod can be extended to cover the case above? Although technically it's also not a single line method. More like a 1.5 line method. 😅

@bquorning
Copy link
Contributor Author

When opening the issue, I wasn’t sure whether to blame Semicolon or SingleLineMethod. You could argue that SingleLineMethod should ensure a newline before end and a newline after the method signature.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 11, 2017

@Drenmi The purpose of this cop was to find multiple expressions on the same line, that should actually be on separate lines. Many early day cops have horrible names. I didn't really think much about them back then.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 11, 2017

And, of course, like most very old cops - this one has poor documentation and no code examples. 😄

garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 5, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 5, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 5, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 5, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 5, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Nov 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants