Skip to content

Commit

Permalink
[Fix #8880] Fix an error for Style/ClassLength
Browse files Browse the repository at this point in the history
Fixes #8880.

This PR fixes an error for `Style/ClassLength`
when overlapping constant assignments.
  • Loading branch information
koic authored and bbatsov committed Oct 12, 2020
1 parent 0798771 commit eb9b664
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
* [#8872](https://github.com/rubocop-hq/rubocop/issues/8872): Fix an error for `Metrics/ClassLength` when multiple assignments to constants. ([@koic][])
* [#8871](https://github.com/rubocop-hq/rubocop/issues/8871): Fix a false positive for `Style/RedundantBegin` when using `begin` for method argument or part of conditions. ([@koic][])
* [#8875](https://github.com/rubocop-hq/rubocop/issues/8875): Fix an incorrect auto-correct for `Style/ClassEqualityComparison` when comparing class name. ([@koic][])
* [#8880](https://github.com/rubocop-hq/rubocop/issues/8880): Fix an error for `Style/ClassLength` when overlapping constant assignments. ([@koic][])

## 0.93.0 (2020-10-08)

Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/metrics/class_length.rb
Expand Up @@ -49,7 +49,9 @@ def on_casgn(node)
_scope, _name, block_node = *node
end

check_code_length(block_node) if block_node.class_definition?
return unless block_node.respond_to?(:class_definition?) && block_node.class_definition?

check_code_length(block_node)
end

private
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/metrics/class_length_spec.rb
Expand Up @@ -202,6 +202,14 @@ class Test
end
end

context 'when overlapping constant assignments' do
it 'registers an offense' do
expect_no_offenses(<<~RUBY)
X = Y = Z = do_something
RUBY
end
end

context 'when inspecting a class defined with Struct.new' do
it 'registers an offense' do
expect_offense(<<~RUBY)
Expand Down

0 comments on commit eb9b664

Please sign in to comment.