A semicolon in the same line as the method signature isn鈥檛 violating any existing cop.
I expect RuboCop (Style/Semicolon) to complain about having a semicolon after def foo.
No offenses detected.
Run rubocop on this file:
# frozen_string_literal: true
def foo; nil
end
$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin15)
Likely a bug in the detection of one-line methods.
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. 馃槄
When opening the issue, I wasn鈥檛 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.
@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.
And, of course, like most very old cops - this one has poor documentation and no code examples. 馃槃