Class: Simplabs::Excellent::Checks::Base
- Inherits:
-
Object
- Object
- Simplabs::Excellent::Checks::Base
- Defined in:
- lib/simplabs/excellent/checks/base.rb
Overview
This is the base class for all code checks. All checks must specify interesting_nodes. When one of these nodes is processed by Excellent, it will invoke the evaluate_node method of all checks that specify the node as one if their interesting_nodes.
Direct Known Subclasses
AbcMetricMethodCheck, AssignmentInConditionalCheck, CaseMissingElseCheck, ControlCouplingCheck, CyclomaticComplexityCheck, EmptyRescueBodyCheck, FlogCheck, ForLoopCheck, GlobalVariableCheck, LineCountCheck, NameCheck, NestedIteratorsCheck, ParameterNumberCheck, Rails::AttrAccessibleCheck, Rails::AttrProtectedCheck, Rails::CustomInitializeMethodCheck, Rails::InstanceVarInPartialCheck, Rails::ParamsHashInViewCheck, Rails::SessionHashInViewCheck, Rails::ValidationsCheck, SingletonVariableCheck
Instance Attribute Summary collapse
-
#interesting_files ⇒ Object
readonly
An array of regular expressions for file names that are interesting for the check.
-
#interesting_nodes ⇒ Object
readonly
An array of node types that are interesting for the check.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#add_warning(context, message, info = {}, offset = 0) ⇒ Object
Adds a warning.
-
#evaluate_node(context) ⇒ Object
This method is called whenever Excellent processes a node that the check specified as one of the nodes it is interested in (see interesting_nodes).
-
#initialize ⇒ Base
constructor
:nodoc:.
-
#warnings_for(filename) ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ Base
:nodoc:
25 26 27 28 |
# File 'lib/simplabs/excellent/checks/base.rb', line 25 def initialize #:nodoc: @warnings = [] @interesting_files = [/\.rb$/] end |
Instance Attribute Details
#interesting_files ⇒ Object (readonly)
An array of regular expressions for file names that are interesting for the check. These will usually be path extensions rather than longer patterns (e.g. *.rb as well as *.erb files or *.rb files only).
Defaults to /.rb$/. If you do not specify anything else in custom checks, only *.rb files will be processed
23 24 25 |
# File 'lib/simplabs/excellent/checks/base.rb', line 23 def interesting_files @interesting_files end |
#interesting_nodes ⇒ Object (readonly)
An array of node types that are interesting for the check. These are symbols as returned by RubyParser (see parsetree.rubyforge.org/ruby_parser/), e.g. :if or :defn
17 18 19 |
# File 'lib/simplabs/excellent/checks/base.rb', line 17 def interesting_nodes @interesting_nodes end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
13 14 15 |
# File 'lib/simplabs/excellent/checks/base.rb', line 13 def warnings @warnings end |
Instance Method Details
#add_warning(context, message, info = {}, offset = 0) ⇒ Object
Adds a warning
Parameters
-
context- The context the check has been executed on. -
message- The warning message. -
info- The information hash that contains more info on the finding. -
offset- The line offset that is added to the context’s line property.
47 48 49 50 |
# File 'lib/simplabs/excellent/checks/base.rb', line 47 def add_warning(context, , info = {}, offset = 0) klass = self.class @warnings << Simplabs::Excellent::Warning.new(klass, , context.file, context.line + offset, info) end |
#evaluate_node(context) ⇒ Object
This method is called whenever Excellent processes a node that the check specified as one of the nodes it is interested in (see interesting_nodes).
Parameters
-
context- This is the last context the code processor has constructed. It contains all information required to execute the check (see Simplabs::Excellent::Parsing::SexpContext).
35 36 37 |
# File 'lib/simplabs/excellent/checks/base.rb', line 35 def evaluate_node(context) evaluate(context) end |
#warnings_for(filename) ⇒ Object
:nodoc:
52 53 54 |
# File 'lib/simplabs/excellent/checks/base.rb', line 52 def warnings_for(filename) #:nodoc: warnings.select { |warning| warning.filename == filename } end |