jshintrb 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,84 +1,84 @@
1
- # Define a task library for running JSHint contexts.
2
-
3
- require 'rake'
4
- require 'rake/tasklib'
5
-
6
- require 'jshintrb'
7
-
8
- module Jshintrb
9
-
10
- class JshintTask < ::Rake::TaskLib
11
- # Name of JSHint task. (default is :jshint)
12
- attr_accessor :name
13
-
14
- # Glob pattern to match JavaScript files. (default is './**/*.js')
15
- attr_accessor :pattern
16
-
17
- # options
18
- attr_accessor :options
19
-
20
- # Whether or not to fail Rake when an error occurs (typically when Jshint check fail).
21
- # Defaults to true.
22
- attr_accessor :fail_on_error
23
-
24
- # Explicitly define the list of JavaScript files to be linted.
25
- # +js_files+ is expected to be an array of file names (a
26
- # FileList is acceptable). If both +pattern+ and +js_files+ are
27
- # used, then the list of JavaScritp files is the union of the two.
28
- attr_accessor :js_files
29
-
30
- attr_accessor :exclude_pattern
31
-
32
- attr_accessor :exclude_js_files
33
-
34
- # Defines a new task, using the name +name+.
35
- def initialize(name=:jshint)
36
- @name = name
37
- @pattern = nil
38
- @js_files = nil
39
- @exclude_pattern = nil
40
- @exclude_js_files = nil
41
- @options = nil
42
- @fail_on_error = true
43
-
44
- yield self if block_given?
45
- @pattern = './**/*.js' if pattern.nil? && js_files.nil?
46
- define
47
- end
48
-
49
- def define # :nodoc:
50
-
51
- actual_name = Hash === name ? name.keys.first : name
52
- unless ::Rake.application.last_comment
53
- desc "Run JShint"
54
- end
55
- task name do
56
- unless js_file_list.empty?
57
- result = Jshintrb::report(js_file_list, @options, STDERR)
58
- if result.size > 0
59
- abort("JSHint check failed") if fail_on_error
60
- end
61
- end
62
- end
63
-
64
- self
65
- end
66
-
67
- def evaluate(o) # :nodoc:
68
- case o
69
- when Proc then o.call
70
- else o
71
- end
72
- end
73
-
74
- def js_file_list # :nodoc:
75
- result = []
76
- result += js_files.to_a if js_files
77
- result += FileList[ pattern ].to_a if pattern
78
- result -= exclude_js_files.to_a if exclude_js_files
79
- result -= FileList[ exclude_pattern ].to_a if exclude_pattern
80
- FileList[result]
81
- end
82
- end
83
-
84
- end
1
+ # Define a task library for running JSHint contexts.
2
+
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+
6
+ require 'jshintrb'
7
+
8
+ module Jshintrb
9
+
10
+ class JshintTask < ::Rake::TaskLib
11
+ # Name of JSHint task. (default is :jshint)
12
+ attr_accessor :name
13
+
14
+ # Glob pattern to match JavaScript files. (default is './**/*.js')
15
+ attr_accessor :pattern
16
+
17
+ # options
18
+ attr_accessor :options
19
+
20
+ # Whether or not to fail Rake when an error occurs (typically when Jshint check fail).
21
+ # Defaults to true.
22
+ attr_accessor :fail_on_error
23
+
24
+ # Explicitly define the list of JavaScript files to be linted.
25
+ # +js_files+ is expected to be an array of file names (a
26
+ # FileList is acceptable). If both +pattern+ and +js_files+ are
27
+ # used, then the list of JavaScritp files is the union of the two.
28
+ attr_accessor :js_files
29
+
30
+ attr_accessor :exclude_pattern
31
+
32
+ attr_accessor :exclude_js_files
33
+
34
+ # Defines a new task, using the name +name+.
35
+ def initialize(name=:jshint)
36
+ @name = name
37
+ @pattern = nil
38
+ @js_files = nil
39
+ @exclude_pattern = nil
40
+ @exclude_js_files = nil
41
+ @options = nil
42
+ @fail_on_error = true
43
+
44
+ yield self if block_given?
45
+ @pattern = './**/*.js' if pattern.nil? && js_files.nil?
46
+ define
47
+ end
48
+
49
+ def define # :nodoc:
50
+
51
+ actual_name = Hash === name ? name.keys.first : name
52
+ unless ::Rake.application.last_comment
53
+ desc "Run JShint"
54
+ end
55
+ task name do
56
+ unless js_file_list.empty?
57
+ result = Jshintrb::report(js_file_list, @options, STDERR)
58
+ if result.size > 0
59
+ abort("JSHint check failed") if fail_on_error
60
+ end
61
+ end
62
+ end
63
+
64
+ self
65
+ end
66
+
67
+ def evaluate(o) # :nodoc:
68
+ case o
69
+ when Proc then o.call
70
+ else o
71
+ end
72
+ end
73
+
74
+ def js_file_list # :nodoc:
75
+ result = []
76
+ result += js_files.to_a if js_files
77
+ result += FileList[ pattern ].to_a if pattern
78
+ result -= exclude_js_files.to_a if exclude_js_files
79
+ result -= FileList[ exclude_pattern ].to_a if exclude_pattern
80
+ FileList[result]
81
+ end
82
+ end
83
+
84
+ end
data/lib/jshintrb/lint.rb CHANGED
@@ -1,64 +1,64 @@
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 == :defaults then
36
- @options = DEFAULTS.dup
37
- elsif options.instance_of? Hash then
38
- @options = options.dup
39
- # @options = DEFAULTS.merge(options)
40
- elsif options.nil?
41
- @options = nil
42
- else
43
- raise 'Unsupported option for Jshintrb: ' + options.to_s
44
- end
45
-
46
- @context = ExecJS.compile(File.open(SourcePath, "r:UTF-8").read)
47
- end
48
-
49
- def lint(source)
50
- source = source.respond_to?(:read) ? source.read : source.to_s
51
-
52
- js = []
53
- if @options.nil? then
54
- js << "JSHINT(#{MultiJson.dump(source)});"
55
- else
56
- js << "JSHINT(#{MultiJson.dump(source)}, #{MultiJson.dump(@options)});"
57
- end
58
- js << "return JSHINT.errors;"
59
-
60
- @context.exec js.join("\n")
61
- end
62
-
63
- end
64
- end
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 == :defaults then
36
+ @options = DEFAULTS.dup
37
+ elsif options.instance_of? Hash then
38
+ @options = options.dup
39
+ # @options = DEFAULTS.merge(options)
40
+ elsif options.nil?
41
+ @options = nil
42
+ else
43
+ raise 'Unsupported option for Jshintrb: ' + options.to_s
44
+ end
45
+
46
+ @context = ExecJS.compile(File.open(SourcePath, "r:UTF-8").read)
47
+ end
48
+
49
+ def lint(source)
50
+ source = source.respond_to?(:read) ? source.read : source.to_s
51
+
52
+ js = []
53
+ if @options.nil? then
54
+ js << "JSHINT(#{MultiJson.dump(source)});"
55
+ else
56
+ js << "JSHINT(#{MultiJson.dump(source)}, #{MultiJson.dump(@options)});"
57
+ end
58
+ js << "return JSHINT.errors;"
59
+
60
+ @context.exec js.join("\n")
61
+ end
62
+
63
+ end
64
+ end
@@ -1,30 +1,30 @@
1
- module Jshintrb
2
- module Reporter
3
- class Default
4
-
5
- def format errors, file
6
- result = ''
7
- indent = ''
8
- if file then
9
- indent = ' '
10
- end
11
-
12
- errors.each do |error|
13
- if error.nil? then
14
- result += indent + 'fatal error'
15
- else
16
- result += indent + 'line ' + error["line"].to_s + ', col ' +
17
- error["character"].to_s + ', ' + error["reason"].to_s + "\n"
18
- end
19
- end
20
-
21
- if file && result.size > 0 then
22
- result = 'file: ' + file + "\n" + result
23
- end
24
-
25
- result
26
- end
27
-
28
- end
29
- end
1
+ module Jshintrb
2
+ module Reporter
3
+ class Default
4
+
5
+ def format errors, file
6
+ result = ''
7
+ indent = ''
8
+ if file then
9
+ indent = ' '
10
+ end
11
+
12
+ errors.each do |error|
13
+ if error.nil? then
14
+ result += indent + 'fatal error'
15
+ else
16
+ result += indent + 'line ' + error["line"].to_s + ', col ' +
17
+ error["character"].to_s + ', ' + error["reason"].to_s + "\n"
18
+ end
19
+ end
20
+
21
+ if file && result.size > 0 then
22
+ result = 'file: ' + file + "\n" + result
23
+ end
24
+
25
+ result
26
+ end
27
+
28
+ end
29
+ end
30
30
  end
@@ -1,3 +1,4 @@
1
1
  module Jshintrb
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
+ SUBMODULE = "42f4b4a094fe5a2da39cc9fa8848cad2cbfdc201"
3
4
  end
data/lib/jshintrb.rb CHANGED
File without changes
@@ -1,16 +1,16 @@
1
- # encoding: UTF-8
2
- require "jshintrb"
3
-
4
- def gen_file source, option, value
5
- "/*jshint " + option.to_s + ": " + value.to_s + "*/\n" + source
6
- end
7
-
8
- describe "Jshintrb" do
9
-
10
- it "support options" do
11
- options = {
12
- :bitwise => "var a = 1|1;",
13
- :curly => "while (true)\n var a = 'a';",
1
+ # encoding: UTF-8
2
+ require "jshintrb"
3
+
4
+ def gen_file source, option, value
5
+ "/*jshint " + option.to_s + ": " + value.to_s + "*/\n" + source
6
+ end
7
+
8
+ describe "Jshintrb" do
9
+
10
+ it "support options" do
11
+ options = {
12
+ :bitwise => "var a = 1|1;",
13
+ :curly => "while (true)\n var a = 'a';",
14
14
  # :eqeqeq => true,
15
15
  # :forin => true,
16
16
  # :immed => true,
@@ -24,18 +24,18 @@ describe "Jshintrb" do
24
24
  :undef => "if (a == 'a') { var b = 'b'; }"
25
25
  # :strict => true,
26
26
  # :trailing => true,
27
- # :browser => true
28
- }
29
-
30
- options.each do |option, source|
31
- Jshintrb.lint(source, option => false).length.should eq 0
32
- Jshintrb.lint(source, option => true).length.should eq 1
33
- end
34
-
35
- options.each do |option, source|
36
- Jshintrb.lint(gen_file(source, option, false)).length.should eq 0
37
- Jshintrb.lint(gen_file(source, option, true)).length.should eq 1
38
- end
39
- end
40
-
41
- end
27
+ # :browser => true
28
+ }
29
+
30
+ options.each do |option, source|
31
+ Jshintrb.lint(source, option => false).length.should eq 0
32
+ Jshintrb.lint(source, option => true).length.should eq 1
33
+ end
34
+
35
+ options.each do |option, source|
36
+ Jshintrb.lint(gen_file(source, option, false)).length.should eq 0
37
+ Jshintrb.lint(gen_file(source, option, true)).length.should eq 1
38
+ end
39
+ end
40
+
41
+ end
metadata CHANGED
@@ -1,68 +1,98 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jshintrb
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 6
9
+ version: 0.1.6
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - stereobooster
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-05-07 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rspec
16
- requirement: &29479944 !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: submodule
35
+ requirement: &id002 !ruby/object:Gem::Requirement
17
36
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
22
43
  type: :development
23
44
  prerelease: false
24
- version_requirements: *29479944
25
- - !ruby/object:Gem::Dependency
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
26
47
  name: rake
27
- requirement: &29479500 !ruby/object:Gem::Requirement
48
+ requirement: &id003 !ruby/object:Gem::Requirement
28
49
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
33
56
  type: :runtime
34
57
  prerelease: false
35
- version_requirements: *29479500
36
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
37
60
  name: multi_json
38
- requirement: &29478960 !ruby/object:Gem::Requirement
61
+ requirement: &id004 !ruby/object:Gem::Requirement
39
62
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '1.3'
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 1
68
+ - 3
69
+ version: "1.3"
44
70
  type: :runtime
45
71
  prerelease: false
46
- version_requirements: *29478960
47
- - !ruby/object:Gem::Dependency
72
+ version_requirements: *id004
73
+ - !ruby/object:Gem::Dependency
48
74
  name: execjs
49
- requirement: &29478636 !ruby/object:Gem::Requirement
75
+ requirement: &id005 !ruby/object:Gem::Requirement
50
76
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
55
83
  type: :runtime
56
84
  prerelease: false
57
- version_requirements: *29478636
58
- description: Ruby wrapper for JSHint. The main difference from jshint gem it does
59
- not depend on Java. Instead, it uses ExecJS
60
- email:
85
+ version_requirements: *id005
86
+ description: Ruby wrapper for JSHint. The main difference from jshint gem it does not depend on Java. Instead, it uses ExecJS
87
+ email:
61
88
  - stereobooster@gmail.com
62
89
  executables: []
90
+
63
91
  extensions: []
92
+
64
93
  extra_rdoc_files: []
65
- files:
94
+
95
+ files:
66
96
  - .gitignore
67
97
  - .gitmodules
68
98
  - .travis.yml
@@ -77,34 +107,39 @@ files:
77
107
  - lib/jshintrb/reporter/default.rb
78
108
  - lib/jshintrb/version.rb
79
109
  - spec/jshintrb_spec.rb
110
+ has_rdoc: true
80
111
  homepage: https://github.com/stereobooster/jshintrb
81
112
  licenses: []
113
+
82
114
  post_install_message:
83
115
  rdoc_options: []
84
- require_paths:
116
+
117
+ require_paths:
85
118
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
119
+ required_ruby_version: !ruby/object:Gem::Requirement
87
120
  none: false
88
- requirements:
89
- - - ! '>='
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- segments:
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: -591355473
125
+ segments:
93
126
  - 0
94
- hash: 266408271
95
- required_rubygems_version: !ruby/object:Gem::Requirement
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
129
  none: false
97
- requirements:
98
- - - ! '>='
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- segments:
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: -591355473
134
+ segments:
102
135
  - 0
103
- hash: 266408271
136
+ version: "0"
104
137
  requirements: []
105
- rubyforge_project: jshintrb
106
- rubygems_version: 1.8.15
138
+
139
+ rubyforge_project:
140
+ rubygems_version: 1.3.7
107
141
  signing_key:
108
142
  specification_version: 3
109
143
  summary: Ruby wrapper for JSHint
110
144
  test_files: []
145
+