jslint_on_rails 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ Version 1.0.6 (19.02.2011)
2
+
3
+ * escape $ in predef line to prevent Bash for interpreting it
4
+ * predef can be passed as a YAML array
5
+
1
6
  Version 1.0.5 (08.01.2011)
2
7
 
3
8
  * options passed on the command line to JSLint are joined with "&" to fix the "predef" option
@@ -51,7 +51,7 @@ indent: 2 # Number of spaces that should be used for indentation - use
51
51
  maxerr: 50 # The maximum number of warnings reported (per file)
52
52
  passfail: false # true if the scan should stop on first error (per file)
53
53
  # following are relevant only if undef = true
54
- predef: '' # Names of predefined global variables - comma-separated string
54
+ predef: '' # Names of predefined global variables - comma-separated string or a YAML array
55
55
  browser: true # true if the standard browser globals should be predefined
56
56
  rhino: false # true if the Rhino environment globals should be predefined
57
57
  windows: false # true if Windows-specific globals should be predefined
@@ -23,6 +23,10 @@ module JSLint
23
23
  custom_config = Utils.load_config_file(options[:config_path] || JSLint.config_path)
24
24
  @config = default_config.merge(custom_config)
25
25
 
26
+ if @config['predef'].is_a?(Array)
27
+ @config['predef'] = @config['predef'].join(",")
28
+ end
29
+
26
30
  included_files = files_matching_paths(options, :paths)
27
31
  excluded_files = files_matching_paths(options, :exclude_paths)
28
32
  @file_list = Utils.exclude_files(included_files, excluded_files)
@@ -34,7 +38,7 @@ module JSLint
34
38
  def run
35
39
  check_java
36
40
  Utils.xputs "Running JSLint:\n\n"
37
- arguments = "#{JSLINT_FILE} #{option_string.inspect} #{@file_list.join(' ')}"
41
+ arguments = "#{JSLINT_FILE} #{option_string.inspect.gsub(/\$/, "\\$")} #{@file_list.join(' ')}"
38
42
  success = call_java_with_status(RHINO_JAR_FILE, RHINO_JAR_CLASS, arguments)
39
43
  raise LintCheckFailure, "JSLint test failed." unless success
40
44
  end
@@ -3,7 +3,7 @@ require 'yaml'
3
3
 
4
4
  module JSLint
5
5
 
6
- VERSION = "1.0.5"
6
+ VERSION = "1.0.6"
7
7
  DEFAULT_CONFIG_FILE = File.expand_path(File.dirname(__FILE__) + "/config/jslint.yml")
8
8
 
9
9
  class << self
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe JSLint::Lint do
4
4
 
5
+ JSLint::Lint.class_eval do
6
+ attr_reader :config, :file_list
7
+ end
8
+
5
9
  before :all do
6
10
  File.open(JSLint::DEFAULT_CONFIG_FILE, "w") { |f| f.write "color: red\nsize: 5\nshape: circle\n" }
7
11
  File.open("custom_config.yml", "w") { |f| f.write "color: blue\nsize: 7\nborder: 2\n" }
@@ -13,20 +17,28 @@ describe JSLint::Lint do
13
17
  lint.should_receive(:call_java_with_output).once.and_return("OK")
14
18
  end
15
19
 
16
- def file_list(lint)
17
- lint.instance_variable_get("@file_list")
18
- end
19
-
20
20
  it "should merge default config with custom config from JSLint.config_path" do
21
21
  lint = JSLint::Lint.new
22
- config = lint.instance_variable_get("@config")
23
- config.should == { 'color' => 'blue', 'size' => 7, 'border' => 2, 'shape' => 'circle' }
22
+ lint.config.should == { 'color' => 'blue', 'size' => 7, 'border' => 2, 'shape' => 'circle' }
24
23
  end
25
24
 
26
25
  it "should merge default config with custom config given in argument, if available" do
27
26
  lint = JSLint::Lint.new :config_path => 'other_config.yml'
28
- config = lint.instance_variable_get("@config")
29
- config.should == { 'color' => 'green', 'border' => 0, 'shape' => 'square', 'size' => 5 }
27
+ lint.config.should == { 'color' => 'green', 'border' => 0, 'shape' => 'square', 'size' => 5 }
28
+ end
29
+
30
+ it "should convert predef to string if it's an array" do
31
+ File.open("predef.yml", "w") { |f| f.write "predef:\n - a\n - b\n - c" }
32
+
33
+ lint = JSLint::Lint.new :config_path => 'predef.yml'
34
+ lint.config['predef'].should == "a,b,c"
35
+ end
36
+
37
+ it "should accept predef as string" do
38
+ File.open("predef.yml", "w") { |f| f.write "predef: d,e,f" }
39
+
40
+ lint = JSLint::Lint.new :config_path => 'predef.yml'
41
+ lint.config['predef'].should == "d,e,f"
30
42
  end
31
43
 
32
44
  it "should not pass paths and exclude_paths options to real JSLint" do
@@ -34,10 +46,9 @@ describe JSLint::Lint do
34
46
  f.write(YAML.dump({ 'paths' => ['a', 'b'], 'exclude_paths' => ['c'], 'debug' => 'true' }))
35
47
  end
36
48
  lint = JSLint::Lint.new :config_path => 'test.yml'
37
- config = lint.instance_variable_get("@config")
38
- config['debug'].should == 'true'
39
- config['paths'].should be_nil
40
- config['exclude_paths'].should be_nil
49
+ lint.config['debug'].should == 'true'
50
+ lint.config['paths'].should be_nil
51
+ lint.config['exclude_paths'].should be_nil
41
52
  end
42
53
 
43
54
  it "should fail if Java isn't available" do
@@ -86,6 +97,19 @@ describe JSLint::Lint do
86
97
  eval(option_string).split('&').sort.should == ['debug=true', 'linelength=120', 'semicolons=false']
87
98
  end
88
99
 
100
+ it "should escape $ in option string when passing it to Java/JSLint" do
101
+ lint = JSLint::Lint.new
102
+ lint.instance_variable_set("@config", { 'predef' => 'window,$,Ajax,$app,Request' })
103
+ setup_java(lint)
104
+ param_string = ""
105
+ lint.
106
+ should_receive(:call_java_with_status).
107
+ once.
108
+ with(an_instance_of(String), an_instance_of(String), /window,\\\$,Ajax,\\\$app,Request/).
109
+ and_return(true)
110
+ lint.run
111
+ end
112
+
89
113
  it "should pass space-separated list of files to JSLint" do
90
114
  lint = JSLint::Lint.new
91
115
  lint.instance_variable_set("@file_list", ['app.js', 'test.js', 'jquery.js'])
@@ -112,33 +136,33 @@ describe JSLint::Lint do
112
136
 
113
137
  it "should calculate a list of files to test" do
114
138
  lint = JSLint::Lint.new :paths => ['test/**/*.js']
115
- file_list(lint).should == @files
139
+ lint.file_list.should == @files
116
140
 
117
141
  lint = JSLint::Lint.new :paths => ['test/a*.js', 'test/**/*r*.js']
118
- file_list(lint).should == [@files[0], @files[3], @files[4]]
142
+ lint.file_list.should == [@files[0], @files[3], @files[4]]
119
143
 
120
144
  lint = JSLint::Lint.new :paths => ['test/a*.js', 'test/**/*r*.js'], :exclude_paths => ['**/*q*.js']
121
- file_list(lint).should == [@files[0], @files[4]]
145
+ lint.file_list.should == [@files[0], @files[4]]
122
146
 
123
147
  lint = JSLint::Lint.new :paths => ['test/**/*.js'], :exclude_paths => ['**/*.js']
124
- file_list(lint).should == []
148
+ lint.file_list.should == []
125
149
 
126
150
  lint = JSLint::Lint.new :paths => ['test/**/*.js', 'test/**/a*.js', 'test/**/p*.js']
127
- file_list(lint).should == @files
151
+ lint.file_list.should == @files
128
152
 
129
153
  File.open("new.yml", "w") { |f| f.write(YAML.dump({ 'paths' => ['test/vendor/*.js'] })) }
130
154
 
131
155
  lint = JSLint::Lint.new :config_path => 'new.yml', :exclude_paths => ['**/proto.js']
132
- file_list(lint).should == [@files[3]]
156
+ lint.file_list.should == [@files[3]]
133
157
 
134
158
  lint = JSLint::Lint.new :config_path => 'new.yml', :paths => ['test/l*.js']
135
- file_list(lint).should == [@files[1]]
159
+ lint.file_list.should == [@files[1]]
136
160
  end
137
161
 
138
162
  it "should accept :paths and :exclude_paths as string instead of one-element array" do
139
163
  lambda do
140
164
  lint = JSLint::Lint.new :paths => 'test/*.js', :exclude_paths => 'test/lib.js'
141
- file_list(lint).should == [@files[0], @files[2]]
165
+ lint.file_list.should == [@files[0], @files[2]]
142
166
  end.should_not raise_error
143
167
  end
144
168
 
@@ -147,8 +171,8 @@ describe JSLint::Lint do
147
171
  File.open("test/full.js", "w") { |f| f.write("qqq") }
148
172
 
149
173
  lint = JSLint::Lint.new :paths => ['test/*.js']
150
- file_list(lint).should_not include(File.expand_path("test/empty.js"))
151
- file_list(lint).should include(File.expand_path("test/full.js"))
174
+ lint.file_list.should_not include(File.expand_path("test/empty.js"))
175
+ lint.file_list.should include(File.expand_path("test/full.js"))
152
176
  end
153
177
  end
154
178
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jslint_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jakub Suder
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-08 00:00:00 +01:00
18
+ date: 2011-02-19 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21