jslint_on_rails 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog.markdown +4 -0
- data/lib/jslint/utils.rb +1 -1
- data/lib/jslint/vendor/jslint.js +20 -11
- data/spec/jslint_spec.rb +46 -0
- data/spec/lint_spec.rb +11 -12
- data/spec/railtie_spec.rb +3 -3
- data/spec/spec_helper.rb +23 -0
- data/spec/utils_spec.rb +5 -5
- metadata +5 -4
data/Changelog.markdown
CHANGED
data/lib/jslint/utils.rb
CHANGED
data/lib/jslint/vendor/jslint.js
CHANGED
@@ -5877,19 +5877,28 @@ loop: for (;;) {
|
|
5877
5877
|
var input = readFile(args[f]);
|
5878
5878
|
if (!input) {
|
5879
5879
|
print("Error: couldn't open file.");
|
5880
|
-
} else
|
5881
|
-
|
5882
|
-
|
5883
|
-
|
5884
|
-
|
5885
|
-
if (e) {
|
5886
|
-
print('Lint at line ' + e.line + ' character ' + e.character + ': ' + e.reason);
|
5887
|
-
print((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
|
5888
|
-
print('');
|
5880
|
+
} else {
|
5881
|
+
var optionsCopy = {};
|
5882
|
+
for (var key in options) {
|
5883
|
+
if (options.hasOwnProperty(key)) {
|
5884
|
+
optionsCopy[key] = options[key];
|
5889
5885
|
}
|
5890
5886
|
}
|
5891
|
-
|
5892
|
-
|
5887
|
+
|
5888
|
+
if (!JSLINT(input, optionsCopy)) {
|
5889
|
+
print(pluralize(JSLINT.errors.length, "error") + ":\n");
|
5890
|
+
totalErrors += JSLINT.errors.length;
|
5891
|
+
for (var i = 0; i < JSLINT.errors.length; i += 1) {
|
5892
|
+
var e = JSLINT.errors[i];
|
5893
|
+
if (e) {
|
5894
|
+
print('Lint at line ' + e.line + ' character ' + e.character + ': ' + e.reason);
|
5895
|
+
print((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
|
5896
|
+
print('');
|
5897
|
+
}
|
5898
|
+
}
|
5899
|
+
} else {
|
5900
|
+
print("OK");
|
5901
|
+
}
|
5893
5902
|
}
|
5894
5903
|
}
|
5895
5904
|
|
data/spec/jslint_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'jslint.js' do
|
4
|
+
before :all do
|
5
|
+
File.open(JSLint::DEFAULT_CONFIG_FILE, "w") { |f| f.write "color: red\nsize: 5\nshape: circle\n" }
|
6
|
+
File.open("custom_config.yml", "w") { |f| f.write "color: blue\nsize: 7\nborder: 2\n" }
|
7
|
+
File.open("other_config.yml", "w") { |f| f.write "color: green\nborder: 0\nshape: square" }
|
8
|
+
JSLint.config_path = "custom_config.yml"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "options in comments" do
|
12
|
+
before do
|
13
|
+
FakeFS.deactivate!
|
14
|
+
create_file 'spec-config.yml', 'evil: false'
|
15
|
+
create_file 'first.js', "
|
16
|
+
/*jslint evil: true*/
|
17
|
+
eval('alert(\"muahahahaha\")');
|
18
|
+
"
|
19
|
+
create_file 'second.js', "
|
20
|
+
// I shouldn't be able to do that
|
21
|
+
eval('alert(\"muahahahaha\")');
|
22
|
+
"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not apply local options from one file to all subsequent files" do
|
26
|
+
lint = JSLint::Lint.new(:paths => ["first.js", "second.js"], :config => 'spec-config.yml')
|
27
|
+
|
28
|
+
# silence stdout from jslint
|
29
|
+
lint.instance_eval do
|
30
|
+
def system(command)
|
31
|
+
`#{command}`
|
32
|
+
$? == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
expect { lint.run }.to raise_error(JSLint::LintCheckFailure)
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
File.delete('first.js')
|
41
|
+
File.delete('second.js')
|
42
|
+
File.delete('spec-config.yml')
|
43
|
+
FakeFS.activate!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/lint_spec.rb
CHANGED
@@ -7,9 +7,9 @@ describe JSLint::Lint do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
before :all do
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
create_config 'color' => 'red', 'size' => 5, 'shape' => 'circle'
|
11
|
+
create_file 'custom_config.yml', 'color' => 'blue', 'size' => 7, 'border' => 2
|
12
|
+
create_file 'other_config.yml', 'color' => 'green', 'border' => 0, 'shape' => 'square'
|
13
13
|
JSLint.config_path = "custom_config.yml"
|
14
14
|
end
|
15
15
|
|
@@ -28,23 +28,22 @@ describe JSLint::Lint do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should convert predef to string if it's an array" do
|
31
|
-
|
31
|
+
create_file 'predef.yml', 'predef' => ['a', 'b', 'c']
|
32
32
|
|
33
33
|
lint = JSLint::Lint.new :config_path => 'predef.yml'
|
34
34
|
lint.config['predef'].should == "a,b,c"
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should accept predef as string" do
|
38
|
-
|
38
|
+
create_file 'predef.yml', 'predef' => 'd,e,f'
|
39
39
|
|
40
40
|
lint = JSLint::Lint.new :config_path => 'predef.yml'
|
41
41
|
lint.config['predef'].should == "d,e,f"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not pass paths and exclude_paths options to real JSLint" do
|
45
|
-
|
46
|
-
|
47
|
-
end
|
45
|
+
create_file 'test.yml', 'paths' => ['a', 'b'], 'exclude_paths' => ['c'], 'debug' => 'true'
|
46
|
+
|
48
47
|
lint = JSLint::Lint.new :config_path => 'test.yml'
|
49
48
|
lint.config['debug'].should == 'true'
|
50
49
|
lint.config['paths'].should be_nil
|
@@ -130,7 +129,7 @@ describe JSLint::Lint do
|
|
130
129
|
|
131
130
|
before :all do
|
132
131
|
@files = ['test/app.js', 'test/lib.js', 'test/utils.js', 'test/vendor/jquery.js', 'test/vendor/proto.js']
|
133
|
-
@files.each { |fn|
|
132
|
+
@files.each { |fn| create_file(fn, "alert()") }
|
134
133
|
@files = @files.map { |fn| File.expand_path(fn) }
|
135
134
|
end
|
136
135
|
|
@@ -150,7 +149,7 @@ describe JSLint::Lint do
|
|
150
149
|
lint = JSLint::Lint.new :paths => ['test/**/*.js', 'test/**/a*.js', 'test/**/p*.js']
|
151
150
|
lint.file_list.should == @files
|
152
151
|
|
153
|
-
|
152
|
+
create_file 'new.yml', 'paths' => ['test/vendor/*.js']
|
154
153
|
|
155
154
|
lint = JSLint::Lint.new :config_path => 'new.yml', :exclude_paths => ['**/proto.js']
|
156
155
|
lint.file_list.should == [@files[3]]
|
@@ -167,8 +166,8 @@ describe JSLint::Lint do
|
|
167
166
|
end
|
168
167
|
|
169
168
|
it "should ignore empty files" do
|
170
|
-
|
171
|
-
|
169
|
+
create_file 'test/empty.js', ''
|
170
|
+
create_file 'test/full.js', 'qqq'
|
172
171
|
|
173
172
|
lint = JSLint::Lint.new :paths => ['test/*.js']
|
174
173
|
lint.file_list.should_not include(File.expand_path("test/empty.js"))
|
data/spec/railtie_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'jslint/railtie'
|
|
3
3
|
|
4
4
|
describe JSLint::Railtie do
|
5
5
|
before :all do
|
6
|
-
|
6
|
+
create_config 'example config'
|
7
7
|
JSLint.config_path = "custom_config.yml"
|
8
8
|
end
|
9
9
|
|
@@ -16,11 +16,11 @@ describe JSLint::Railtie do
|
|
16
16
|
JSLint::Railtie.create_example_config
|
17
17
|
|
18
18
|
File.exist?(JSLint.config_path).should be_true
|
19
|
-
File.read(JSLint.config_path).should ==
|
19
|
+
File.read(JSLint.config_path).should == 'example config'
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not do anything if config already exists" do
|
23
|
-
|
23
|
+
create_file(JSLint.config_path, "bar")
|
24
24
|
|
25
25
|
JSLint::Railtie.create_example_config
|
26
26
|
|
data/spec/spec_helper.rb
CHANGED
@@ -19,3 +19,26 @@ module FileUtils
|
|
19
19
|
cp(*args)
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
module FakeFS
|
24
|
+
class File
|
25
|
+
def self.identical?(file1, file2)
|
26
|
+
File.expand_path(file1) == File.expand_path(file2)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module SpecHelper
|
32
|
+
def create_file(filename, contents)
|
33
|
+
contents = YAML.dump(contents) + "\n" unless contents.is_a?(String)
|
34
|
+
File.open(filename, "w") { |f| f.print(contents) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_config(data)
|
38
|
+
create_file(JSLint::DEFAULT_CONFIG_FILE, data)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec.configure do |config|
|
43
|
+
config.include SpecHelper
|
44
|
+
end
|
data/spec/utils_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe JSLint::Utils do
|
|
5
5
|
JSU = JSLint::Utils
|
6
6
|
|
7
7
|
before :all do
|
8
|
-
|
8
|
+
create_config "default config file"
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have a config_path setting" do
|
@@ -37,7 +37,7 @@ describe JSLint::Utils do
|
|
37
37
|
describe "load_config_file" do
|
38
38
|
|
39
39
|
before :all do
|
40
|
-
|
40
|
+
create_file 'sample.yml', 'framework: rails'
|
41
41
|
Dir.mkdir("tmp")
|
42
42
|
end
|
43
43
|
|
@@ -103,7 +103,7 @@ describe JSLint::Utils do
|
|
103
103
|
|
104
104
|
it "should not overwrite the file if it exists" do
|
105
105
|
JSLint.config_path = "newfile2.yml"
|
106
|
-
|
106
|
+
create_file 'newfile2.yml', 'qwe'
|
107
107
|
FileUtils.should_not_receive(:copy)
|
108
108
|
JSLint::Utils.copy_config_file
|
109
109
|
end
|
@@ -117,7 +117,7 @@ describe JSLint::Utils do
|
|
117
117
|
|
118
118
|
it "should remove the file if it's identical to default one" do
|
119
119
|
JSLint.config_path = "newfile3.yml"
|
120
|
-
|
120
|
+
create_file 'newfile3.yml', 'default config file'
|
121
121
|
File.exists?("newfile3.yml").should be_true
|
122
122
|
JSLint::Utils.remove_config_file
|
123
123
|
File.exists?("newfile3.yml").should be_false
|
@@ -125,7 +125,7 @@ describe JSLint::Utils do
|
|
125
125
|
|
126
126
|
it "should not remove the file if it's not identical to default one" do
|
127
127
|
JSLint.config_path = "newfile4.yml"
|
128
|
-
|
128
|
+
create_file 'newfile4.yml', "something's changed"
|
129
129
|
File.exists?("newfile4.yml").should be_true
|
130
130
|
JSLint::Utils.remove_config_file
|
131
131
|
File.exists?("newfile4.yml").should be_true
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 7
|
10
|
+
version: 1.0.7
|
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-
|
18
|
+
date: 2011-09-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/jslint/vendor/test.jar
|
47
47
|
- lib/jslint.rb
|
48
48
|
- lib/jslint_on_rails.rb
|
49
|
+
- spec/jslint_spec.rb
|
49
50
|
- spec/lint_spec.rb
|
50
51
|
- spec/railtie_spec.rb
|
51
52
|
- spec/spec_helper.rb
|