check_js 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/check_js +36 -0
- data/bin/check_js_hook +7 -0
- data/check_js.gemspec +69 -0
- data/lib/check_js/hook.rb +29 -0
- data/lib/check_js.rb +47 -0
- data/lib/jar/js_compiler.jar +0 -0
- data/spec/check_js_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +146 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.5.2)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 David A. Cuadrado
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= check_js
|
2
|
+
|
3
|
+
check js compatibility with browsers
|
4
|
+
|
5
|
+
== Contributing to check_js
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 David A. Cuadrado. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "check_js"
|
16
|
+
gem.homepage = "http://github.com/dcu/check_js"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{small utility to check the JavaScript syntax of a list of files}
|
19
|
+
gem.description = %Q{small utility to check the JavaScript syntax of a list of files. it also allow to install it as a git hook}
|
20
|
+
gem.email = "krawek@gmail.com"
|
21
|
+
gem.authors = ["David A. Cuadrado"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "check_js #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/check_js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'check_js'
|
6
|
+
|
7
|
+
if !CheckJS.check_java
|
8
|
+
$stderr.puts "Java was not found on your system. please install it and try again"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
files = ARGV
|
13
|
+
if files.empty?
|
14
|
+
puts "\e[32m>>>>\e[0m Parsing all files since no file was provided"
|
15
|
+
if File.directory?("public/javascripts")
|
16
|
+
files = Dir.glob("public/javascripts/**/**/*.js")
|
17
|
+
else
|
18
|
+
files = Dir.glob("**/**/*.js")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ok = true
|
23
|
+
|
24
|
+
files.each do |file_path|
|
25
|
+
puts "\e[32m>>>>\e[0m Checking syntax for #{file_path} ..."
|
26
|
+
ret = CheckJS.check_syntax(file_path)
|
27
|
+
ok = ok && ret
|
28
|
+
puts ""
|
29
|
+
|
30
|
+
sleep 0.2
|
31
|
+
end
|
32
|
+
|
33
|
+
if !ok
|
34
|
+
puts "\e[31mERROR:\e[0m Aborting commit..."
|
35
|
+
exit 255
|
36
|
+
end
|
data/bin/check_js_hook
ADDED
data/check_js.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{check_js}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David A. Cuadrado"]
|
12
|
+
s.date = %q{2011-01-14}
|
13
|
+
s.description = %q{small utility to check the JavaScript syntax of a list of files. it also allow to install it as a git hook}
|
14
|
+
s.email = %q{krawek@gmail.com}
|
15
|
+
s.executables = ["check_js", "check_js_hook"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/check_js",
|
30
|
+
"bin/check_js_hook",
|
31
|
+
"lib/check_js.rb",
|
32
|
+
"lib/check_js/hook.rb",
|
33
|
+
"lib/jar/js_compiler.jar",
|
34
|
+
"spec/check_js_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/dcu/check_js}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{small utility to check the JavaScript syntax of a list of files}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/check_js_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# VERSION: 0
|
3
|
+
|
4
|
+
working_dir = File.expand_path("../../../", __FILE__)
|
5
|
+
|
6
|
+
Dir.chdir(working_dir) do
|
7
|
+
files = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
|
8
|
+
files += `git diff --name-only --diff-filter=ACM`.split("\n")
|
9
|
+
files.uniq!
|
10
|
+
|
11
|
+
files.map! do |f|
|
12
|
+
f.strip!
|
13
|
+
puts f
|
14
|
+
if f =~ /\.js$/
|
15
|
+
"'#{File.join(working_dir, f)}'"
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end.compact!
|
20
|
+
|
21
|
+
if !files.empty?
|
22
|
+
ok = true
|
23
|
+
Dir.chdir(File.expand_path("../../../", __FILE__)) do
|
24
|
+
ok = system("check_js #{files.join(' ')}")
|
25
|
+
end
|
26
|
+
|
27
|
+
exit(1) if !ok
|
28
|
+
end
|
29
|
+
end
|
data/lib/check_js.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module CheckJS
|
4
|
+
COMPILER = File.expand_path("../jar/js_compiler.jar", __FILE__)
|
5
|
+
|
6
|
+
def self.check_java
|
7
|
+
system("java -h >/dev/null 2>/dev/null")
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.check_syntax(file)
|
11
|
+
cmd = "java -jar #{CheckJS::COMPILER} --js #{"'#{file}'"} >/dev/null"
|
12
|
+
File.open(file, "r") do |f|
|
13
|
+
count = 0
|
14
|
+
f.each_line do |line|
|
15
|
+
if line =~ /console\.log\s*\(/
|
16
|
+
$stderr.puts "#{file}:#{count}: WARNING - Suspicious code. console.log() only works when the inspector is enabled"
|
17
|
+
$stderr.puts " #{line.strip}"
|
18
|
+
end
|
19
|
+
count += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
system(cmd)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.install
|
26
|
+
if File.exist?(self.hooks_path)
|
27
|
+
if File.exist?(self.pre_commit_path) && File.read(self.pre_commit_path) !~ /check_js/
|
28
|
+
cp_path = self.pre_commit_path+".backup"
|
29
|
+
puts "Creating a copy of your current hook on #{cp_path}"
|
30
|
+
FileUtils.mv(self.pre_commit_path, cp_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
File.open(self.pre_commit_path, "w") do |f|
|
34
|
+
f << File.read(File.expand_path("../check_js/hook.rb", __FILE__))
|
35
|
+
end
|
36
|
+
FileUtils.chmod(0755, self.pre_commit_path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.hooks_path
|
41
|
+
".git/hooks"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.pre_commit_path
|
45
|
+
"#{self.hooks_path}/pre-commit"
|
46
|
+
end
|
47
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'check_js'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: check_js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David A. Cuadrado
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-14 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: 2.3.0
|
33
|
+
requirement: *id001
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
name: rspec
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 23
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
49
|
+
requirement: *id002
|
50
|
+
prerelease: false
|
51
|
+
type: :development
|
52
|
+
name: bundler
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 5
|
63
|
+
- 2
|
64
|
+
version: 1.5.2
|
65
|
+
requirement: *id003
|
66
|
+
prerelease: false
|
67
|
+
type: :development
|
68
|
+
name: jeweler
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirement: *id004
|
80
|
+
prerelease: false
|
81
|
+
type: :development
|
82
|
+
name: rcov
|
83
|
+
description: small utility to check the JavaScript syntax of a list of files. it also allow to install it as a git hook
|
84
|
+
email: krawek@gmail.com
|
85
|
+
executables:
|
86
|
+
- check_js
|
87
|
+
- check_js_hook
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.rdoc
|
93
|
+
files:
|
94
|
+
- .document
|
95
|
+
- .rspec
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.rdoc
|
100
|
+
- Rakefile
|
101
|
+
- VERSION
|
102
|
+
- bin/check_js
|
103
|
+
- bin/check_js_hook
|
104
|
+
- check_js.gemspec
|
105
|
+
- lib/check_js.rb
|
106
|
+
- lib/check_js/hook.rb
|
107
|
+
- lib/jar/js_compiler.jar
|
108
|
+
- spec/check_js_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://github.com/dcu/check_js
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.3.7
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: small utility to check the JavaScript syntax of a list of files
|
144
|
+
test_files:
|
145
|
+
- spec/check_js_spec.rb
|
146
|
+
- spec/spec_helper.rb
|