jslint_on_rails 1.0.7 → 1.1
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 +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/README.markdown +46 -51
- data/lib/jslint/railtie.rb +0 -14
- data/lib/jslint/utils.rb +7 -17
- data/spec/spec_helper.rb +1 -0
- data/spec/utils_spec.rb +0 -37
- metadata +20 -43
- data/lib/jslint/rails.rb +0 -4
- data/spec/railtie_spec.rb +0 -31
data/Changelog.markdown
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Version 1.1 (09.04.2012)
|
2
|
+
|
3
|
+
* removed support for installing as a Rails plugin
|
4
|
+
* doesn't auto-generate jslint.yml if it doesn't exist (create one explicitly using the rake task if you want)
|
5
|
+
* no need to set JSLint.config_path (if you aren't using the Railtie) if the file is in the default location
|
6
|
+
|
1
7
|
Version 1.0.7 (12.09.2011)
|
2
8
|
|
3
9
|
* fixed problem with local options from one file being applied to all subsequent files
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
diff-lcs (1.1.
|
5
|
-
fakefs (0.2
|
6
|
-
rake (0.
|
7
|
-
rspec (2.
|
8
|
-
rspec-core (~> 2.
|
9
|
-
rspec-expectations (~> 2.
|
10
|
-
rspec-mocks (~> 2.
|
11
|
-
rspec-core (2.
|
12
|
-
rspec-expectations (2.
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
fakefs (0.3.2)
|
6
|
+
rake (0.9.2)
|
7
|
+
rspec (2.6.0)
|
8
|
+
rspec-core (~> 2.6.0)
|
9
|
+
rspec-expectations (~> 2.6.0)
|
10
|
+
rspec-mocks (~> 2.6.0)
|
11
|
+
rspec-core (2.6.4)
|
12
|
+
rspec-expectations (2.6.0)
|
13
13
|
diff-lcs (~> 1.1.2)
|
14
|
-
rspec-mocks (2.
|
14
|
+
rspec-mocks (2.6.0)
|
15
15
|
|
16
16
|
PLATFORMS
|
17
17
|
ruby
|
18
18
|
|
19
19
|
DEPENDENCIES
|
20
|
-
fakefs
|
20
|
+
fakefs (= 0.3.2)
|
21
21
|
rake
|
22
22
|
rspec
|
data/README.markdown
CHANGED
@@ -1,34 +1,27 @@
|
|
1
1
|
# JSLint on Rails
|
2
2
|
|
3
|
+
[](http://travis-ci.org/psionides/jslint_on_rails)
|
4
|
+
|
3
5
|
**JSLint on Rails** is a Ruby library which lets you run
|
4
|
-
the [JSLint JavaScript code checker](https://github.com/douglascrockford/JSLint) on your Javascript code easily.
|
5
|
-
be installed either as a gem (the recommended method), or as a Rails plugin (legacy method).
|
6
|
+
the [JSLint JavaScript code checker](https://github.com/douglascrockford/JSLint) on your Javascript code easily.
|
6
7
|
|
7
|
-
Note: to run JSLint on Rails
|
8
|
+
Note: to run JSLint on Rails you need to have **Java** available on your machine - it's required because JSLint is
|
8
9
|
itself written in JavaScript, and is run using the [Rhino](http://www.mozilla.org/rhino) JavaScript engine (written in
|
9
10
|
Java). Any decent version of Java will do (and by decent I mean 5.0 or later).
|
10
11
|
|
11
12
|
|
12
13
|
## Compatibility
|
13
14
|
|
14
|
-
Latest version should be compatible with Ruby 1.
|
15
|
-
|
15
|
+
Latest version should be compatible with Ruby 1.8.7 and 1.9.2+ (check [Travis build status](http://travis-ci.org/#!/psionides/jslint_on_rails)), and also with Rails 2.x and 3.x.
|
16
16
|
|
17
|
-
## Installation (as gem)
|
18
17
|
|
19
|
-
|
20
|
-
advantage is that it's easier to update the library to newer versions later, and you keep its code separate from your
|
21
|
-
own code.
|
18
|
+
## Installation
|
22
19
|
|
23
|
-
To use JSLint
|
20
|
+
To use JSLint in Rails 3 you just need to do one thing:
|
24
21
|
|
25
22
|
* add `gem 'jslint_on_rails'` to bundler's Gemfile
|
26
23
|
|
27
|
-
|
28
|
-
you can then tweak to suit your app.
|
29
|
-
|
30
|
-
In Rails 2 and in other frameworks JSLint on Rails can't be loaded automatically using a Railtie, so you have to do a
|
31
|
-
bit more work. The procedure in this case is:
|
24
|
+
In Rails 2 and other frameworks JSLint on Rails can't be loaded automatically using a Railtie, so you have to load it explicitly. The procedure in this case is:
|
32
25
|
|
33
26
|
* install the gem in your application using whatever technique is recommended for your framework (e.g. using bundler,
|
34
27
|
or by installing the gem manually with `gem install jslint_on_rails` and loading it with `require 'jslint'`)
|
@@ -36,51 +29,23 @@ or by installing the gem manually with `gem install jslint_on_rails` and loading
|
|
36
29
|
|
37
30
|
require 'jslint/tasks'
|
38
31
|
|
39
|
-
|
40
|
-
file to be kept - for example:
|
41
|
-
|
42
|
-
JSLint.config_path = "config/jslint.yml"
|
43
|
-
|
44
|
-
* run a rake task which will generate a sample config file for you:
|
45
|
-
|
46
|
-
rake jslint:copy_config
|
47
|
-
|
48
|
-
|
49
|
-
## Installation (as Rails plugin)
|
50
|
-
|
51
|
-
Installing libraries as Rails plugins was popular before Rails 3, but now gems with Railties can do everything that
|
52
|
-
plugins could do, so plugins are getting less and less popular. But if you want to install JSLint on Rails as a plugin
|
53
|
-
anyway, here's how you do it:
|
54
|
-
|
55
|
-
./script/plugin install git://github.com/psionides/jslint_on_rails.git
|
56
|
-
|
57
|
-
This will also create a sample `jslint.yml` config file for you in your config directory.
|
58
|
-
|
32
|
+
## Configuration
|
59
33
|
|
60
|
-
|
34
|
+
It's strongly recommended that you create your own copy of the JSLint config file provided by the gem and tweak it to suit your preferences. To create a new config file from the template in your config directory, call this rake task:
|
61
35
|
|
62
|
-
|
36
|
+
[bundle exec] rake jslint:copy_config
|
63
37
|
|
64
|
-
|
65
|
-
|
66
|
-
lint = JSLint::Lint.new(
|
67
|
-
:paths => ['public/javascripts/**/*.js'],
|
68
|
-
:exclude_paths => ['public/javascripts/vendor/**/*.js'],
|
69
|
-
:config_path => 'config/jslint.yml'
|
70
|
-
)
|
71
|
-
|
72
|
-
lint.run
|
38
|
+
This will create a config file at `config/jslint.yml` listing all available options. If for some reason you'd like to put the config file at a different location, set the `config_path` variable somewhere in your Rakefile:
|
73
39
|
|
40
|
+
JSLint.config_path = "config/lint.yml"
|
74
41
|
|
75
|
-
|
76
|
-
|
77
|
-
Whatever method you use for installation, a YAML config file should be created for you. In this file, you can:
|
42
|
+
There are two things you can change in the config file:
|
78
43
|
|
79
44
|
* define which Javascript files are checked by default; you'll almost certainly want to change that, because the default
|
80
45
|
is `public/javascripts/**/*.js` which means all Javascript files, and you probably don't want JSLint to check entire
|
81
46
|
jQuery, Prototype or whatever other libraries you use - so change this so that only your scripts are checked (you can
|
82
47
|
put multiple entries under "paths:" and "exclude_paths:")
|
83
|
-
*
|
48
|
+
* enable or disable specific checks - I've set the defaults to what I believe is reasonable,
|
84
49
|
but what's reasonable for me may not be reasonable for you
|
85
50
|
|
86
51
|
|
@@ -128,10 +93,31 @@ and/or paths to exclude to the rake task:
|
|
128
93
|
|
129
94
|
rake jslint paths=public/javascripts/models/*.js,public/javascripts/lib/*.js exclude_paths=public/javascripts/lib/jquery.js
|
130
95
|
|
131
|
-
For the best effect, you should include JSLint check in your Continuous Integration build - that way
|
96
|
+
For the best effect, you should include JSLint check in your Continuous Integration build - that way you'll get
|
132
97
|
immediate notification when you've committed JS code with errors.
|
133
98
|
|
134
99
|
|
100
|
+
## Running automatically with Guard
|
101
|
+
|
102
|
+
If you want to run JSLint on Rails automatically everytime you save a JS file, check out the
|
103
|
+
[guard-jslint-on-rails](https://github.com/wireframe/guard-jslint-on-rails) gem by Ryan Sonnek.
|
104
|
+
|
105
|
+
|
106
|
+
## Running from your code
|
107
|
+
|
108
|
+
If you would prefer to write your own rake task to run JSLint, you can create and execute the JSLint object manually:
|
109
|
+
|
110
|
+
require 'jslint'
|
111
|
+
|
112
|
+
lint = JSLint::Lint.new(
|
113
|
+
:paths => ['public/javascripts/**/*.js'],
|
114
|
+
:exclude_paths => ['public/javascripts/vendor/**/*.js'],
|
115
|
+
:config_path => 'config/jslint.yml'
|
116
|
+
)
|
117
|
+
|
118
|
+
lint.run
|
119
|
+
|
120
|
+
|
135
121
|
## Additional options
|
136
122
|
|
137
123
|
I've added some additional options to JSLint to get rid of some warnings which I thought didn't make sense. They're all
|
@@ -181,6 +167,15 @@ So I've tweaked the code that creates this warning so that it doesn't print it i
|
|
181
167
|
* expressions with ?: are accepted if both alternatives (before and after the colon) are statements
|
182
168
|
|
183
169
|
|
170
|
+
## Version 2.0 and JSHint
|
171
|
+
|
172
|
+
Some people have asked about [JSHint](http://jshint.com) support (some have even made forks replacing JSLint with JSHint). I like the idea of a less strict lint giving the user more control; the reason I haven't integrated JSHint yet is because I want the gem to provide both JSLint and JSHint and let you choose which engine you want to use. The thing is, I can't do that easily because their option sets have diverged - a few options have been changed in JSLint since JSHint was forked off from it, and JSHint has changed or added some other options. There was even [a plan](https://github.com/jshint/jshint/issues/166) to completely redesign the option system in JSHint. So I've decided to hold off the integration until I can be sure that the option sets won't be completely changed again. I'm hoping this might happen as a part of the [JSHint Next](https://github.com/jshint/jshint-next) project, but I don't know what the timeline is.
|
173
|
+
|
174
|
+
I haven't been updating JSLint for the same reason - some options have changed there and I'd rather wait until I can update everything together at the same time. If you're impatient, check out some of the [forks that use JSHint](https://github.com/psionides/jslint_on_rails/network); some of them have even been released as gems (e.g. see [jshint\_on\_rails](https://rubygems.org/gems/jshint_on_rails)) - although as far as I know, none of them have adapted the config file template to match JSHint's option set.
|
175
|
+
|
176
|
+
Another thing that's planned for 2.0, whenever that happens, is a redesign of the Javascript runner code to make it possible to use other ways of running Javascript - probably using [execjs](https://github.com/sstephenson/execjs).
|
177
|
+
|
178
|
+
|
184
179
|
## Credits
|
185
180
|
|
186
181
|
* JSLint on Rails was created by [Jakub Suder](http://psionides.jogger.pl), licensed under MIT License
|
data/lib/jslint/railtie.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
1
|
module JSLint
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
|
4
3
|
rake_tasks do
|
5
|
-
require 'jslint/rails'
|
6
4
|
require 'jslint/tasks'
|
7
|
-
JSLint::Railtie.create_example_config
|
8
5
|
end
|
9
|
-
|
10
|
-
def self.create_example_config
|
11
|
-
unless File.exists?(JSLint.config_path)
|
12
|
-
begin
|
13
|
-
JSLint::Utils.copy_config_file
|
14
|
-
rescue StandardError => error
|
15
|
-
puts "Error: #{error.message}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
6
|
end
|
21
7
|
end
|
data/lib/jslint/utils.rb
CHANGED
@@ -3,13 +3,19 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module JSLint
|
5
5
|
|
6
|
-
VERSION = "1.
|
6
|
+
VERSION = "1.1"
|
7
7
|
DEFAULT_CONFIG_FILE = File.expand_path(File.dirname(__FILE__) + "/config/jslint.yml")
|
8
8
|
|
9
9
|
class << self
|
10
10
|
attr_accessor :config_path
|
11
11
|
end
|
12
12
|
|
13
|
+
self.config_path = if defined?(Rails)
|
14
|
+
File.join(Rails.root, 'config', 'jslint.yml')
|
15
|
+
else
|
16
|
+
'config/jslint.yml'
|
17
|
+
end
|
18
|
+
|
13
19
|
module Utils
|
14
20
|
class << self
|
15
21
|
|
@@ -59,22 +65,6 @@ module JSLint
|
|
59
65
|
xputs "done."
|
60
66
|
end
|
61
67
|
end
|
62
|
-
|
63
|
-
def remove_config_file
|
64
|
-
raise ArgumentError, "Please set JSLint.config_path" if JSLint.config_path.nil?
|
65
|
-
xprint "Removing config file... "
|
66
|
-
if File.exists?(JSLint.config_path) && File.file?(JSLint.config_path)
|
67
|
-
if File.read(JSLint.config_path) == File.read(JSLint::DEFAULT_CONFIG_FILE)
|
68
|
-
File.delete(JSLint.config_path)
|
69
|
-
xputs "OK."
|
70
|
-
else
|
71
|
-
xputs "File was modified, so it won't be deleted automatically."
|
72
|
-
end
|
73
|
-
else
|
74
|
-
xputs "OK (no config file found)."
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
68
|
end
|
79
69
|
end
|
80
70
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/utils_spec.rb
CHANGED
@@ -108,41 +108,4 @@ describe JSLint::Utils do
|
|
108
108
|
JSLint::Utils.copy_config_file
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
112
|
-
describe "remove_config_file" do
|
113
|
-
it "throw an error if config path isn't set" do
|
114
|
-
JSLint.config_path = nil
|
115
|
-
lambda { JSLint::Utils.remove_config_file }.should raise_error(ArgumentError)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should remove the file if it's identical to default one" do
|
119
|
-
JSLint.config_path = "newfile3.yml"
|
120
|
-
create_file 'newfile3.yml', 'default config file'
|
121
|
-
File.exists?("newfile3.yml").should be_true
|
122
|
-
JSLint::Utils.remove_config_file
|
123
|
-
File.exists?("newfile3.yml").should be_false
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should not remove the file if it's not identical to default one" do
|
127
|
-
JSLint.config_path = "newfile4.yml"
|
128
|
-
create_file 'newfile4.yml', "something's changed"
|
129
|
-
File.exists?("newfile4.yml").should be_true
|
130
|
-
JSLint::Utils.remove_config_file
|
131
|
-
File.exists?("newfile4.yml").should be_true
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should not remove the file if it doesn't exist" do
|
135
|
-
JSLint.config_path = "this_doesnt_exist.yml"
|
136
|
-
lambda { JSLint::Utils.remove_config_file }.should_not raise_error
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should not remove the file if it's not a file" do
|
140
|
-
Dir.mkdir("public")
|
141
|
-
JSLint.config_path = "public"
|
142
|
-
lambda { JSLint::Utils.remove_config_file }.should_not raise_error
|
143
|
-
File.exist?("public").should be_true
|
144
|
-
File.directory?("public").should be_true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
111
|
end
|
metadata
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jslint_on_rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 1.0.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jakub Suder
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-09-12 00:00:00 +02:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-04-09 00:00:00.000000000Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
14
|
description:
|
23
15
|
email: jakub.suder@gmail.com
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
18
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
19
|
+
files:
|
31
20
|
- MIT-LICENSE
|
32
21
|
- README.markdown
|
33
22
|
- Changelog.markdown
|
@@ -37,7 +26,6 @@ files:
|
|
37
26
|
- lib/jslint/config/jslint.yml
|
38
27
|
- lib/jslint/errors.rb
|
39
28
|
- lib/jslint/lint.rb
|
40
|
-
- lib/jslint/rails.rb
|
41
29
|
- lib/jslint/railtie.rb
|
42
30
|
- lib/jslint/tasks.rb
|
43
31
|
- lib/jslint/utils.rb
|
@@ -48,42 +36,31 @@ files:
|
|
48
36
|
- lib/jslint_on_rails.rb
|
49
37
|
- spec/jslint_spec.rb
|
50
38
|
- spec/lint_spec.rb
|
51
|
-
- spec/railtie_spec.rb
|
52
39
|
- spec/spec_helper.rb
|
53
40
|
- spec/utils_spec.rb
|
54
|
-
has_rdoc: true
|
55
41
|
homepage: http://github.com/psionides/jslint_on_rails
|
56
42
|
licenses: []
|
57
|
-
|
58
43
|
post_install_message:
|
59
44
|
rdoc_options: []
|
60
|
-
|
61
|
-
require_paths:
|
45
|
+
require_paths:
|
62
46
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
48
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
54
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
- 0
|
80
|
-
version: "0"
|
81
|
-
requirements:
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements:
|
82
60
|
- Java JRE (5.0 or later)
|
83
61
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.8.10
|
85
63
|
signing_key:
|
86
64
|
specification_version: 3
|
87
65
|
summary: JSLint JavaScript checker wrapped in a Ruby gem for easier use
|
88
66
|
test_files: []
|
89
|
-
|
data/lib/jslint/rails.rb
DELETED
data/spec/railtie_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'jslint/railtie'
|
3
|
-
|
4
|
-
describe JSLint::Railtie do
|
5
|
-
before :all do
|
6
|
-
create_config 'example config'
|
7
|
-
JSLint.config_path = "custom_config.yml"
|
8
|
-
end
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
File.delete(JSLint.config_path) if File.exist?(JSLint.config_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "create_example_config" do
|
15
|
-
it "should create a config file if it doesn't exist" do
|
16
|
-
JSLint::Railtie.create_example_config
|
17
|
-
|
18
|
-
File.exist?(JSLint.config_path).should be_true
|
19
|
-
File.read(JSLint.config_path).should == 'example config'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should not do anything if config already exists" do
|
23
|
-
create_file(JSLint.config_path, "bar")
|
24
|
-
|
25
|
-
JSLint::Railtie.create_example_config
|
26
|
-
|
27
|
-
File.exist?(JSLint.config_path).should be_true
|
28
|
-
File.read(JSLint.config_path).should == "bar"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|