class Simplabs::Excellent::Checks::Base

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.

Attributes

interesting_contexts[R]

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

interesting_files[R]

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

Public Instance Methods

add_warning(context, message, info = {}, offset = 0) click to toggle source

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.

# File lib/simplabs/excellent/checks/base.rb, line 53
def add_warning(context, message, info = {}, offset = 0)
  @warnings << Simplabs::Excellent::Warning.new(message, context.file, context.line + offset, info)
end
evaluate_context(context) click to toggle source

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

# File lib/simplabs/excellent/checks/base.rb, line 41
def evaluate_context(context)
  evaluate(context)
end