Class: Simplabs::Excellent::Checks::NameCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/name_check.rb

Overview

:nodoc:

Direct Known Subclasses

ClassNameCheck, MethodNameCheck, ModuleNameCheck

Instance Attribute Summary

Attributes inherited from Base

#interesting_contexts, #interesting_files, #options, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_context, #warnings_for

Constructor Details

#initialize(interesting_contexts, options = {}) ⇒ NameCheck

:nodoc:



11
12
13
14
15
16
# File 'lib/simplabs/excellent/checks/name_check.rb', line 11

def initialize(interesting_contexts, options = {}) #:nodoc:
  super(options)
  @interesting_contexts = interesting_contexts
  @pattern              = Regexp.new(options[:pattern].to_s)
  @whitelist            = Array(options[:whitelist])
end

Instance Method Details

#evaluate(context) ⇒ Object



18
19
20
21
22
23
# File 'lib/simplabs/excellent/checks/name_check.rb', line 18

def evaluate(context)
  name = context.name.to_s
  if !@whitelist.include?(name) && !(name =~ @pattern)
    add_warning(*warning_args(context))
  end
end