Class: JSLint::TestTask
- Inherits:
-
Object
- Object
- JSLint::TestTask
- Includes:
- Rake::DSL
- Defined in:
- lib/jslint/testtask.rb
Instance Attribute Summary collapse
-
#file_list ⇒ Object
Public: Gets/Sets the Array of JavaScript filenames as Strings, each of which will be run through JSLINT.
-
#options ⇒ Object
Public: Gets/Sets the Hash of options that will be passed to each call of JSLINT.
Instance Method Summary collapse
-
#define_task ⇒ Object
Internal: Define the actual Rake task.
-
#initialize(name = :jslint) {|_self| ... } ⇒ TestTask
constructor
Public: Define a new Rake task that runs JSLint tests over several JavaScript files.
Constructor Details
#initialize(name = :jslint) {|_self| ... } ⇒ TestTask
Public: Define a new Rake task that runs JSLint tests over several JavaScript files.
name - the name of the defined Rake Task. (default: ‘jslint’)
Yields itself for configuration if a block is given.
23 24 25 26 27 28 29 30 |
# File 'lib/jslint/testtask.rb', line 23 def initialize(name=:jslint) @name = name @file_list = Dir['**/*.js'] @options = {} yield self if block_given? define_task end |
Instance Attribute Details
#file_list ⇒ Object
Public: Gets/Sets the Array of JavaScript filenames as Strings, each of which will be run through JSLINT. (default: Dir[‘*/.js’])
10 11 12 |
# File 'lib/jslint/testtask.rb', line 10 def file_list @file_list end |
#options ⇒ Object
Public: Gets/Sets the Hash of options that will be passed to each call of JSLINT. See www.jslint.com/lint.html for allowed options. (default: {})
15 16 17 |
# File 'lib/jslint/testtask.rb', line 15 def @options end |
Instance Method Details
#define_task ⇒ Object
Internal: Define the actual Rake task.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jslint/testtask.rb', line 33 def define_task desc "Run #{@name == :jslint ? '' : @name.to_s + ' '}JSLint tests" task @name do t0 = Time.now errors = [] @file_list.each do |f| result = JSLint.run(File.open(f), @options) if result.valid? print '.' else errors << result..map {|e| "#{f}:#{e}"} print 'F' end end puts puts if errors.any? puts *errors puts end puts "Finished in %.5f seconds" % [Time.now.to_f - t0.to_f] puts "%d files, %d errors" % [@file_list.length, errors.length] abort if errors.any? end end |