Skip to content

Commit

Permalink
Merge pull request #9910 from jonas054/8469_fix_singleton_class_op
Browse files Browse the repository at this point in the history
[Fix #8469] Add singleton class operator inspection
  • Loading branch information
koic committed Jul 4, 2021
2 parents 33ed53a + abb9032 commit 79f6115
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/fix_space_around_singleton_class_operator.md
@@ -0,0 +1 @@
* [#8469](https://github.com/rubocop/rubocop/issues/8469): Add inspection of `class <<` to `Layout/SpaceAroundOperators`. ([@jonas054][])
4 changes: 4 additions & 0 deletions lib/rubocop/cop/layout/space_around_operators.rb
Expand Up @@ -63,6 +63,10 @@ def self.autocorrect_incompatible_with
[Style::SelfAssignment]
end

def on_sclass(node)
check_operator(:sclass, node.loc.operator, node.source_range)
end

def on_pair(node)
return unless node.hash_rocket?

Expand Down
12 changes: 9 additions & 3 deletions spec/rubocop/cop/layout/space_around_operators_spec.rb
Expand Up @@ -278,9 +278,15 @@ def init(name=nil)
RUBY
end

it 'accepts the construct class <<self with no space after <<' do
expect_no_offenses(<<~RUBY)
class <<self
it 'registers an offense and corrects singleton class operator`' do
expect_offense(<<~RUBY)
class<<self
^^ Surrounding space missing for operator `<<`.
end
RUBY

expect_correction(<<~RUBY)
class << self
end
RUBY
end
Expand Down

0 comments on commit 79f6115

Please sign in to comment.