From abb903277de8ae6ff7ef7ab6e8f3c017cbde00a3 Mon Sep 17 00:00:00 2001 From: Jonas Arvidsson Date: Sat, 3 Jul 2021 12:41:22 +0200 Subject: [PATCH] [Fix #8469] Add singleton class operator inspection We classify the << operator used for the singleton class construct `class << self` as an operator like any other. This means that not inspecting it was a bug, and this change fixes it. --- .../fix_space_around_singleton_class_operator.md | 1 + lib/rubocop/cop/layout/space_around_operators.rb | 4 ++++ .../cop/layout/space_around_operators_spec.rb | 12 +++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelog/fix_space_around_singleton_class_operator.md diff --git a/changelog/fix_space_around_singleton_class_operator.md b/changelog/fix_space_around_singleton_class_operator.md new file mode 100644 index 00000000000..a07d33720e3 --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/layout/space_around_operators.rb b/lib/rubocop/cop/layout/space_around_operators.rb index 3e72bb23bfa..e03d57b9116 100644 --- a/lib/rubocop/cop/layout/space_around_operators.rb +++ b/lib/rubocop/cop/layout/space_around_operators.rb @@ -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? diff --git a/spec/rubocop/cop/layout/space_around_operators_spec.rb b/spec/rubocop/cop/layout/space_around_operators_spec.rb index 8cbe15701fe..a2fa14295d1 100644 --- a/spec/rubocop/cop/layout/space_around_operators_spec.rb +++ b/spec/rubocop/cop/layout/space_around_operators_spec.rb @@ -278,9 +278,15 @@ def init(name=nil) RUBY end - it 'accepts the construct class <