jslintrb 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ === 0.4.0 / 2010-03-16
2
+
3
+ * First Hoe version
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG.rdoc
2
+ LICENSE
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/jslintrb
7
+ lib/jslintrb.rb
8
+ lib/jslintrb/fulljslint.js
9
+ lib/jslintrb/jslintrb.js
10
+ lib/jslintrb/jslintrb.wk
11
+ lib/jslintrb/options.rb
data/README.rdoc CHANGED
@@ -1,7 +1,11 @@
1
1
  = jslintrb
2
2
 
3
- jslintrb is a packaged version of Douglas Crockford's JSLint
4
- JavaScript code checker. jslintrb uses SpiderMonkey via the Johnson
3
+ * http://github.com/smparkes/jslintrb
4
+
5
+ == Description
6
+
7
+ jslintrb is a packaged version of Douglas Crockford's JSLint JavaScript code checker.
8
+ jslintrb uses SpiderMonkey via the Johnson
5
9
  Ruby gem to interpret the JSLint javascript.
6
10
 
7
11
  == Usage
@@ -17,16 +21,11 @@ top-level project directory that sets options for my project, then one
17
21
  in my spec directory (like a test directory) which adds the globals
18
22
  that exist for the tests but not for the core application code.
19
23
 
20
- The file is JSON-formatted. See the
21
- jslint documentation (http://www.jslint.com/lint.html) for allowed
22
- options.
23
-
24
- jslintrb adds support for JavaScript with statements. They are parsed
25
- but produce a warning. The "withstmt" option will suppress that
26
- warning. Note that this does not endorse the use of with statements.
24
+ The file is JSON-formatted. See the jslint documentation
25
+ (http://www.jslint.com/lint.html#options) for allowed options and an
26
+ example at http://github.com/smparkes/env-js/blob/envjsrb/.jslintrbrc.
27
27
 
28
28
  == Copyright
29
29
 
30
30
  jslintrb copyright (c) 2010 Steven Parkes. See LICENSE for details.
31
31
  jslint copyright (c) 2002 Douglas Crockford. See lib/jslintrb/fulljslint.js for details.
32
- json2 is in the public domain. See lib/jslintrb/json2.js for details.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :debugging, :doofus, :git
7
+ Hoe.plugins.delete :rubyforge
8
+
9
+ Hoe.spec 'jslintrb' do
10
+
11
+ developer 'Steven Parkes', 'smparkes@smparkes.net'
12
+
13
+ self.history_file = "CHANGELOG.rdoc"
14
+ self.readme_file = "README.rdoc"
15
+
16
+ extra_deps << ["johnson", ">= 2.0.0.pre0"]
17
+
18
+ end
data/bin/jslintrb CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $VERBOSE = true
4
3
 
5
4
  require 'jslintrb/options'
@@ -13,7 +12,6 @@ args = [ "env",
13
12
  "JOHNSON_RUNTIME=tracemonkey",
14
13
  "johnson",
15
14
  File.join(JSLINT_DIR,"fulljslint.js"),
16
- File.join(JSLINT_DIR,"json2.js"),
17
15
  File.join(JSLINT_DIR,"jslintrb.js") ]
18
16
 
19
17
  cmd = args.join(" ")
@@ -23,219 +21,3 @@ puts cmd if $jslintrb_verbose
23
21
  if !system cmd
24
22
  exit $?.exitstatus
25
23
  end
26
-
27
- exit
28
-
29
- intro = File.join(JSLINT_DIR, "intro.js")
30
- outro = File.join(JSLINT_DIR, "outro.js")
31
-
32
- args << intro
33
-
34
- introd = true
35
- outrod = true
36
-
37
- ARGV.each do |f|
38
-
39
- if f =~ /\.x?html?$/ || f =~ %r(^https?://)
40
- if introd && !outrod
41
- args << outro
42
- args << "about:blank"
43
- outrod = true
44
- introd = false
45
- end
46
- if !introd
47
- args << intro
48
- end
49
- args << f
50
- introd = true
51
- outrod = false
52
- elsif f == "about:blank"
53
- if introd && !outrod
54
- args << outro
55
- outrod = true
56
- introd = false
57
- end
58
- args << f
59
- else
60
- args << f
61
- end
62
-
63
- end
64
-
65
- args << outro
66
-
67
- cmd = args.join(" ")
68
-
69
- puts cmd if $jslintrb_verbose
70
-
71
- require 'eventmachine'
72
- require 'nokogiri'
73
-
74
- class Restart < Exception; end
75
-
76
- def colour(text, colour_code)
77
- # return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?))
78
- "#{colour_code}#{text}\e[0m"
79
- end
80
-
81
- def green(text); colour(text, "\e[32m"); end
82
- def red(text); colour(text, "\e[31m"); end
83
- def yellow(text); colour(text, "\e[33m"); end
84
- def blue(text); colour(text, "\e[34m"); end
85
-
86
- $spec_info = {}
87
- $spec_info[:specs] = []
88
- $spec_info[:failures] = []
89
- $spec_info[:pending] = []
90
-
91
- class SAX < Nokogiri::XML::SAX::Document
92
-
93
- def start_element name, attrs
94
- # p attrs
95
- attrs = Hash[*attrs]
96
- # p attrs
97
- case name
98
- when "testsuites";
99
- when "testsuite";
100
- @testsuite_name = attrs["name"]
101
- if @testsuite_pending = ( attrs["skipped"] == "true" )
102
- $spec_info[:specs] << (tc = {})
103
- tc[:name] = @testsuite_name
104
- $spec_info[:pending] << $spec_info[:specs].last
105
- end
106
- when "testcase";
107
- $spec_info[:specs] << (tc = {})
108
- tc[:name] = @testsuite_name + " : " + attrs["name"]
109
- @testcase_failed = false
110
- when "failure";
111
- $spec_info[:failures] << (tc = $spec_info[:specs].last)
112
- tc[:message] = attrs["message"]
113
- @testcase_failed = true
114
- else; raise "hell: #{name}"
115
- end
116
- end
117
-
118
- def cdata_block string
119
- if @testcase_failed
120
- $spec_info[:failures].last[:stack] ||= ""
121
- $spec_info[:failures].last[:stack] << string
122
- end
123
- end
124
-
125
- def end_element name
126
- case name
127
- when "testsuites";
128
- raise Restart
129
- when "testsuite";
130
- if !$jslintrb_xml
131
- if @testsuite_pending
132
- char = yellow("*")
133
- print char
134
- $stdout.flush
135
- end
136
- end
137
- when "testcase";
138
- if !$jslintrb_xml
139
- char = nil
140
- if @testcase_failed
141
- char = red("F")
142
- else
143
- char = green(".")
144
- end
145
- print char
146
- $stdout.flush
147
- end
148
- when "failure";
149
- else; raise "hell: #{name}"
150
- end
151
- end
152
- end
153
-
154
- $failed_processes = 0
155
-
156
- module WriteToNokogiri
157
- def post_init
158
- @parser = Nokogiri::XML::SAX::PushParser.new( SAX.new )
159
- end
160
- def receive_data data
161
- begin
162
- if $jslintrb_xml
163
- # $stderr.print data
164
- puts data
165
- $stdout.flush
166
- end
167
- @parser << data
168
- rescue Restart
169
- @parser = Nokogiri::XML::SAX::PushParser.new( SAX.new )
170
- rescue Exception => e
171
- $stderr.puts "Parser raised #{e} on #{data}"
172
- exit 1
173
- end
174
- end
175
- def unbind
176
- $failed_processes += 1 if get_status.exitstatus &&
177
- get_status.exitstatus > 0
178
- EM.stop
179
- end
180
- end
181
-
182
- date = Time.now
183
- failures = nil
184
- examples = nil
185
- pending = nil
186
-
187
- EM.run do
188
- EM.popen cmd, WriteToNokogiri
189
- end
190
-
191
- puts
192
- puts
193
-
194
- if !$jslintrb_xml
195
- if $spec_info[:pending].length > 0
196
- puts "Pending:"
197
- $spec_info[:pending].each do |pending|
198
- puts
199
- puts yellow(pending[:name])
200
- end
201
- puts "\n"
202
- end
203
- $spec_info[:failures].each_with_index do |failure,i|
204
- print i+1,")\n"
205
- print red("#{failure[:name]} FAILED\n")
206
- print red(failure[:message]),"\n"
207
- # double check, but is there really anything in the jslint stack that's useful?
208
- stack = failure[:stack]
209
- stack and ( stack = stack.split "\n" )
210
- stack and stack.each do |line|
211
- if line =~ %r(/jasmine.js:\d+) || line =~ %r(/jasmine/src/.*\.js:\d+)
212
- break
213
- end
214
- print line, "\n"
215
- end
216
- # p stack
217
- # print failure[:stack],"\n"
218
- end
219
- puts "Finished in #{Time.now - date} seconds"
220
- puts
221
- examples = $spec_info[:specs].length
222
- # require 'pp'
223
- # pp $spec_info[:specs]
224
- failures = $spec_info[:failures].length
225
- pending = $spec_info[:pending].length
226
- if $failed_processes > 0
227
- examples += $failed_processes
228
- failures += $failed_processes
229
- end
230
- msg = "#{examples} examples, #{failures} failures, #{pending} pending"
231
- if failures > 0
232
- msg = red(msg)
233
- elsif pending > 0
234
- msg = yellow(msg)
235
- else
236
- msg = green(msg)
237
- end
238
- puts msg
239
- end
240
-
241
- exit ( !failures.nil? && failures > 0 ) ? 1 : 0