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_contexts. When one of these contexts is processed by Excellent, it will invoke the evaluate_context method of all checks that specify the context as one if their interesting_contexts.
Direct Known Subclasses
AbcMetricMethodCheck, AssignmentInConditionalCheck, CaseMissingElseCheck, ClassVariableCheck, ControlCouplingCheck, CyclomaticComplexityCheck, EmptyRescueBodyCheck, FlogCheck, ForLoopCheck, GlobalVariableCheck, LineCountCheck, NameCheck, NestedIteratorsCheck, ParameterNumberCheck, Rails::AttrAccessibleCheck, Rails::AttrProtectedCheck, Rails::CustomInitializeMethodCheck, Rails::InstanceVarInPartialCheck, Rails::ParamsHashInViewCheck, Rails::SessionHashInViewCheck, Rails::ValidationsCheck
Instance Attribute Summary collapse
-
#interesting_contexts ⇒ Object
readonly
An array of contexts that are interesting for the check.
-
#interesting_files ⇒ Object
readonly
An array of regular expressions for file names that are interesting for the check.
-
#options ⇒ Object
readonly
:nodoc:.
-
#warnings ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#add_warning(context, message, info = {}, offset = 0) ⇒ Object
Adds a warning.
-
#evaluate_context(context) ⇒ Object
This method is called whenever Excellent processes a context that the check specified as one of the contexts it is interested in (see interesting_contexts).
-
#initialize(options = {}) ⇒ Base
constructor
:nodoc:.
-
#warnings_for(filename) ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ Base
:nodoc:
28 29 30 31 32 33 |
# File 'lib/simplabs/excellent/checks/base.rb', line 28 def initialize( = {}) #:nodoc: = @interesting_contexts = [] @warnings = [] @interesting_files = [/\.rb$/] end |
Instance Attribute Details
#interesting_contexts ⇒ Object (readonly)
An array of contexts that are interesting for the check. These contexts are based on symbols as returned by RubyParser (see parsetree.rubyforge.org/ruby_parser/) and add some additional data, e.g. Ifcontext or MethodContext
20 21 22 |
# File 'lib/simplabs/excellent/checks/base.rb', line 20 def interesting_contexts @interesting_contexts end |
#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
26 27 28 |
# File 'lib/simplabs/excellent/checks/base.rb', line 26 def interesting_files @interesting_files end |
#options ⇒ Object (readonly)
:nodoc:
15 16 17 |
# File 'lib/simplabs/excellent/checks/base.rb', line 15 def end |
#warnings ⇒ Object (readonly)
:nodoc:
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.
53 54 55 |
# File 'lib/simplabs/excellent/checks/base.rb', line 53 def add_warning(context, , info = {}, offset = 0) @warnings << Simplabs::Excellent::Warning.new(, context.file, context.line + offset, info) end |
#evaluate_context(context) ⇒ Object
This method is called whenever Excellent processes a context that the check specified as one of the contexts it is interested in (see interesting_contexts).
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).
41 42 43 |
# File 'lib/simplabs/excellent/checks/base.rb', line 41 def evaluate_context(context) evaluate(context) end |
#warnings_for(filename) ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/simplabs/excellent/checks/base.rb', line 57 def warnings_for(filename) #:nodoc: warnings.select { |warning| warning.filename == filename } end |