jslint_on_rails 1.0.3 → 1.0.4
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 +24 -0
- data/Gemfile.lock +22 -0
- data/README.markdown +33 -20
- data/Rakefile +3 -4
- data/lib/jslint/lint.rb +1 -0
- data/lib/jslint/railtie.rb +21 -0
- data/lib/jslint/utils.rb +3 -3
- data/lib/jslint/vendor/jslint.js +425 -256
- data/lib/jslint.rb +4 -0
- data/lib/jslint_on_rails.rb +1 -0
- data/spec/lint_spec.rb +9 -0
- data/spec/railtie_spec.rb +31 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/utils_spec.rb +2 -2
- metadata +11 -3
data/Changelog.markdown
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Version 1.0.4 (05.12.2010)
|
2
|
+
|
3
|
+
* bundler should be able to load the gem without :require
|
4
|
+
* added a Railtie to make things simpler in Rails 3
|
5
|
+
* don't print any warnings if tested JS file is empty
|
6
|
+
* lastsemic option will now not work if the missing semicolon is on a different line than the end bracket (so it only
|
7
|
+
makes sense for inline one-liner functions)
|
8
|
+
* updated JSLint to version from 2010-11-27 (adds some new warnings about comparing variables with empty string using
|
9
|
+
"==")
|
10
|
+
|
11
|
+
Version 1.0.3 (11.06.2010)
|
12
|
+
|
13
|
+
* Ruby 1.9 compatibility fixes
|
14
|
+
* 'es5' option is disabled by default
|
15
|
+
|
16
|
+
Version 1.0.2 (10.04.2010)
|
17
|
+
|
18
|
+
* Rails 3 compatibility fixes
|
19
|
+
* updated JSLint to version from 2010-04-06
|
20
|
+
* refactoring, added specs
|
21
|
+
|
22
|
+
Version 1.0.0 (18.12.2009)
|
23
|
+
|
24
|
+
* first gem release
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
fakefs (0.2.1)
|
6
|
+
rake (0.8.7)
|
7
|
+
rspec (2.1.0)
|
8
|
+
rspec-core (~> 2.1.0)
|
9
|
+
rspec-expectations (~> 2.1.0)
|
10
|
+
rspec-mocks (~> 2.1.0)
|
11
|
+
rspec-core (2.1.0)
|
12
|
+
rspec-expectations (2.1.0)
|
13
|
+
diff-lcs (~> 1.1.2)
|
14
|
+
rspec-mocks (2.1.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
fakefs
|
21
|
+
rake
|
22
|
+
rspec
|
data/README.markdown
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# JSLint on Rails
|
2
2
|
|
3
|
-
**JSLint on Rails** is a Ruby
|
4
|
-
the [JSLint JavaScript code checker](
|
5
|
-
|
6
|
-
It can be installed either as a Rails plugin (the recommended method for Rails), or as a gem (for other frameworks).
|
3
|
+
**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. It can
|
5
|
+
be installed either as a gem (the recommended method), or as a Rails plugin (legacy method).
|
7
6
|
|
8
7
|
Note: to run JSLint on Rails, you need to have **Java** available on your machine - it's required because JSLint is
|
9
8
|
itself written in JavaScript, and is run using the [Rhino](http://www.mozilla.org/rhino) JavaScript engine (written in
|
@@ -15,25 +14,24 @@ Java). Any decent version of Java will do (and by decent I mean 5.0 or later).
|
|
15
14
|
Latest version should be compatible with Ruby 1.9 and Rails 3 (and also with Ruby 1.8 and Rails 2, of course).
|
16
15
|
|
17
16
|
|
18
|
-
## Installation (
|
19
|
-
|
20
|
-
If you use Rails, you can install the library as a plugin - it's less work to set it up this way.
|
21
|
-
To install the plugin, use this command:
|
22
|
-
|
23
|
-
./script/plugin install git://github.com/psionides/jslint_on_rails.git
|
17
|
+
## Installation (as gem)
|
24
18
|
|
25
|
-
|
19
|
+
The recommended installation method (for Rails and for other frameworks) is to install JSLint on Rails as a gem. The
|
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.
|
26
22
|
|
23
|
+
To use JSLint as a gem in Rails 3, you just need to do one thing:
|
27
24
|
|
28
|
-
|
25
|
+
* add `gem 'jslint_on_rails'` to bundler's Gemfile
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
And that's it. On first run, JSLint on Rails will create an example config file for you in config/jslint.yml, which
|
28
|
+
you can then tweak to suit your app.
|
32
29
|
|
33
|
-
|
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:
|
34
32
|
|
35
|
-
* install the gem in your application using whatever technique is recommended for your framework (e.g. using
|
36
|
-
|
33
|
+
* install the gem in your application using whatever technique is recommended for your framework (e.g. using bundler,
|
34
|
+
or just plain old `gem install jslint_on_rails`)
|
37
35
|
* in your Rakefile, add a line to load the JSLint tasks:
|
38
36
|
|
39
37
|
require 'jslint/tasks'
|
@@ -48,6 +46,17 @@ file to be kept - for example:
|
|
48
46
|
rake jslint:copy_config
|
49
47
|
|
50
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
|
+
|
59
|
+
|
51
60
|
## Installation (custom)
|
52
61
|
|
53
62
|
If you wish to write your own rake task to run JSLint, you can create and execute the JSLint object manually:
|
@@ -79,7 +88,7 @@ but what's reasonable for me may not be reasonable for you
|
|
79
88
|
|
80
89
|
To start the check, run the rake task:
|
81
90
|
|
82
|
-
rake jslint
|
91
|
+
[bundle exec] rake jslint
|
83
92
|
|
84
93
|
You will get a result like this (if everything goes well):
|
85
94
|
|
@@ -134,11 +143,15 @@ Here's a documentation for all the extra options:
|
|
134
143
|
### lastsemic
|
135
144
|
|
136
145
|
If set to true, this will ignore warnings about missing semicolon after a statement, if the statement is the last one in
|
137
|
-
a block or function. I've added this because I like to omit the semicolon in
|
138
|
-
situations like this:
|
146
|
+
a block or function, and the whole block is on the same line. I've added this because I like to omit the semicolon in
|
147
|
+
one-liner anonymous functions, in situations like this:
|
139
148
|
|
140
149
|
var ids = $$('.entry').map(function(e) { return e.id });
|
141
150
|
|
151
|
+
Note: in versions up to 1.0.3, this option also disabled the warning in blocks that span multiple lines, but I've
|
152
|
+
changed that in 1.0.4, because removing a last semicolon in a multi-line block doesn't really affect the readability
|
153
|
+
(while removing the only semicolon in a one-liner like above does, IMHO).
|
154
|
+
|
142
155
|
|
143
156
|
### newstat
|
144
157
|
|
data/Rakefile
CHANGED
@@ -2,10 +2,9 @@ require "rubygems"
|
|
2
2
|
require "bundler"
|
3
3
|
Bundler.setup
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'rspec/core/rake_task'
|
6
6
|
|
7
7
|
desc 'Run the specs'
|
8
|
-
|
9
|
-
t.
|
10
|
-
t.spec_opts = ['--colour', '--format', 'specdoc']
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.rspec_opts = ['--colour', '--format', 'documentation']
|
11
10
|
end
|
data/lib/jslint/lint.rb
CHANGED
@@ -26,6 +26,7 @@ module JSLint
|
|
26
26
|
included_files = files_matching_paths(options, :paths)
|
27
27
|
excluded_files = files_matching_paths(options, :exclude_paths)
|
28
28
|
@file_list = Utils.exclude_files(included_files, excluded_files)
|
29
|
+
@file_list.delete_if { |f| File.size(f) == 0 }
|
29
30
|
|
30
31
|
['paths', 'exclude_paths'].each { |field| @config.delete(field) }
|
31
32
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module JSLint
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
rake_tasks do
|
5
|
+
require 'jslint/rails'
|
6
|
+
require 'jslint/tasks'
|
7
|
+
JSLint::Railtie.create_example_config
|
8
|
+
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
|
+
end
|
21
|
+
end
|
data/lib/jslint/utils.rb
CHANGED
@@ -2,7 +2,7 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module JSLint
|
4
4
|
|
5
|
-
VERSION = "1.0.
|
5
|
+
VERSION = "1.0.4"
|
6
6
|
DEFAULT_CONFIG_FILE = File.expand_path(File.dirname(__FILE__) + "/config/jslint.yml")
|
7
7
|
|
8
8
|
class << self
|
@@ -49,13 +49,13 @@ module JSLint
|
|
49
49
|
|
50
50
|
def copy_config_file
|
51
51
|
raise ArgumentError, "Please set JSLint.config_path" if JSLint.config_path.nil?
|
52
|
-
xprint "
|
52
|
+
xprint "Creating example JSLint config file in #{File.expand_path(JSLint.config_path)}... "
|
53
53
|
if File.exists?(JSLint.config_path)
|
54
54
|
xputs "\n\nWarning: config file exists, so it won't be overwritten. " +
|
55
55
|
"You can copy it manually from the jslint_on_rails directory if you want to reset it."
|
56
56
|
else
|
57
57
|
FileUtils.copy(JSLint::DEFAULT_CONFIG_FILE, JSLint.config_path)
|
58
|
-
xputs "
|
58
|
+
xputs "done."
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|