execjslint 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -5
- data/lib/jslint/testtask.rb +61 -0
- data/lib/jslint.rb +6 -4
- metadata +20 -8
data/README.md
CHANGED
@@ -3,17 +3,24 @@ ExecJSLint
|
|
3
3
|
|
4
4
|
ExecJSLint is a thin Ruby wrapper that uses ExecJS to execute [Douglas Crockford's JSLint][jslint].
|
5
5
|
|
6
|
+
Install
|
7
|
+
-------
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install execjslint
|
11
|
+
```
|
12
|
+
|
6
13
|
Usage
|
7
14
|
-----
|
8
15
|
|
9
16
|
```ruby
|
10
17
|
js = File.open('path/to/my.js')
|
11
|
-
results =
|
12
|
-
if result.
|
13
|
-
puts "You suck at JavaScript!"
|
14
|
-
puts results.problems
|
15
|
-
else
|
18
|
+
results = JSLint.run(js)
|
19
|
+
if result.valid?
|
16
20
|
puts "GREAT SUCCESS!"
|
21
|
+
else
|
22
|
+
puts "You suck at JavaScript!"
|
23
|
+
puts result.errors
|
17
24
|
end
|
18
25
|
```
|
19
26
|
|
@@ -75,6 +82,13 @@ you may want to try one of these projects:
|
|
75
82
|
|
76
83
|
* [rondevera/jslintmate][jslintmate] - TextMate plugin for running JSLint. Uses JSC.
|
77
84
|
|
85
|
+
Why
|
86
|
+
---
|
87
|
+
|
88
|
+
Why another JSLint wrapper?
|
89
|
+
|
90
|
+
![you need a java runtime](http://mintdigital.github.com/execjslint/java.png)
|
91
|
+
|
78
92
|
[jslint]: <http://jslint.com/>
|
79
93
|
[rake]: <https://github.com/mintdigital/jslint/blob/master/examples/jslint.rake>
|
80
94
|
[execjs-runtimes]: <https://github.com/sstephenson/execjs/blob/master/README.md>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'jslint'
|
3
|
+
|
4
|
+
module JSLint
|
5
|
+
class TestTask
|
6
|
+
include Rake::DSL
|
7
|
+
|
8
|
+
# Public: Gets/Sets the Array of JavaScript filenames as Strings, each of
|
9
|
+
# which will be run through JSLINT. (default: Dir['**/*.js'])
|
10
|
+
attr_accessor :file_list
|
11
|
+
|
12
|
+
# Public: Gets/Sets the Hash of options that will be passed to each call
|
13
|
+
# of JSLINT. See http://www.jslint.com/lint.html for allowed options.
|
14
|
+
# (default: {})
|
15
|
+
attr_accessor :options
|
16
|
+
|
17
|
+
# Public: Define a new Rake task that runs JSLint tests over several
|
18
|
+
# JavaScript files.
|
19
|
+
#
|
20
|
+
# name - the name of the defined Rake Task. (default: 'jslint')
|
21
|
+
#
|
22
|
+
# Yields itself for configuration if a block is given.
|
23
|
+
def initialize(name=:jslint)
|
24
|
+
@name = name
|
25
|
+
@file_list = Dir['**/*.js']
|
26
|
+
@options = {}
|
27
|
+
yield self if block_given?
|
28
|
+
|
29
|
+
define_task
|
30
|
+
end
|
31
|
+
|
32
|
+
# Internal: Define the actual Rake task.
|
33
|
+
def define_task
|
34
|
+
desc "Run #{@name == :jslint ? '' : @name} JSLint tests"
|
35
|
+
task @name do
|
36
|
+
t0 = Time.now
|
37
|
+
errors = []
|
38
|
+
|
39
|
+
@file_list.each do |f|
|
40
|
+
result = JSLint.run(File.open(f), @options)
|
41
|
+
if result.valid?
|
42
|
+
print '.'
|
43
|
+
else
|
44
|
+
errors << result.error_messages.map {|e| "#{f}:#{e}"}
|
45
|
+
print 'F'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
puts
|
50
|
+
puts
|
51
|
+
if errors.any?
|
52
|
+
puts *errors
|
53
|
+
puts
|
54
|
+
end
|
55
|
+
puts "Finished in %.5f seconds" % [Time.now.to_f - t0.to_f]
|
56
|
+
puts "%d files, %d errors" % [@file_list.length, errors.length]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/jslint.rb
CHANGED
@@ -8,17 +8,19 @@ module JSLint
|
|
8
8
|
# return value and the JSLINT.errors object.
|
9
9
|
def self.context
|
10
10
|
ExecJS.compile(
|
11
|
-
JSLint::Source.contents +
|
12
|
-
"function JSLINTR(source) {
|
11
|
+
JSLint::Source.contents +
|
12
|
+
"function JSLINTR(source, options) { " +
|
13
|
+
"return [JSLINT(source, options),JSLINT.errors]; };"
|
13
14
|
)
|
14
15
|
end
|
15
16
|
|
16
17
|
# Public: Run JSLint over some JavaScript source.
|
17
18
|
#
|
18
19
|
# source - some String-like or IO-like JavaScript source.
|
19
|
-
|
20
|
+
# options - Hash of options passed directly to JSLINT (default: {})
|
21
|
+
def self.run(source, options={})
|
20
22
|
source = source.respond_to?(:read) ? source.read : source
|
21
|
-
Result.new(*context.call("JSLINTR", source))
|
23
|
+
Result.new(*context.call("JSLINTR", source, options))
|
22
24
|
end
|
23
25
|
|
24
26
|
class Result
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjslint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70340978638460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70340978638460
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: jslint-source
|
16
|
-
requirement: &
|
27
|
+
requirement: &70340978637720 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :runtime
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *70340978637720
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: execjs
|
27
|
-
requirement: &
|
38
|
+
requirement: &70340978637220 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :runtime
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70340978637220
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rspec
|
38
|
-
requirement: &
|
49
|
+
requirement: &70340978636620 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70340978636620
|
47
58
|
description: ! ' A bridge to run JSLint from Ruby via ExecJS.
|
48
59
|
|
49
60
|
'
|
@@ -54,6 +65,7 @@ extra_rdoc_files: []
|
|
54
65
|
files:
|
55
66
|
- lib/execjslint.rb
|
56
67
|
- lib/jslint.rb
|
68
|
+
- lib/jslint/testtask.rb
|
57
69
|
- LICENSE
|
58
70
|
- README.md
|
59
71
|
homepage: http://github.com/mintdigital/execjslint
|