jshint 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.3
3
+ script: rspec spec
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'pry'
7
+
8
+ group :test, :development do
9
+ gem 'coveralls', require: false
10
+ end
data/README.md CHANGED
@@ -1,24 +1,66 @@
1
- # Jshint
1
+ # JSHint
2
2
 
3
- TODO: Write a gem description
3
+ [![travis-ci](https://api.travis-ci.org/damian/jshint.png)](http://travis-ci.org/#!/damian/jshint)
4
+ [![Code Climate](https://codeclimate.com/github/damian/jshint.png)](https://codeclimate.com/github/damian/jshint)
5
+ [![Coverage Status](https://coveralls.io/repos/damian/jshint/badge.png?branch=master)](https://coveralls.io/r/damian/jshint?branch=master)
6
+
7
+ Making it easy to lint your JavaScript assets in any Rails 3.1+ application.
4
8
 
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
8
12
 
9
- gem 'jshint'
13
+ ```ruby
14
+ group :development, :test do
15
+ gem 'jshint'
16
+ end
17
+ ```
10
18
 
11
19
  And then execute:
12
20
 
13
- $ bundle
21
+ ```ruby
22
+ $ bundle
23
+ ```
14
24
 
15
- Or install it yourself as:
25
+ Run the generator:
16
26
 
17
- $ gem install jshint
27
+ ```ruby
28
+ bundle exec rake jshint:install_config
29
+ ```
18
30
 
19
31
  ## Usage
20
32
 
21
- TODO: Write usage instructions here
33
+ To start using JSHint simply run the Rake task:
34
+
35
+ ```ruby
36
+ bundle exec rake jshint
37
+ ```
38
+
39
+ This Rake task runs JSHint across all the JavaScript assets within the following three folders to ensure that they're lint free. Using that data it builds a report which is shown in STDOUT.
40
+
41
+ ```bash
42
+ your-rails-project/app/assets/javascripts
43
+ your-rails-project/vendor/assets/javascripts
44
+ your-rails-project/lib/assets/javascripts
45
+ ```
46
+
47
+ ## Configuration
48
+
49
+ JSHint has some configuration options. You can read the default configuration created by JSHint in your applications config folder.
50
+
51
+ ```yaml
52
+ # your-rails-project/config/jshint.yml
53
+ files: ['**/*.js']
54
+ options:
55
+ boss: true
56
+ browser: true
57
+ ...
58
+ globals:
59
+ jQuery: true
60
+ $: true
61
+ ```
62
+
63
+ For more configuration options see the [JSHint documentation](http://jshint.com/docs/options/).
22
64
 
23
65
  ## Contributing
24
66
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "therubyracer", "~> 0.10.2"
21
+ spec.add_dependency "therubyracer", "~> 0.12.1"
22
22
  spec.add_dependency "execjs", "~> 1.4.0"
23
23
  spec.add_dependency "railties", ">= 3.2.0"
24
24
  spec.add_dependency 'multi_json', '~> 1.0'
@@ -1,10 +1,14 @@
1
1
  require "jshint/version"
2
2
  require "jshint/railtie" if defined?(Rails)
3
3
 
4
+ # Our gems top level namespace
4
5
  module Jshint
5
6
  autoload :Lint, 'jshint/lint'
6
7
  autoload :Configuration, 'jshint/configuration'
7
8
 
9
+ # The absolute path to this gems root
10
+ #
11
+ # @return [String] The absolute path
8
12
  def self.root
9
13
  File.expand_path('../..', __FILE__)
10
14
  end
@@ -1,9 +1,14 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Jshint
4
+ # Configuration object containing JSHint lint settings
4
5
  class Configuration
6
+
7
+ # @return [Hash] the configration options
5
8
  attr_reader :options
6
9
 
10
+ # Initializes our configuration object
11
+ #
7
12
  # @param path [String] The path to the config file
8
13
  def initialize(path = nil)
9
14
  @path = path || default_config_path
@@ -15,7 +20,7 @@ module Jshint
15
20
  # @param key [Symbol]
16
21
  # @return The value of the of the options Hash at the passed in key
17
22
  def [](key)
18
- options[key.to_s]
23
+ options["options"][key.to_s]
19
24
  end
20
25
 
21
26
  # Returns a Hash of global variables if one exists
@@ -43,7 +48,7 @@ module Jshint
43
48
  # }
44
49
  # @return [Hash, nil] The key value pairs of options or nil
45
50
  def lint_options
46
- options["options"].slice!("globals")
51
+ @lint_options ||= options["options"].reject { |key| key == "globals" }
47
52
  end
48
53
 
49
54
  # Returns the list of files that JSHint should lint over relatives to the Application root
@@ -3,20 +3,34 @@ require "multi_json"
3
3
  require "jshint/configuration"
4
4
 
5
5
  module Jshint
6
+ # Performs the linting of the files declared in our Configuration object
6
7
  class Lint
7
- attr_reader :errors, :config
8
8
 
9
+ # @return [Hash] A Hash of errors
10
+ attr_reader :errors
11
+
12
+ # @return [Jshint::Configuration] The configuration object
13
+ attr_reader :config
14
+
15
+ # @return [Array] The standard location for JavaScript assets in a Rails project
9
16
  RAILS_JS_ASSET_PATHS = [
10
17
  'app/assets/javascripts',
11
18
  'vendor/assets/javascripts',
12
19
  'lib/assets/javascripts'
13
20
  ]
14
21
 
22
+ # Sets up our Linting behaviour
23
+ #
24
+ # @param config_path [String] The absolute path to a configuration YAML file
25
+ # @return [void]
15
26
  def initialize(config_path = nil)
16
27
  @config = Configuration.new(config_path)
17
28
  @errors = {}
18
29
  end
19
30
 
31
+ # Runs JSHint over each file in our search path
32
+ #
33
+ # @return [void]
20
34
  def lint
21
35
  javascript_files.each do |file|
22
36
  file_content = get_file_content_as_json(file)
@@ -28,6 +42,10 @@ module Jshint
28
42
  end
29
43
  end
30
44
 
45
+ # Converts a Hash in to properly escaped JSON
46
+ #
47
+ # @param hash [Hash]
48
+ # @return [String] The JSON outout
31
49
  def get_json(hash)
32
50
  MultiJson.dump(hash)
33
51
  end
@@ -90,6 +108,5 @@ module Jshint
90
108
 
91
109
  js_asset_files
92
110
  end
93
-
94
111
  end
95
112
  end
@@ -2,6 +2,8 @@ require 'jshint'
2
2
  require 'rails'
3
3
 
4
4
  module Jshint
5
+
6
+ # A way to hook in to Rails to load our custom lint Rake task
5
7
  class Railtie < Rails::Railtie
6
8
  rake_tasks do
7
9
  load "jshint/tasks/jshint.rake"
@@ -1,3 +1,4 @@
1
+ # Top level namespace capable of containing different lint reporting classes
1
2
  module Jshint::Reporters
2
3
  autoload :Default, 'jshint/reporters/default'
3
4
  end
@@ -1,5 +1,8 @@
1
1
  module Jshint::Reporters
2
+ # Outputs a basic lint report suitable for STDOUT
2
3
  class Default
4
+
5
+ # @return [String] the report output
3
6
  attr_reader :output
4
7
 
5
8
  # Sets up the output string for the final report
@@ -1,3 +1,4 @@
1
1
  module Jshint
2
- VERSION = "0.0.1"
2
+ # Our gem version
3
+ VERSION = "0.0.2"
3
4
  end
@@ -0,0 +1,20 @@
1
+ files: ["**/*.js"] # No need to put app/assets/ or vendor/assets here
2
+ options:
3
+ boss: true
4
+ browser: true
5
+ curly: true
6
+ eqeqeq: true
7
+ eqnull: true
8
+ expr: true
9
+ immed: true
10
+ indent: 2
11
+ latedef: true
12
+ newcap: true
13
+ noarg: true
14
+ sub: true
15
+ trailing: true
16
+ undef: true
17
+ unused: true
18
+ globals:
19
+ jQuery: true
20
+ "$": true
@@ -2,30 +2,33 @@ require 'spec_helper'
2
2
  require 'jshint/configuration'
3
3
 
4
4
  describe Jshint::Configuration do
5
- let(:file) { { "include" => [ 'foo/bar/**/*', 'baz.js' ], "curly" => true } }
6
- let(:yaml) { file.to_yaml }
5
+ let(:config) { File.join(Jshint.root, 'spec', 'fixtures', 'jshint.yml') }
7
6
 
8
- before do
9
- described_class.any_instance.stub(:default_config_path).and_return('/foo/bar.yml')
10
- described_class.any_instance.stub(:read_config_file).and_return(yaml)
11
- described_class.any_instance.stub(:parse_yaml_config).and_return(YAML.load(yaml))
12
- end
7
+ describe "core behaviour" do
8
+ before do
9
+ described_class.any_instance.stub(:default_config_path).and_return('/foo/bar.yml')
10
+ described_class.any_instance.stub(:parse_yaml_config).and_return(YAML.load_file(config))
11
+ end
13
12
 
14
- it "should fall back to the default JSHint config file when one is provided" do
15
- described_class.any_instance.should_receive(:default_config_path)
16
- config = described_class.new
17
- config.options.should == file
18
- end
13
+ it "should allow the developer to index in to config options" do
14
+ config = described_class.new
15
+ config[:boss].should be_true
16
+ config[:browser].should be_true
17
+ end
19
18
 
20
- it "should return a hash of options when reading the contents of the passed in config file" do
21
- described_class.any_instance.should_not_receive(:default_config_path)
22
- config = described_class.new('/bar/baz.yml')
23
- config.options.should == file
24
- end
19
+ it "should return a Hash of the global variables declared" do
20
+ config = described_class.new
21
+ config.global_variables.should == { "jQuery" => true, "$" => true }
22
+ end
23
+
24
+ it "should return a Hash of the lint options declared" do
25
+ config = described_class.new
26
+ config.lint_options.should == config.options["options"].reject { |key| key == "globals" }
27
+ end
25
28
 
26
- it "should allow the developer to index in to config options" do
27
- config = described_class.new
28
- config[:include].should == file["include"]
29
- config[:curly].should == file["curly"]
29
+ it "should return an array of files" do
30
+ config = described_class.new
31
+ config.files.should == ["**/*.js"]
32
+ end
30
33
  end
31
34
  end
@@ -46,6 +46,7 @@ describe Jshint::Lint do
46
46
  ))
47
47
  subject.lint
48
48
  end
49
+
49
50
  it "should add two error messages to the errors Hash" do
50
51
  subject.errors[file].length.should == 2
51
52
  end
@@ -66,6 +67,11 @@ describe Jshint::Lint do
66
67
  subject.lint
67
68
  end
68
69
 
70
+ it "should retrieve the files content" do
71
+ subject.should_receive(:get_file_content_as_json).with(file)
72
+ subject.lint
73
+ end
74
+
69
75
  it "should add two error messages to the errors Hash" do
70
76
  subject.errors[file].length.should == 0
71
77
  end
@@ -88,4 +88,25 @@ describe Jshint::Reporters::Default do
88
88
  subject.output.should include "'app' is not defined"
89
89
  end
90
90
  end
91
+
92
+ describe :report do
93
+ it "should call print errors for file 1 time" do
94
+ subject.should_receive(:print_errors_for_file)
95
+ subject.report
96
+ end
97
+
98
+ it "should print the report footer" do
99
+ subject.should_receive(:print_footer).with(3)
100
+ subject.report
101
+ end
102
+
103
+ it "should return a thorough report" do
104
+ subject.report.length.should >= 10
105
+ end
106
+
107
+ it "should return 0 errors when it has no results" do
108
+ subject.instance_variable_set(:@results, {})
109
+ subject.report.should include "0 errors"
110
+ end
111
+ end
91
112
  end
@@ -1,9 +1,6 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
7
4
  RSpec.configure do |config|
8
5
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
6
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jshint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Damian Nicholson
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-25 00:00:00.000000000 Z
12
+ date: 2014-03-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: therubyracer
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
19
- version: 0.10.2
21
+ version: 0.12.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
- version: 0.10.2
29
+ version: 0.12.1
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: execjs
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: railties
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: multi_json
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: bundler
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: rake
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -97,6 +110,7 @@ dependencies:
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: rspec
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
115
  - - ! '>='
102
116
  - !ruby/object:Gem::Version
@@ -104,6 +118,7 @@ dependencies:
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
123
  - - ! '>='
109
124
  - !ruby/object:Gem::Version
@@ -111,6 +126,7 @@ dependencies:
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: yard
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
131
  - - ! '>='
116
132
  - !ruby/object:Gem::Version
@@ -118,6 +134,7 @@ dependencies:
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
139
  - - ! '>='
123
140
  - !ruby/object:Gem::Version
@@ -132,6 +149,7 @@ extra_rdoc_files: []
132
149
  files:
133
150
  - .gitignore
134
151
  - .rspec
152
+ - .travis.yml
135
153
  - Gemfile
136
154
  - LICENSE.txt
137
155
  - README.md
@@ -146,6 +164,7 @@ files:
146
164
  - lib/jshint/reporters/default.rb
147
165
  - lib/jshint/tasks/jshint.rake
148
166
  - lib/jshint/version.rb
167
+ - spec/fixtures/jshint.yml
149
168
  - spec/jshint_spec.rb
150
169
  - spec/lib/configuration_spec.rb
151
170
  - spec/lib/lint_spec.rb
@@ -155,28 +174,36 @@ files:
155
174
  homepage: http://damiannicholson.com
156
175
  licenses:
157
176
  - MIT
158
- metadata: {}
159
177
  post_install_message:
160
178
  rdoc_options: []
161
179
  require_paths:
162
180
  - lib
163
181
  required_ruby_version: !ruby/object:Gem::Requirement
182
+ none: false
164
183
  requirements:
165
184
  - - ! '>='
166
185
  - !ruby/object:Gem::Version
167
186
  version: '0'
187
+ segments:
188
+ - 0
189
+ hash: 463206555677395138
168
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
169
192
  requirements:
170
193
  - - ! '>='
171
194
  - !ruby/object:Gem::Version
172
195
  version: '0'
196
+ segments:
197
+ - 0
198
+ hash: 463206555677395138
173
199
  requirements: []
174
200
  rubyforge_project:
175
- rubygems_version: 2.0.6
201
+ rubygems_version: 1.8.23
176
202
  signing_key:
177
- specification_version: 4
203
+ specification_version: 3
178
204
  summary: Ensures your JavaScript code adheres to best practices
179
205
  test_files:
206
+ - spec/fixtures/jshint.yml
180
207
  - spec/jshint_spec.rb
181
208
  - spec/lib/configuration_spec.rb
182
209
  - spec/lib/lint_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTFkMWQzYWVjZmExNDEzMDRjYzMwZmI1OTI5OTdiYTUyNWIwZjI2NA==
5
- data.tar.gz: !binary |-
6
- YTc2MDljNzAwOTZiYjY5NTIyODEyNWEzNWM0ODk2MDY1ZTRkYjIyOA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDI0ZDIxYzA0NmY2OGVlMzgxYzMwZTFjMTBiZjUxMTE5NGQ3NjI3OGRjODQy
10
- MGQ2YzBkMzdjMGI1NDIxZGMyMjRlOTRhMjM3YzJmNTk2MWNhYWVjMGE5OGFm
11
- MjllZGQxNzBkMTdiYTNkNTUzYTI5YjllMTM4YmU3NDUyNDA5OTY=
12
- data.tar.gz: !binary |-
13
- MjlhZDE4NWM3M2Q5OTc2YmUzMzliMWZmNjBkM2RkMGZiMWQ2MDlkM2IzMzE2
14
- YTg5ODY2NTU3Yjg1NzFlMDc2N2M3M2IxYTJlN2YyZjVlY2MzMDVjMzQ2MDc1
15
- NWM2YTNmYTdkNGJjNGRiZGJjMWVmMzIzZjcyNjIyOGYwOWE1ODk=