Skip to content

Commit

Permalink
Merge pull request #1096 from geniou/class_and_module_children_single…
Browse files Browse the repository at this point in the history
…_method

[Fixes #1094] Fix bug in ClassAndModuleChildren
  • Loading branch information
bbatsov committed May 18, 2014
2 parents 5ae2530 + 49ab420 commit 395a0f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Fix problem that appears in some installations when reading empty YAML files. ([@jonas054][])
* [#1022](https://github.com/bbatsov/rubocop/issues/1022): A Cop will no longer auto-correct a file that's excluded through an `Exclude` setting in the cop's configuration. ([@jonas054][])
* Fix paths in `Exclude` config section not being recognized on Windows. ([@wndhydrnt][])
* [#1094](https://github.com/bbatsov/rubocop/issues/1094): Fix ClassAndModuleChildren for classes with a single method. ([@geniou][])

## 0.21.0 (24/04/2014)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/class_and_module_children.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check_compact_style(node, body)
end

def one_child?(body)
body && body.type != :begin
body && [:module, :class].include?(body.type)
end

def compact_node_name?(node)
Expand Down
22 changes: 12 additions & 10 deletions spec/rubocop/cop/style/class_and_module_children_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
subject(:cop) { described_class.new(config) }

context 'nested style' do
let(:cop_config) do
{
'EnforcedStyle' => 'nested'
}
end
let(:cop_config) { { 'EnforcedStyle' => 'nested' } }

it 'registers an offense for not nested classes' do
inspect_source(cop, ['class FooClass::BarClass', 'end'])
Expand Down Expand Up @@ -62,11 +58,7 @@
end

context 'compact style' do
let(:cop_config) do
{
'EnforcedStyle' => 'compact'
}
end
let(:cop_config) { { 'EnforcedStyle' => 'compact' } }

it 'registers a offense for classes with nested children' do
inspect_source(cop,
Expand Down Expand Up @@ -125,5 +117,15 @@
])
expect(cop.offenses).to be_empty
end

it 'accepts class / module with single method' do
inspect_source(cop,
['class FooClass',
' def bar_method',
' end',
'end'
])
expect(cop.offenses).to be_empty
end
end
end

0 comments on commit 395a0f8

Please sign in to comment.