Module: RuboCop::SketchUp::NamespaceChecker

Instance Method Summary collapse

Instance Method Details

#check_namespace(node) ⇒ Object


25
26
27
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 25

def check_namespace(node)
  add_offense(node, location:  :name, severity: :error) if in_namespace?(node)
end

#in_namespace?(node) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
32
33
34
35
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 29

def in_namespace?(node)
  # parent_module_name might return nil if for instance a method is
  # defined within a block. (Apparently that is possible...)
  return false if node.parent_module_name.nil?
  namespace = SketchUp::Namespace.new(node.parent_module_name)
  namespaces.include?(namespace.first)
end

#namespacesObject

Raises:

  • (NotImplementedError)

37
38
39
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 37

def namespaces
  raise NotImplementedError
end

#on_casgn(node) ⇒ Object

Constant assignment.


21
22
23
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 21

def on_casgn(node)
  check_namespace(node)
end

#on_class(node) ⇒ Object


7
8
9
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 7

def on_class(node)
  check_namespace(node)
end

#on_def(node) ⇒ Object Also known as: on_defs


15
16
17
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 15

def on_def(node)
  check_namespace(node)
end

#on_module(node) ⇒ Object


11
12
13
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 11

def on_module(node)
  check_namespace(node)
end