Skip to content

Commit

Permalink
[Doc] Tweak examples for AllowMultilineFinalElement
Browse files Browse the repository at this point in the history
This commit tweaks example to clarify the diff for the `AllowMultilineFinalElement` difference.
  • Loading branch information
koic committed Apr 14, 2023
1 parent c59e349 commit 8dfe1b4
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 264 deletions.
59 changes: 25 additions & 34 deletions lib/rubocop/cop/layout/first_array_element_line_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,40 @@ module Layout
# Checks for a line break before the first element in a
# multi-line array.
#
# @example AllowMultilineFinalElement: false (default)
# @example
#
# # bad
# [ :a,
# :b]
# # bad
# [ :a,
# :b]
#
# # bad
# [ :a, {
# :b => :c
# }]
# # good
# [
# :a,
# :b]
#
# # good
# [:a, :b]
# # good
# [:a, :b]
#
# # good
# [
# :a,
# :b]
# @example AllowMultilineFinalElement: false (default)
#
# # good
# [
# :a, {
# :b => :c
# }]
# # bad
# [ :a, {
# :b => :c
# }]
#
# @example AllowMultilineFinalElement: true
# # good
# [
# :a, {
# :b => :c
# }]
#
# # bad
# [ :a,
# :b]
#
# # good
# [ :a, {
# :b => :c
# }]
# @example AllowMultilineFinalElement: true
#
# # good
# [
# :a,
# :b]
# # good
# [:a, {
# :b => :c
# }]
#
# # good
# [:a, :b]
class FirstArrayElementLineBreak < Base
include FirstElementLineBreak
extend AutoCorrector
Expand Down
26 changes: 7 additions & 19 deletions lib/rubocop/cop/layout/first_hash_element_line_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ module Layout
# Checks for a line break before the first element in a
# multi-line hash.
#
# @example AllowMultilineFinalElement: false (default)
# @example
#
# # bad
# { a: 1,
# b: 2}
#
# # bad
# { a: 1, b: {
# c: 3
# }}
#
# # good
# {
# a: 1,
Expand All @@ -28,11 +23,14 @@ module Layout
# c: 3
# }}
#
# @example AllowMultilineFinalElement: true
# @example AllowMultilineFinalElement: false (default)
#
# # bad
# { a: 1,
# b: 2}
# { a: 1, b: {
# c: 3
# }}
#
# @example AllowMultilineFinalElement: true
#
# # bad
# { a: 1,
Expand All @@ -45,16 +43,6 @@ module Layout
# c: 3
# }}
#
# # good
# {
# a: 1,
# b: 2 }
#
# # good
# {
# a: 1, b: {
# c: 3
# }}
class FirstHashElementLineBreak < Base
include FirstElementLineBreak
extend AutoCorrector
Expand Down
94 changes: 42 additions & 52 deletions lib/rubocop/cop/layout/first_method_argument_line_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,63 @@ module Layout
# Checks for a line break before the first argument in a
# multi-line method call.
#
# @example AllowMultilineFinalElement: false (default)
#
# # bad
# method(foo, bar,
# baz)
#
# # bad
# method(foo, bar, {
# baz: "a",
# qux: "b",
# })
# @example
#
# # good
# method(
# foo, bar,
# baz)
# # bad
# method(foo, bar,
# baz)
#
# # good
# method(
# foo, bar, {
# baz: "a",
# qux: "b",
# })
# # good
# method(
# foo, bar,
# baz)
#
# # ignored
# method foo, bar,
# baz
#
# @example AllowMultilineFinalElement: true
# @example AllowMultilineFinalElement: false (default)
#
# # bad
# method(foo, bar, {
# baz: "a",
# qux: "b",
# })
#
# # bad
# method(foo, bar,
# baz)
# # good
# method(
# foo, bar, {
# baz: "a",
# qux: "b",
# })
#
# # bad
# method(foo,
# bar,
# {
# baz: "a",
# qux: "b",
# }
# )
# @example AllowMultilineFinalElement: true
#
# # good
# method(foo, bar, {
# # bad
# method(foo,
# bar,
# {
# baz: "a",
# qux: "b",
# })
# }
# )
#
# # good
# method(
# foo, bar,
# baz)
# # good
# method(foo, bar, {
# baz: "a",
# qux: "b",
# })
#
# # good
# method(
# foo,
# bar,
# {
# baz: "a",
# qux: "b",
# }
# )
# # good
# method(
# foo,
# bar,
# {
# baz: "a",
# qux: "b",
# }
# )
#
# # ignored
# method foo, bar,
# baz
class FirstMethodArgumentLineBreak < Base
include FirstElementLineBreak
extend AutoCorrector
Expand Down
93 changes: 38 additions & 55 deletions lib/rubocop/cop/layout/first_method_parameter_line_break.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,52 @@ module Layout
# Checks for a line break before the first parameter in a
# multi-line method parameter definition.
#
# @example AllowMultilineFinalElement: false (default)
#
# # bad
# def method(foo, bar,
# baz)
# do_something
# end
#
# # bad
# def method(foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
# @example
#
# # good
# def method(
# foo, bar,
# baz)
# do_something
# end
# # bad
# def method(foo, bar,
# baz)
# do_something
# end
#
# # good
# def method(
# foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
# # good
# def method(
# foo, bar,
# baz)
# do_something
# end
#
# # ignored
# def method foo,
# bar
# do_something
# end
# # ignored
# def method foo,
# bar
# do_something
# end
#
# @example AllowMultilineFinalElement: true
# @example AllowMultilineFinalElement: false (default)
#
# # bad
# def method(foo, bar,
# baz)
# do_something
# end
# # bad
# def method(foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
#
# # good
# def method(foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
# # good
# def method(
# foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
#
# # good
# def method(
# foo, bar,
# baz)
# do_something
# end
# @example AllowMultilineFinalElement: true
#
# # ignored
# def method foo,
# bar
# do_something
# end
# # good
# def method(foo, bar, baz = {
# :a => "b",
# })
# do_something
# end
#
class FirstMethodParameterLineBreak < Base
include FirstElementLineBreak
Expand Down

0 comments on commit 8dfe1b4

Please sign in to comment.