Class: Simplabs::Excellent::Checks::SingletonVariableCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/singleton_variable_check.rb

Overview

This check reports class variables. Class variables in Ruby have a very complicated inheritance policy that often leads to errors. Usually class variables can be replaced with another construct which will also lead to better design.

Applies to

  • class variables

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initializeSingletonVariableCheck

:nodoc:



17
18
19
20
21
# File 'lib/simplabs/excellent/checks/singleton_variable_check.rb', line 17

def initialize #:nodoc:
  super
  @interesting_nodes = [:cvar]
  @interesting_files = [/\.rb$/, /\.erb$/]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



23
24
25
# File 'lib/simplabs/excellent/checks/singleton_variable_check.rb', line 23

def evaluate(context) #:nodoc:
  add_warning(context, 'Singleton variable {{variable}} used.', { :variable => context.full_name })
end