Class: JslintRb::Formatter
- Inherits:
-
Object
- Object
- JslintRb::Formatter
- Defined in:
- lib/jslint-rb/formatter.rb
Overview
Formatters are used to parse the output from Lint and transform it for use with other programs (or simply to customize the output)
Constant Summary collapse
- VIM =
Formatter for use with VIM’s :make command. Set your errorformat for JS files to ‘%f:%l:%c:%m’ and it will work flawlessly with :cope
Proc.new do |errors, filename| results = [] errors.each do |error| fmt_err = "#{filename}:#{error.line_number}:"\ "#{error.character}:#{error.reason}" results << fmt_err end results end
- MULTI_LINE =
Multiline output suitible for a terminal window
Proc.new do |errors, filename| results = [] #header results << "#########################################" results << "# Lint output for: #{filename}" results << "#########################################" errors.each do |error| results << "Error occured on line #{error.line_number} at col #{error.character}:" results << " #{error.reason}" results << "EVIDENCE: #{error.evidence}" unless error.evidence.nil? results << "\n" end results end
Instance Method Summary collapse
-
#initialize(formatter) ⇒ Formatter
constructor
Uses MULTI_LINE as a default.
-
#print(errors, filename) ⇒ Object
Put the formatted JSHINT results to STDOUT.
Constructor Details
#initialize(formatter) ⇒ Formatter
Uses MULTI_LINE as a default
43 44 45 46 |
# File 'lib/jslint-rb/formatter.rb', line 43 def initialize(formatter) formatter = JslintRb::Formatter::MULTI_LINE if formatter.nil? @command = formatter end |
Instance Method Details
#print(errors, filename) ⇒ Object
Put the formatted JSHINT results to STDOUT
50 51 52 53 |
# File 'lib/jslint-rb/formatter.rb', line 50 def print(errors, filename) output = @command.call(errors, filename) puts output end |