Skip to content

Commit

Permalink
Merge pull request #7657 from rrosenblum/empty_line_between_defs_context
Browse files Browse the repository at this point in the history
Add the method name to the highlight area of Layout/EmptyLineBetweenDefs
  • Loading branch information
koic committed Jan 22, 2020
2 parents c3bc810 + 3b6bd3e commit d7a6d1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* [#7636](https://github.com/rubocop-hq/rubocop/issues/7636): Remove `console` from `Lint/Debugger` to prevent false positives. ([@gsamokovarov][])
* [#7641](https://github.com/rubocop-hq/rubocop/issues/7641): **(Breaking)** Remove `Style/BracesAroundHashParameters` cop. ([@pocke][])
* Add the method name to highlight area of `Layout/EmptyLineBetweenDefs` to help provide more context. ([@rrosenblum][])

## 0.79.0 (2020-01-06)

Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/layout/empty_line_between_defs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def check_defs(nodes)
return if nodes.all?(&:single_line?) &&
cop_config['AllowAdjacentOneLineDefs']

add_offense(nodes.last, location: :keyword)
location = nodes.last.loc.keyword.join(nodes.last.loc.name)
add_offense(nodes.last, location: location)
end

def autocorrect(node)
Expand Down
26 changes: 13 additions & 13 deletions spec/rubocop/cop/layout/empty_line_between_defs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class J
def n
end
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
end
# checks something
Expand All @@ -33,7 +33,7 @@ def n
# checks something o-related
# and more
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
end
RUBY
Expand Down Expand Up @@ -74,7 +74,7 @@ def foo
true
end
def bar
^^^ Use empty lines between method definitions.
^^^^^^^ Use empty lines between method definitions.
true
end
else
Expand All @@ -95,7 +95,7 @@ def self.foo
true
end
def self.bar
^^^ Use empty lines between method definitions.
^^^^^^^^^^^^ Use empty lines between method definitions.
true
end
end
Expand Down Expand Up @@ -123,7 +123,7 @@ def foo
true
end
def self.bar
^^^ Use empty lines between method definitions.
^^^^^^^^^^^^ Use empty lines between method definitions.
true
end
end
Expand Down Expand Up @@ -215,7 +215,7 @@ def initialize(attrs)
expect_offense(<<~RUBY)
def a; end
def b; end
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -232,7 +232,7 @@ def a; end
def b; end
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
RUBY

expect_correction(<<~RUBY)
Expand Down Expand Up @@ -262,7 +262,7 @@ def n
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
end
RUBY
Expand Down Expand Up @@ -293,10 +293,10 @@ def b; end
def a; end
def b; end
def c # Not a one-liner, so this is an offense.
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
def d; end # Also an offense since previous was multi-line:
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
RUBY

expect_correction(<<~RUBY)
Expand Down Expand Up @@ -340,7 +340,7 @@ def n
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
RUBY

Expand All @@ -363,7 +363,7 @@ def n
end
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
RUBY

Expand All @@ -386,7 +386,7 @@ def n
def o
^^^ Use empty lines between method definitions.
^^^^^ Use empty lines between method definitions.
end
RUBY

Expand Down

0 comments on commit d7a6d1b

Please sign in to comment.