class RubyLint::Analysis::Base
Base
analysis class that provides various helper methods commonly used across analysis classes.
@!attribute [r] report
@return [RubyLint::Report]
@!attribute [r] vm
@return [RubyLint::VirtualMachine]
@!attribute [r] config
@return [RubyLint::Configuration]
Constants
- SCOPES
Array containing the callback names for which a new scope should be created.
@return [Array<Symbol>]
Attributes
Public Class Methods
Returns a boolean that indicates if the analysis class should be used or not.
@param [RubyLint::AST::Node] ast @param [RubyLint::VirtualMachine] vm @return [TrueClass|FalseClass]
# File lib/ruby-lint/analysis/base.rb, line 47 def self.analyze?(ast, vm) return true end
Registers the current class in {RubyLint::Configuration.available_analysis_classes}.
@param [String] name A human friendly name of the current class.
# File lib/ruby-lint/analysis/base.rb, line 35 def self.register(name) Configuration.available_analysis_classes[name] = self end
Public Instance Methods
Called after a new instance of this class is created.
# File lib/ruby-lint/analysis/base.rb, line 54 def after_initialize unless vm.is_a?(VirtualMachine) raise( ArgumentError, 'Analysis classes require a valid RubyLint::VirtualMachine ' \ 'instance to be set using `SomeAnalysisClass.new(:vm => ...)`' ) end @scopes = [] end
Protected Instance Methods
Adds a message of the given level.
@param [Symbol] level @param [String] message @param [String] node
# File lib/ruby-lint/analysis/base.rb, line 149 def add_message(level, message, node) return unless report report.add( :level => level, :message => message, :line => node.line, :column => node.column, :file => node.file, :node => node ) end
Returns the current scope.
@return [RubyLint::Definition::RubyObject]
# File lib/ruby-lint/analysis/base.rb, line 83 def current_scope return @scopes[-1] end
Adds an error message to the report.
@see add_message
# File lib/ruby-lint/analysis/base.rb, line 120 def error(*args) add_message(:error, *args) end
Adds a regular informational message to the report.
@see add_message
# File lib/ruby-lint/analysis/base.rb, line 138 def info(*args) add_message(:info, *args) end
@return [RubyLint::Definition::RubyObject]
# File lib/ruby-lint/analysis/base.rb, line 90 def previous_scope return @scopes[-2] end
Sets the current scope to the definition associated with the given node.
@param [RubyLint::Node] node
# File lib/ruby-lint/analysis/base.rb, line 100 def set_current_scope(node) unless vm.associations.key?(node) raise ArgumentError, "No associations for node #{node}" end @scopes << vm.associations[node] end
Sets the current scope back to the previous one.
# File lib/ruby-lint/analysis/base.rb, line 111 def set_previous_scope @scopes.pop end
Adds a warning message to the report.
@see add_message
# File lib/ruby-lint/analysis/base.rb, line 129 def warning(*args) add_message(:warning, *args) end