Skip to content

Commit

Permalink
Change AllowAdjacentOneLineDefs config parameter of `Layout/EmptyLi…
Browse files Browse the repository at this point in the history
…neBetweenDefs` to `true` by default

This PR changes `AllowAdjacentOneLineDefs` config parameter of `Layout/EmptyLineBetweenDefs` to `true` by default.

Currently, warnings that occur are different for each type of definition grouped as shown below.

```console
% cat example.rb
class FooError < StandardError; end
class BarError < StandardError; end
class BazError < StandardError; end

attr_accessor :foo
attr_accessor :bar
attr_accessor :baz

before_action :do_foo
before_action :do_bar
before_action :do_baz
```

```console
% bundle exec rubocop
(snip)

Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment:
Missing frozen string literal comment.
class FooError < StandardError; end
^
example.rb:2:1: C: [Correctable] Layout/EmptyLineBetweenDefs: Expected 1
empty line between class definitions; found 0.
class BarError < StandardError; end
^^^^^^^^^^^^^^
example.rb:3:1: C: [Correctable] Layout/EmptyLineBetweenDefs: Expected 1
empty line between class definitions; found 0.
class BazError < StandardError; end
^^^^^^^^^^^^^^

1 file inspected, 3 offenses detected, 3 offenses auto-correctable
```

This `AllowAdjacentOneLineDefs: true` makes it consistent so that there are no blank lines when
grouped by one liner definitions.
  • Loading branch information
koic committed Oct 25, 2021
1 parent e1de418 commit d0e9aa1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
@@ -0,0 +1 @@
* [#10199](https://github.com/rubocop/rubocop/pull/10199): Change `AllowAdjacentOneLineDefs` config parameter of `Layout/EmptyLineBetweenDefs` to `true` by default . ([@koic][])
8 changes: 4 additions & 4 deletions config/default.yml
Expand Up @@ -511,13 +511,13 @@ Layout/EmptyLineBetweenDefs:
StyleGuide: '#empty-lines-between-methods'
Enabled: true
VersionAdded: '0.49'
VersionChanged: '1.7'
VersionChanged: '<<next>>'
EmptyLineBetweenMethodDefs: true
EmptyLineBetweenClassDefs: true
EmptyLineBetweenModuleDefs: true
# If `true`, this parameter means that single line method definitions don't
# need an empty line between them.
AllowAdjacentOneLineDefs: false
# `AllowAdjacentOneLineDefs` means that single line method definitions don't
# need an empty line between them. `true` by default.
AllowAdjacentOneLineDefs: true
# Can be array to specify minimum and maximum number of empty lines, e.g. [1, 2]
NumberOfEmptyLines: 1

Expand Down
23 changes: 22 additions & 1 deletion lib/rubocop/cop/layout/empty_line_between_defs.rb
Expand Up @@ -77,13 +77,34 @@ module Layout
# def b
# end
#
# @example AllowAdjacentOneLineDefs: true
# @example AllowAdjacentOneLineDefs: true (default)
#
# # good
# class ErrorA < BaseError; end
# class ErrorB < BaseError; end
# class ErrorC < BaseError; end
#
# # good
# class ErrorA < BaseError; end
#
# class ErrorB < BaseError; end
#
# class ErrorC < BaseError; end
#
# @example AllowAdjacentOneLineDefs: false
#
# # bad
# class ErrorA < BaseError; end
# class ErrorB < BaseError; end
# class ErrorC < BaseError; end
#
# # good
# class ErrorA < BaseError; end
#
# class ErrorB < BaseError; end
#
# class ErrorC < BaseError; end
#
class EmptyLineBetweenDefs < Base
include RangeHelp
extend AutoCorrector
Expand Down

0 comments on commit d0e9aa1

Please sign in to comment.