Module: RuboCop::SketchUp::NamespaceChecker

Instance Method Summary collapse

Instance Method Details

#check_namespace(node) ⇒ Object



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

def check_namespace(node)
  return unless in_namespace?(node)

  add_offense(node, location: :name, severity: :error)
end

#in_namespace?(node) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 31

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)


40
41
42
# File 'lib/rubocop/sketchup/namespace_checker.rb', line 40

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