From d0e9aa1a6ca6907658a4548a50576562117d74b0 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 19 Oct 2021 02:22:29 +0900 Subject: [PATCH] Change `AllowAdjacentOneLineDefs` config parameter of `Layout/EmptyLineBetweenDefs` 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. --- ..._adjacent_one_line_defs_true_by_default.md | 1 + config/default.yml | 8 +++---- .../cop/layout/empty_line_between_defs.rb | 23 ++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 changelog/change_allow_adjacent_one_line_defs_true_by_default.md diff --git a/changelog/change_allow_adjacent_one_line_defs_true_by_default.md b/changelog/change_allow_adjacent_one_line_defs_true_by_default.md new file mode 100644 index 00000000000..65406891ca8 --- /dev/null +++ b/changelog/change_allow_adjacent_one_line_defs_true_by_default.md @@ -0,0 +1 @@ +* [#10199](https://github.com/rubocop/rubocop/pull/10199): Change `AllowAdjacentOneLineDefs` config parameter of `Layout/EmptyLineBetweenDefs` to `true` by default . ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 572710c6aea..57561e5cc1a 100644 --- a/config/default.yml +++ b/config/default.yml @@ -511,13 +511,13 @@ Layout/EmptyLineBetweenDefs: StyleGuide: '#empty-lines-between-methods' Enabled: true VersionAdded: '0.49' - VersionChanged: '1.7' + VersionChanged: '<>' 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 diff --git a/lib/rubocop/cop/layout/empty_line_between_defs.rb b/lib/rubocop/cop/layout/empty_line_between_defs.rb index 9e65de5101d..6bd24124d25 100644 --- a/lib/rubocop/cop/layout/empty_line_between_defs.rb +++ b/lib/rubocop/cop/layout/empty_line_between_defs.rb @@ -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