Skip to content

Commit

Permalink
Merge pull request #6679 from rmm5t/fix-lint-disjunctive-assignment-i…
Browse files Browse the repository at this point in the history
…n-constructor-for-empty-constructors

[Fix #6678] Allow empty constructors during Lint/DisjunctiveAssignmentInConstructor
  • Loading branch information
koic authored Jan 17, 2019
2 parents 457cd4f + 608943f commit 9402436
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6678](https://github.com/rubocop-hq/rubocop/issues/6678): Fix `Lint/DisjunctiveAssignmentInConstructor` when it finds an empty constructor. ([@rmm5t][])

## 0.63.0 (2019-01-16)

### New features
Expand Down Expand Up @@ -3758,3 +3762,4 @@
[@Intrepidd]: https://github.com/Intrepidd
[@Ruffeng]: https://github.com/Ruffeng
[@roooodcastro]: https://github.com/roooodcastro
[@rmm5t]: https://github.com/rmm5t
7 changes: 4 additions & 3 deletions lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def on_def(node)
def check(node)
return unless node.method_name == :initialize

check_body(node)
check_body(node.body)
end

# @param [DefNode] node a constructor definition
def check_body(node)
body = node.body
def check_body(body)
return if body.nil?

case body.type
when :begin
check_body_lines(body.child_nodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
) do
subject(:cop) { described_class.new(config) }

context 'empty constructor' do
it 'accepts' do
expect_no_offenses(<<-RUBY.strip_indent)
class Banana
def initialize
end
end
RUBY
end
end

context 'constructor does not have disjunctive assignment' do
it 'accepts' do
expect_no_offenses(<<-RUBY.strip_indent)
Expand Down

0 comments on commit 9402436

Please sign in to comment.