Class: Simplabs::Excellent::Checks::GlobalVariableCheck
- Defined in:
- lib/simplabs/excellent/checks/global_variable_check.rb
Overview
This check reports global variables. Global variables introduce strong dependencies between otherwise unrelated parts of code and their use is usually considered extremely bad style.
Applies to
-
global variables
Constant Summary collapse
- DEFAULT_WHITELIST =
%w(! @ & ` ' + \d+ ~ = / \ , ; \. < > _ 0 * $ ? : " DEBUG FILENAME LOAD_PATH stdin stdout stderr VERBOSE -0 -a -d -F -i -I -l -p -v)
Instance Attribute Summary
Attributes inherited from Base
#interesting_contexts, #interesting_files, #options, #warnings
Instance Method Summary collapse
-
#evaluate(context) ⇒ Object
:nodoc:.
-
#initialize(options = {}) ⇒ GlobalVariableCheck
constructor
:nodoc:.
Methods inherited from Base
#add_warning, #evaluate_context, #warnings_for
Constructor Details
#initialize(options = {}) ⇒ GlobalVariableCheck
:nodoc:
19 20 21 22 23 24 |
# File 'lib/simplabs/excellent/checks/global_variable_check.rb', line 19 def initialize( = {}) #:nodoc: super @whitelist = [:whitelist] ||= DEFAULT_WHITELIST @interesting_contexts = [Parsing::GvarContext, Parsing::GasgnContext] @interesting_files = [/\.rb$/, /\.erb$/] end |
Instance Method Details
#evaluate(context) ⇒ Object
:nodoc:
26 27 28 29 30 |
# File 'lib/simplabs/excellent/checks/global_variable_check.rb', line 26 def evaluate(context) #:nodoc: if context.is_a?(Parsing::GasgnContext) || !@whitelist.include?(context.full_name) add_warning(context, 'Global variable {{variable}} used.', { :variable => context.full_name }) end end |