jslint-johnson 1.0.0 → 1.0.1

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.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "johnson", "~> 1.2.0"
4
+ gem "rake", "~> 0.8.7"
5
+ gem "jeweler", "~> 1.5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ johnson (1.2.0)
10
+ rake (0.8.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ jeweler (~> 1.5.0)
17
+ johnson (~> 1.2.0)
18
+ rake (~> 0.8.7)
@@ -0,0 +1,6 @@
1
+ module JSLintJohnson end
2
+
3
+ require File.expand_path("jslint-johnson/runner", File.dirname(__FILE__))
4
+ require File.expand_path("jslint-johnson/lint_error", File.dirname(__FILE__))
5
+ require File.expand_path("jslint-johnson/rake_task", File.dirname(__FILE__))
6
+ require File.expand_path("jslint-johnson/formatter", File.dirname(__FILE__))
@@ -0,0 +1,46 @@
1
+
2
+ module JSLintJohnson
3
+ class Formatter
4
+ attr_reader :output_stream
5
+
6
+ def initialize(stream)
7
+ @output_stream = stream
8
+ end
9
+
10
+ def tick(errors)
11
+ output_stream.print(errors.any?? "*" : ".")
12
+ end
13
+
14
+ def summary(tested_files, lint_result)
15
+ if lint_result.keys.any?
16
+ print_error_summary(lint_result)
17
+ output_stream.print "\n"
18
+ end
19
+
20
+ print_count_summary(tested_files, lint_result)
21
+ end
22
+
23
+ private
24
+ def print_error_summary(result)
25
+ out = output_stream
26
+
27
+ out.print "\nFailures:\n\n"
28
+
29
+ result.each do |file, errors|
30
+ out.print "#{file}:\n"
31
+ errors.each do |error|
32
+ out.print " line #{error.line_number} character #{error.character} #{error.reason}\n"
33
+ end
34
+ end
35
+ end
36
+
37
+ def print_count_summary(tested_files, lint_result)
38
+ file_count = tested_files.length
39
+ failure_count = lint_result.keys.length
40
+ error_count = lint_result.values.flatten.length
41
+
42
+ output_stream.print "#{file_count} files, #{failure_count} failures, #{error_count} errors\n"
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module JSLintJohnson
3
+ class LintError
4
+ attr_reader :line_number, :character, :reason, :evidence
5
+
6
+ def initialize(jsobject)
7
+ @line_number = jsobject["line"]
8
+ @character = jsobject["character"]
9
+ @reason = jsobject["reason"]
10
+ @evidence = jsobject["evidence"]
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,76 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module JSLintJohnson
5
+ class RakeTask < ::Rake::TaskLib
6
+ # name of the rake task
7
+ attr_accessor :name
8
+
9
+ # description for the task
10
+ attr_accessor :description
11
+
12
+ # inclusion glob pattern for files
13
+ attr_accessor :include_pattern
14
+
15
+ # exclusion glob pattern for files
16
+ attr_accessor :exclude_pattern
17
+
18
+ # output stream for this task
19
+ attr_accessor :output_stream
20
+
21
+ def initialize
22
+ # a default name
23
+ @name = "lint"
24
+
25
+ # a default description
26
+ @description = "Runs the JSLint Test Suite"
27
+
28
+ # by default a glob pattern that will include javascript files found in rails
29
+ @include_pattern = "app/javascripts/**/*.js"
30
+
31
+ # by default a glob pattern which will match no files
32
+ @exclude_pattern = ""
33
+
34
+ # by default use standard output for writing information
35
+ @output_stream = STDOUT
36
+
37
+ # if a block was given allow the block to call elements on this object
38
+ yield self if block_given?
39
+
40
+ # create the rake task
41
+ new_task = task(name) do
42
+ formatter = JSLintJohnson::Formatter.new(output_stream)
43
+
44
+ lint_result = runner.run do |file, errors|
45
+ formatter.tick(errors)
46
+ end
47
+
48
+ # put a separator line in between the ticks and any summary
49
+ output_stream.print "\n"
50
+
51
+ # print a summary of failed files
52
+ formatter.summary(files_to_run, lint_result)
53
+ end
54
+
55
+ # assign the description to the rake task
56
+ new_task.comment = description
57
+ end
58
+
59
+ #
60
+ # Returns a list of all files to run, sorted
61
+ #
62
+ def files_to_run
63
+ included_files = Dir.glob(include_pattern)
64
+ excluded_files = Dir.glob(exclude_pattern)
65
+
66
+ (included_files - excluded_files).sort
67
+ end
68
+
69
+ private
70
+
71
+ def runner
72
+ JSLintJohnson::Runner.new(files_to_run)
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,83 @@
1
+ require 'johnson'
2
+
3
+ module JSLintJohnson
4
+ class Runner
5
+ JSLintLibraryFilename = File.expand_path("js/jslint.js", File.dirname(__FILE__))
6
+
7
+ attr_reader :file_list
8
+
9
+ def initialize(files)
10
+ if(files.is_a?(Array))
11
+ @file_list = files
12
+ else
13
+ @file_list = [files]
14
+ end
15
+
16
+ end
17
+
18
+ def run
19
+ # make sure all files exit
20
+ file_list.each do |file|
21
+ raise "file not found: #{file}" unless File.exist?(file)
22
+ end
23
+
24
+ result = {}
25
+
26
+ file_list.each do |file|
27
+ errors = jslint(File.read(file))
28
+
29
+ yield(file, errors) if block_given?
30
+
31
+ next if errors.empty?
32
+
33
+ result[file] = errors
34
+ end
35
+
36
+ result
37
+ end
38
+
39
+ def runtime
40
+ @runtime ||= lambda do
41
+ runtime = Johnson::Runtime.new
42
+
43
+ # load the jslint library into the runtime
44
+ runtime.evaluate("eval(Ruby.File.read('#{JSLintLibraryFilename}'));")
45
+
46
+ # return the runtime
47
+ runtime
48
+ end.call
49
+ end
50
+
51
+ def jslint(source_code)
52
+ jslint_function.call(source_code, jslint_options)
53
+ jslint_result
54
+ end
55
+
56
+ def jslint_function
57
+ runtime["JSLINT"];
58
+ end
59
+
60
+ def jslint_result
61
+ runtime["JSLINT"]["errors"].to_a.map do |error_object|
62
+ JSLintJohnson::LintError.new(error_object)
63
+ end
64
+ end
65
+
66
+ def jslint_options
67
+ {
68
+ "bitwise" => true,
69
+ "eqeqeq" => true,
70
+ "immed" => true,
71
+ "newcap" => true,
72
+ "nomen" => true,
73
+ "onevar" => true,
74
+ "plusplus" => true,
75
+ "regexp" => true,
76
+ "rhino" => true,
77
+ "undef" => true,
78
+ "white" => true
79
+ }
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module JSLintJohnson
3
+ module Version
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ PATCH = 1
7
+ BUILD = nil
8
+
9
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
10
+ end
11
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jslint-johnson
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - William Howard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-28 00:00:00 +02:00
18
+ date: 2011-06-29 00:00:00 +02:00
19
19
  default_executable: jslint-johnson
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,9 +51,25 @@ dependencies:
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: johnson
54
+ name: jeweler
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 0
66
+ version: 1.5.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: johnson
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
57
73
  none: false
58
74
  requirements:
59
75
  - - ~>
@@ -65,7 +81,7 @@ dependencies:
65
81
  - 0
66
82
  version: 1.2.0
67
83
  type: :runtime
68
- version_requirements: *id003
84
+ version_requirements: *id004
69
85
  description: " - Ruby gem wrapper for a JSLint CLI.\n - Uses the Johnson library for performance.\n - Targeted for usage in CI environments.\n - Thoroughly tested.\n"
70
86
  email: whoward.tke@gmail.com
71
87
  executables:
@@ -75,6 +91,15 @@ extensions: []
75
91
  extra_rdoc_files: []
76
92
 
77
93
  files:
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - bin/jslint-johnson
97
+ - lib/jslint-johnson.rb
98
+ - lib/jslint-johnson/formatter.rb
99
+ - lib/jslint-johnson/lint_error.rb
100
+ - lib/jslint-johnson/rake_task.rb
101
+ - lib/jslint-johnson/runner.rb
102
+ - lib/jslint-johnson/version.rb
78
103
  - test/helper.rb
79
104
  - test/suite.rb
80
105
  - test/test_cli.rb
@@ -82,7 +107,6 @@ files:
82
107
  - test/test_lint_error.rb
83
108
  - test/test_runner.rb
84
109
  - test/test_task.rb
85
- - bin/jslint-johnson
86
110
  has_rdoc: true
87
111
  homepage: http://github.com/whoward/jslint-johnson
88
112
  licenses: []