Class: Codeqa::Checkers::CheckYard

Inherits:
Codeqa::Checker show all
Defined in:
lib/codeqa/checkers/check_yard.rb

Instance Attribute Summary

Attributes inherited from Codeqa::Checker

#errors, #sourcefile

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Codeqa::Checker

#initialize

Constructor Details

This class inherits a constructor from Codeqa::Checker

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/codeqa/checkers/check_yard.rb', line 9

def self.available?
  yard?
end

.check?(sourcefile) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/codeqa/checkers/check_yard.rb', line 6

def self.check?(sourcefile)
  sourcefile.ruby? && !(sourcefile.filename =~ /^(test|spec)/)
end

.ioObject



13
14
15
# File 'lib/codeqa/checkers/check_yard.rb', line 13

def self.io
  @@io ||= StringIO.new
end

Instance Method Details

#checkObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/codeqa/checkers/check_yard.rb', line 25

def check
  if self.class.yard?
    ::YARD.parse_string(sourcefile.content) # let yard parse the file content
    io.rewind # rewind the io
    message = io.read
    warnings = message.match(/\A\[warn\]: /)
    errors.add(nil, message.gsub(/\(stdin\)/, sourcefile.filename)) if warnings
  end
ensure
  io.reopen # clear the message for the next file
end

#hintObject



21
22
23
# File 'lib/codeqa/checkers/check_yard.rb', line 21

def hint
  'Yard gives us some warnings on the file you can run <yardoc filename> to check yourself.'
end

#nameObject



17
18
19
# File 'lib/codeqa/checkers/check_yard.rb', line 17

def name
  'yard'
end