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.
@@ -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 gem and Rails plugin which lets you run
4
- the [JSLint JavaScript code checker](http://jslint.com) on your Javascript code easily.
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 (Rails)
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
- This will create for you a sample `jslint.yml` config file in your config directory.
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
- ## Installation (other frameworks)
25
+ * add `gem 'jslint_on_rails'` to bundler's Gemfile
29
26
 
30
- If you use Merb or some other framework, you need to install JSLint as a Ruby gem (you can do that in Rails too - the
31
- advantage of this method is that it may be easier to update to newer versions later).
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
- To use JSLint as a gem, follow these steps:
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 gem
36
- bundler, or just plain old `gem install jslint_on_rails`)
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 one-liner anonymous functions, 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 'spec/rake/spectask'
5
+ require 'rspec/core/rake_task'
6
6
 
7
7
  desc 'Run the specs'
8
- Spec::Rake::SpecTask.new do |t|
9
- t.libs << 'lib'
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.3"
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 "Copying default config file to #{File.expand_path(JSLint.config_path)}... "
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 "OK."
58
+ xputs "done."
59
59
  end
60
60
  end
61
61