Class: Nitpick::Nitpicker

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/nitpick/nitpicker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, meth) ⇒ Nitpicker

Returns a new instance of Nitpicker.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/nitpick/nitpicker.rb', line 5

def initialize(klass, meth)
  super()
  self.auto_shift_type = true
  self.strict = false
  self.expected = Sexp
  
  @unsupported.delete(:cfunc)
  @class = klass
  @method = meth
  @warnings = []
end

Instance Attribute Details

#warningsObject

Returns the value of attribute warnings.



3
4
5
# File 'lib/nitpick/nitpicker.rb', line 3

def warnings
  @warnings
end

Instance Method Details

#nitpick!Object



17
18
19
# File 'lib/nitpick/nitpicker.rb', line 17

def nitpick!
  process(ParseTree.translate(@class, @method))
end

#process_cfunc(exp) ⇒ Object



44
# File 'lib/nitpick/nitpicker.rb', line 44

def process_cfunc(exp); exp.clear; s(); end

#process_defn(exp) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/nitpick/nitpicker.rb', line 33

def process_defn(exp)
  method = exp.shift
  result = s(:defn, method)
  
  until exp.empty?
    result << process(exp.shift)
  end

  result
end

#scan_for(warning_classes, options = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/nitpick/nitpicker.rb', line 21

def scan_for(warning_classes, options = {})
  matched_warnings = warning_classes.map do |warning_class|
    warning_class.discover(options[:with])
  end
  
  warn(*matched_warnings)
end

#warn(*warnings) ⇒ Object



29
30
31
# File 'lib/nitpick/nitpicker.rb', line 29

def warn(*warnings)
  @warnings += warnings.compact
end