jshintrb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ require "execjs"
4
+ require "multi_json"
5
+
6
+ module Jshintrb
7
+
8
+ class Lint
9
+ Error = ExecJS::Error
10
+
11
+ # Default options for compilation
12
+ DEFAULTS = {
13
+ :bitwise => true,
14
+ :curly => true,
15
+ :eqeqeq => true,
16
+ :forin => true,
17
+ :immed => true,
18
+ :latedef => true,
19
+ :newcap => true,
20
+ :noarg => true,
21
+ :noempty => true,
22
+ :nonew => true,
23
+ :plusplus => true,
24
+ :regexp => true,
25
+ :undef => true,
26
+ :strict => true,
27
+ :trailing => true,
28
+ :browser => true
29
+ }
30
+
31
+ SourcePath = File.expand_path("../../js/jshint.js", __FILE__)
32
+
33
+ def initialize(options = nil)
34
+
35
+ if options.nil? then
36
+ @options = DEFAULTS.dup
37
+ elsif options.instance_of? Hash then
38
+ @options = options.dup
39
+ # @options = DEFAULTS.merge(options)
40
+ else
41
+ raise ArgumentError
42
+ end
43
+
44
+ @context = ExecJS.compile(File.open(SourcePath, "r:UTF-8").read)
45
+ end
46
+
47
+ def lint(source)
48
+ source = source.respond_to?(:read) ? source.read : source.to_s
49
+
50
+ js = []
51
+ js << "JSHINT(#{MultiJson.encode(source)}, #{MultiJson.encode(@options)});"
52
+ js << "return JSHINT.errors;"
53
+
54
+ @context.exec js.join("\n")
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ module Jshintrb
2
+ module Reporter
3
+ class Default
4
+
5
+ def format errors
6
+ result = ''
7
+ errors.each do | error |
8
+ result += 'line ' + error["line"].to_s + ', col ' +
9
+ error["character"].to_s + ', ' + error["reason"].to_s + '\n'
10
+ end
11
+ result
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Jshintrb
2
+ VERSION = "0.0.1"
3
+ end
data/lib/jshintrb.rb ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ require "jshintrb/version"
4
+ require "jshintrb/lint"
5
+ require "jshintrb/reporter/default"
6
+
7
+ module Jshintrb
8
+
9
+ def self.lint(source, options = nil)
10
+ Lint.new(options).lint(source)
11
+ end
12
+
13
+ def self.report(source, options = nil)
14
+ reporter = Reporter::Default
15
+ errors = Lint.new(options).lint(source)
16
+ reporter.new.format errors
17
+ end
18
+
19
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ require "jshintrb"
3
+
4
+ describe "Jshintrb" do
5
+
6
+ it "support options" do
7
+ options = {
8
+ :bitwise => "var a = 1|1;",
9
+ :curly => "while (true)\n var a = 'a';",
10
+ # :eqeqeq => true,
11
+ # :forin => true,
12
+ # :immed => true,
13
+ # :latedef => true,
14
+ # :newcap => true,
15
+ # :noarg => true,
16
+ # :noempty => true,
17
+ # :nonew => true,
18
+ # :plusplus => true,
19
+ # :regexp => true,
20
+ :undef => "if (a == 'a') { var b = 'b'; }"
21
+ # :strict => true,
22
+ # :trailing => true,
23
+ # :browser => true
24
+ }
25
+
26
+ options.each do |option, source|
27
+ Jshintrb.lint(source, option => false).length.should eq 0
28
+ Jshintrb.lint(source, option => true).length.should eq 1
29
+ end
30
+
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jshintrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - stereobooster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &21167640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21167640
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &21167352 !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: *21167352
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_json
38
+ requirement: &21167100 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *21167100
47
+ - !ruby/object:Gem::Dependency
48
+ name: execjs
49
+ requirement: &21166800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *21166800
58
+ description: Ruby wrapper for JSHint. The main difference from jshint it does not
59
+ depend on Java. Instead, it uses ExecJS
60
+ email:
61
+ - stereobooster@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .gitmodules
68
+ - .travis.yml
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - jshintrb.gemspec
73
+ - lib/js/jshint.js
74
+ - lib/jshintrb.rb
75
+ - lib/jshintrb/lint.rb
76
+ - lib/jshintrb/reporter/default.rb
77
+ - lib/jshintrb/version.rb
78
+ - spec/jshintrb_spec.rb
79
+ homepage: https://github.com/stereobooster/jshintrb
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project: jshintrb
99
+ rubygems_version: 1.8.15
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Ruby wrapper for JSHint
103
+ test_files: []