execjslint 0.9.0

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.
Files changed (5) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +87 -0
  3. data/lib/execjslint.rb +1 -0
  4. data/lib/jslint.rb +50 -0
  5. metadata +83 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012, Mint Digital
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ ExecJSLint
2
+ ==========
3
+
4
+ ExecJSLint is a thin Ruby wrapper that uses ExecJS to execute [Douglas Crockford's JSLint][jslint].
5
+
6
+ Usage
7
+ -----
8
+
9
+ ```ruby
10
+ js = File.open('path/to/my.js')
11
+ results = ExecJSLint.run(js)
12
+ if result.problems.any?
13
+ puts "You suck at JavaScript!"
14
+ puts results.problems
15
+ else
16
+ puts "GREAT SUCCESS!"
17
+ end
18
+ ```
19
+
20
+ If you're looking to use this in a Rails app, take a look at
21
+ [examples/jslint.rake][rake].
22
+
23
+ Requirements
24
+ ------------
25
+
26
+ You'll need one of the [supported ExecJS runtimes][execjs-runtimes]. OS X
27
+ comes with JavaScriptCore by default, so you likely don't need to install
28
+ anything.
29
+
30
+ JSLint Options
31
+ --------------
32
+
33
+ Right now, `ExecJSLint` does not support setting global JSLint options, so you'll
34
+ have to include them in a `/*jslint */` comment at the top of each file.
35
+ `jslint.js` will automatically parse and apply options specified like this. A
36
+ full list of options is available on [jslint.com][jslint-options].
37
+
38
+ Using an Alternate jslint.js
39
+ ----------------------------
40
+
41
+ ExecJSLint depends on the `jslint-source` gem, which is a ruby packaging
42
+ of the official [jslint.js][jslintjs]. By default, ExecJSLint depends on the
43
+ latest version of the `jslint-source` gem. As there are no official releases
44
+ of JSLint, `jslint-source` is versioned according to [the date at the top of
45
+ jslint.js][jslint-date] (eg, `2012.01.23`). rubygems.org has a [full list of
46
+ `jslint-source` gem versions][source-versions].
47
+
48
+ To override this, you can specify an explicit dependency on `jslint-source`,
49
+ for example, using bundler:
50
+
51
+ ```
52
+ gem 'execjslint'
53
+ gem 'jslint-source', '2011.01.23'
54
+ ```
55
+
56
+ You can also explicitly specify a local copy of `jslint.js` to use by setting
57
+ the `JSLINT_PATH` env variable.
58
+
59
+ ```
60
+ $ JSLINT_PATH=../lib/jslint.js rake jslint
61
+ ```
62
+
63
+ Similar Projects
64
+ ----------------
65
+
66
+ ExecJSLint is meant to be as simple as possible. If it doesn't fit your needs,
67
+ you may want to try one of these projects:
68
+
69
+ * [geraud/jslint][geraud] - rubygem that provides a standalone `jslint` script
70
+ that can be run from the command line. Supports Rhino and Node JavaScript
71
+ engines.
72
+
73
+ * [psionides/jslint\_on\_rails][on-rails] - rubygem meant for integrating JSLint into a
74
+ Rails application. Uses Rhino JavaScript engine.
75
+
76
+ * [rondevera/jslintmate][jslintmate] - TextMate plugin for running JSLint. Uses JSC.
77
+
78
+ [jslint]: <http://jslint.com/>
79
+ [rake]: <https://github.com/mintdigital/jslint/blob/master/examples/jslint.rake>
80
+ [execjs-runtimes]: <https://github.com/sstephenson/execjs/blob/master/README.md>
81
+ [jslintjs]: <https://github.com/douglascrockford/JSLint/blob/master/jslint.js>
82
+ [jslint-date]: <https://github.com/douglascrockford/JSLint/blob/master/jslint.js#L2>
83
+ [jslint-options]: <http://www.jslint.com/lint.html#options>
84
+ [source-versions]: <http://rubygems.org/gems/jslint-source/versions>
85
+ [geraud]: <https://github.com/geraud/jslint>
86
+ [on-rails]: <https://github.com/psionides/jslint_on_rails>
87
+ [jslintmate]: <https://github.com/rondevera/jslintmate>
data/lib/execjslint.rb ADDED
@@ -0,0 +1 @@
1
+ require 'jslint'
data/lib/jslint.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'execjs'
2
+ require 'jslint/source'
3
+
4
+ module JSLint
5
+ # Internal: The ExecJS Context in which to run JSLINT().
6
+ #
7
+ # Provides a small helper function JSLINTR to return both the JSLINT()
8
+ # return value and the JSLINT.errors object.
9
+ def self.context
10
+ ExecJS.compile(
11
+ JSLint::Source.contents + "\n" +
12
+ "function JSLINTR(source) { return [JSLINT(source),JSLINT.errors]; };"
13
+ )
14
+ end
15
+
16
+ # Public: Run JSLint over some JavaScript source.
17
+ #
18
+ # source - some String-like or IO-like JavaScript source.
19
+ def self.run(source)
20
+ source = source.respond_to?(:read) ? source.read : source
21
+ Result.new(*context.call("JSLINTR", source))
22
+ end
23
+
24
+ class Result
25
+ def initialize(valid, errors)
26
+ @valid = valid
27
+ @errors = errors
28
+ end
29
+
30
+ # Public: Did the JavaScript source pass JSLint without errors?
31
+ #
32
+ # This is the return value of the JSLINT() function.
33
+ #
34
+ # Returns true iff JSLint found no errors.
35
+ def valid?
36
+ @valid
37
+ end
38
+
39
+ # Public: A nicely formatted list of errors with their line number.
40
+ #
41
+ # Returns an Array of Strings.
42
+ def error_messages
43
+ # @errors will have a 'nil' last element if JSLINT it hit a catastrophic
44
+ # error before it finished looking at the whole file, so we 'compact'.
45
+ @errors.compact.map {|e|
46
+ "#{e['line']}:#{e['character']}: #{e['reason']}"
47
+ }
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: execjslint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dean Strelau
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jslint-source
16
+ requirement: &70336901655220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70336901655220
25
+ - !ruby/object:Gem::Dependency
26
+ name: execjs
27
+ requirement: &70336901654700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70336901654700
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70336901654180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70336901654180
47
+ description: ! ' A bridge to run JSLint from Ruby via ExecJS.
48
+
49
+ '
50
+ email: dean@mintdigital.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - lib/execjslint.rb
56
+ - lib/jslint.rb
57
+ - LICENSE
58
+ - README.md
59
+ homepage: http://github.com/mintdigital/execjslint
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.15
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: ExecJS JSLint Bridge
83
+ test_files: []