checker 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +48 -30
- data/checker.gemspec +1 -1
- data/lib/checker.rb +13 -9
- data/lib/checker/cli.rb +10 -2
- data/lib/checker/helper.rb +17 -0
- data/lib/checker/installator.rb +46 -0
- data/lib/checker/modules/base.rb +9 -3
- data/lib/checker/modules/coffeescript.rb +1 -1
- data/lib/checker/modules/conflict.rb +19 -0
- data/lib/checker/modules/haml.rb +1 -1
- data/lib/checker/modules/javascript.rb +1 -1
- data/lib/checker/modules/pry.rb +1 -1
- data/lib/checker/modules/ruby.rb +1 -1
- data/lib/checker/modules/sass.rb +2 -2
- data/lib/checker/modules/slim.rb +1 -1
- data/lib/checker/modules/yaml.rb +1 -1
- data/lib/checker/version.rb +1 -1
- data/spec/checker/fixtures/conflict/with_conflict.rb +5 -0
- data/spec/checker/fixtures/conflict/without_conflict.rb +2 -0
- data/spec/checker/modules/base_spec.rb +24 -0
- data/spec/checker/modules/conflict_spec.rb +23 -0
- data/spec/checker/modules/sass_spec.rb +18 -0
- data/templates/checker-prepare-commit-msg +11 -0
- metadata +9 -4
- data/bin/prepare-commit-msg +0 -9
data/README.md
CHANGED
@@ -9,10 +9,11 @@ Checker is available in rubygems, so you just need to do:
|
|
9
9
|
```
|
10
10
|
gem install checker
|
11
11
|
```
|
12
|
-
If you are using bundler, you can add it to your project via `Gemfile` file (best to put it under `:development` group)
|
12
|
+
If you are using bundler, you can add it to your project via `Gemfile` file (best to put it under `:development` group).
|
13
|
+
Since checker is a command-line utility, there is no need to load it up in the application:
|
13
14
|
```ruby
|
14
15
|
group :development do
|
15
|
-
gem 'checker'
|
16
|
+
gem 'checker', :required => false
|
16
17
|
end
|
17
18
|
```
|
18
19
|
|
@@ -20,10 +21,10 @@ After installing the gem please follow [Git hook](#git-hook) section for further
|
|
20
21
|
|
21
22
|
### Git hook
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
All you need to do is type in `checker install` and it will automatically install the prepare-commit-msg hook
|
25
|
+
to your current git project. It will look like this:
|
25
26
|
|
26
|
-
```
|
27
|
+
```
|
27
28
|
#!/bin/bash
|
28
29
|
checker
|
29
30
|
|
@@ -31,40 +32,36 @@ if [ $? == 1 ]; then
|
|
31
32
|
exit 1
|
32
33
|
fi
|
33
34
|
|
34
|
-
echo ":checkered_flag:" >> $1
|
35
|
-
```
|
36
|
-
|
37
|
-
you can also prepend the flag to the first line of commit message, by changing last line with:
|
38
|
-
|
39
|
-
``` bash
|
40
35
|
text=`echo -n ':checkered_flag: '; cat $1`
|
41
36
|
echo $text > $1
|
42
37
|
```
|
43
38
|
|
44
|
-
|
45
|
-
To just check your source code every time you commit, add to your `.git/hooks/pre-commit` line:
|
46
|
-
|
47
|
-
``` bash
|
48
|
-
#!/bin/bash
|
49
|
-
checker
|
50
|
-
```
|
51
|
-
|
52
|
-
Use only either one hook.
|
53
|
-
|
39
|
+
If you don't want your commits be prepended by checkered flag you can remove two last lines from the prepare-commit-msg hook.
|
54
40
|
|
55
|
-
|
41
|
+
Now checker will halt the commit if it finds problem with source code. Couple examples:
|
56
42
|
|
57
|
-
|
58
|
-
|
59
|
-
|
43
|
+
#### pry
|
44
|
+
```
|
45
|
+
[ PRY - 1 files ]
|
46
|
+
Checking app/models/user.rb... [FAIL]
|
47
|
+
46:binding.pry
|
60
48
|
```
|
61
49
|
|
62
|
-
|
50
|
+
#### conflict
|
51
|
+
```
|
52
|
+
[ CONFLICT - 1 files ]
|
53
|
+
Checking a.bad.scss... [FAIL]
|
54
|
+
4:<<<<<<< Updated upstream
|
55
|
+
30:>>>>>>> Stashed changes
|
56
|
+
```
|
63
57
|
|
58
|
+
#### sass
|
64
59
|
```
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
[ SASS - 1 files ]
|
61
|
+
Checking a.bad.scss... [FAIL]
|
62
|
+
Syntax error: Invalid CSS after "qwe:": expected pseudoclass or pseudoelement, was "asd:"
|
63
|
+
on line 1 of .checker-cache/3cc74408b797b92e79207a64d97ae429
|
64
|
+
Use --trace for backtrace.
|
68
65
|
```
|
69
66
|
|
70
67
|
### Advanced usage
|
@@ -75,7 +72,28 @@ To check only specific filetypes on commit, use `git config` :
|
|
75
72
|
git config checker.check 'ruby, haml, coffeescript'
|
76
73
|
```
|
77
74
|
|
78
|
-
Available options
|
75
|
+
### Available options
|
76
|
+
|
77
|
+
#### ruby
|
78
|
+
Checks for correct syntax in ruby (.rb) files
|
79
|
+
|
80
|
+
#### haml
|
81
|
+
Checks for correct syntax in haml files
|
82
|
+
|
83
|
+
#### pry
|
84
|
+
Checks for any occurence of `binding.pry` or `binding.remote_pry`
|
85
|
+
|
86
|
+
#### coffeescript
|
87
|
+
Checks for correct syntax in coffeescript (.coffee) files
|
88
|
+
|
89
|
+
#### sass
|
90
|
+
Checks for correct syntax in sass and scss files
|
91
|
+
|
92
|
+
#### slim
|
93
|
+
Checks for correct syntax in slim files
|
94
|
+
|
95
|
+
#### conflict
|
96
|
+
Checks for any occurence of git conflicts when merging (looks for `<<<<<<< ` or `>>>>>>> `)
|
79
97
|
|
80
98
|
### Dependencies
|
81
99
|
|
data/checker.gemspec
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/checker/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'checker'
|
6
6
|
s.version = Checker::VERSION
|
7
|
-
s.date = '2012-
|
7
|
+
s.date = '2012-09-19'
|
8
8
|
s.summary = "Syntax checker for various files"
|
9
9
|
s.description = "A collection of modules which every is designed to check syntax for specific files."
|
10
10
|
s.authors = ["Jacek Jakubik", "Tomasz Pewiński"]
|
data/lib/checker.rb
CHANGED
@@ -3,13 +3,17 @@ require 'digest/md5'
|
|
3
3
|
|
4
4
|
require 'checker/core_ext'
|
5
5
|
require 'checker/version'
|
6
|
+
require 'checker/installator'
|
7
|
+
require 'checker/helper'
|
6
8
|
|
7
|
-
|
8
|
-
require "checker/modules
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
%w[base ruby haml slim pry coffeescript javascript sass yaml conflict].each do |mod|
|
10
|
+
require "checker/modules/#{mod}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def debug_mode?
|
14
|
+
ENV['CHECKER_DEBUG'].to_s == "1"
|
15
|
+
end
|
16
|
+
|
17
|
+
if debug_mode?
|
18
|
+
puts "Running checker with debug mode!".colorize(:yellow)
|
19
|
+
end
|
data/lib/checker/cli.rb
CHANGED
@@ -7,7 +7,15 @@ module Checker
|
|
7
7
|
if ARGV.size == 0
|
8
8
|
modules = get_modules_to_check
|
9
9
|
else
|
10
|
-
|
10
|
+
if ARGV[0] == "install"
|
11
|
+
Checker::Installator.install!
|
12
|
+
elsif ARGV[0] == "help"
|
13
|
+
Checker::Helper.show_help!
|
14
|
+
elsif ARGV[0] == "modules"
|
15
|
+
Checker::Helper.show_modules!(self.available_modules)
|
16
|
+
else
|
17
|
+
modules = ARGV.map(&:downcase)
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
if modules.empty? || modules.include?('all')
|
@@ -35,7 +43,7 @@ module Checker
|
|
35
43
|
exit (results.all_true? ? 0 : 1)
|
36
44
|
end
|
37
45
|
|
38
|
-
|
46
|
+
protected
|
39
47
|
def available_modules
|
40
48
|
Checker::Modules.constants.map(&:to_s).map(&:downcase) - ['base']
|
41
49
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Checker
|
2
|
+
class Helper
|
3
|
+
def self.show_help!
|
4
|
+
puts "Checker version #{Checker::VERSION}"
|
5
|
+
puts "* install - type 'checker install' to install git pre-commit-hook"
|
6
|
+
puts "* modules - type 'checker modules' to see available modules"
|
7
|
+
puts "* checks - type 'checker [module name]' to check your current git stage"
|
8
|
+
puts "* help - type 'checker help' to see this message :)"
|
9
|
+
exit 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.show_modules!(modules)
|
13
|
+
puts "Available modules are: all, #{modules.join(", ")}"
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Checker
|
2
|
+
class Installator
|
3
|
+
def self.template
|
4
|
+
dir = File.dirname(__FILE__) + "/../.."
|
5
|
+
open(dir + "/templates/checker-prepare-commit-msg").read
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.install!
|
9
|
+
hooks_dir = "#{Dir.pwd}/.git/hooks"
|
10
|
+
|
11
|
+
unless Dir.exist?(hooks_dir)
|
12
|
+
puts "Git Hooks dir not found. Are you sure you are inside project with git?"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
pre_commit = "#{hooks_dir}/prepare-commit-msg"
|
17
|
+
if File.exist?(pre_commit)
|
18
|
+
puts "Appending checker script to existing prepare-commit-msg hook..."
|
19
|
+
begin
|
20
|
+
open(pre_commit, 'a') do |f|
|
21
|
+
f.puts(self.template)
|
22
|
+
f.chmod(0755)
|
23
|
+
end
|
24
|
+
rescue Exception => e
|
25
|
+
puts "Couldn't append checker script: #{e.message}"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
exit 0
|
29
|
+
else
|
30
|
+
tmp = self.template
|
31
|
+
str = "#!/bin/bash \n #{tmp}"
|
32
|
+
begin
|
33
|
+
open(pre_commit, "w") do |f|
|
34
|
+
f.puts(str)
|
35
|
+
f.chmod(0755)
|
36
|
+
end
|
37
|
+
rescue Exception => e
|
38
|
+
puts "Couldn't write checker script: #{e.message}"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
puts "Script installed!"
|
42
|
+
exit 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/checker/modules/base.rb
CHANGED
@@ -64,10 +64,16 @@ module Checker
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
def check_one(filename, options = {})
|
68
|
+
puts "Called from #{self.class} - extend me in here!"
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
67
72
|
def check_one_file file_name
|
68
73
|
checksum = ::Digest::MD5.hexdigest(file_name)
|
74
|
+
puts file_name if debug_mode?
|
69
75
|
checkout_file(file_name, checksum)
|
70
|
-
check_one(checkout_file_name(checksum))
|
76
|
+
check_one(checkout_file_name(checksum), :extension => File.extname(file_name))
|
71
77
|
end
|
72
78
|
|
73
79
|
def self.extensions *args
|
@@ -104,6 +110,7 @@ module Checker
|
|
104
110
|
end
|
105
111
|
|
106
112
|
def execute(cmd)
|
113
|
+
puts cmd if debug_mode?
|
107
114
|
io = IO.popen(cmd)
|
108
115
|
Process.wait(io.pid)
|
109
116
|
@buffer ||= ""
|
@@ -144,9 +151,8 @@ module Checker
|
|
144
151
|
end
|
145
152
|
|
146
153
|
def rvm_command(command)
|
147
|
-
rvm_path = ENV['rvm_path'].to_s
|
148
154
|
rvm_gem = ENV['GEM_HOME'].to_s
|
149
|
-
rvm_version = rvm_gem.gsub(
|
155
|
+
rvm_version = rvm_gem.gsub(/.+rvm\/gems\//, "")
|
150
156
|
|
151
157
|
"#{rvm_shell} '#{rvm_version}' -c '#{command}'"
|
152
158
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Conflict < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
[check_for_conflict_start(file), check_for_conflict_end(file)].all_true?
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_for_conflict_start(file)
|
11
|
+
!plain_command("grep -n \"<<<<<<< \" #{file}", :bundler => false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_for_conflict_end(file)
|
15
|
+
!plain_command("grep -n \">>>>>>> \" #{file}", :bundler => false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/checker/modules/haml.rb
CHANGED
data/lib/checker/modules/pry.rb
CHANGED
data/lib/checker/modules/ruby.rb
CHANGED
data/lib/checker/modules/sass.rb
CHANGED
@@ -3,8 +3,8 @@ module Checker
|
|
3
3
|
class Sass < Base
|
4
4
|
extensions 'scss', 'sass'
|
5
5
|
private
|
6
|
-
def check_one(file)
|
7
|
-
plain_command("sass #{file}")
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
plain_command("sass #{"--scss" if opts[:extension] == ".scss"} -c #{file}")
|
8
8
|
end
|
9
9
|
|
10
10
|
def check_for_executable
|
data/lib/checker/modules/slim.rb
CHANGED
data/lib/checker/modules/yaml.rb
CHANGED
data/lib/checker/version.rb
CHANGED
@@ -25,5 +25,29 @@ describe Checker::Modules::Base do
|
|
25
25
|
Checker::Modules::Base.new.send(:rvm_command, "test").should == "/Users/test/.rvm/bin/rvm-shell 'some_ruby_version@v2' -c 'test'"
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
context "using different rvm_path (system-wide rvm)" do
|
30
|
+
before do
|
31
|
+
ENV.stub!(:[]).with("rvm_path").and_return "/usr/lib/rvm"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "uses no gemsets" do
|
35
|
+
ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version"
|
36
|
+
|
37
|
+
Checker::Modules::Base.new.send(:rvm_command, "test").should == "/usr/lib/rvm/bin/rvm-shell 'some_ruby_version' -c 'test'"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "uses global gemset" do
|
41
|
+
ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version@global"
|
42
|
+
|
43
|
+
Checker::Modules::Base.new.send(:rvm_command, "test").should == "/usr/lib/rvm/bin/rvm-shell 'some_ruby_version@global' -c 'test'"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "uses some other gemset" do
|
47
|
+
ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version@v2"
|
48
|
+
|
49
|
+
Checker::Modules::Base.new.send(:rvm_command, "test").should == "/usr/lib/rvm/bin/rvm-shell 'some_ruby_version@v2' -c 'test'"
|
50
|
+
end
|
51
|
+
end
|
28
52
|
end
|
29
53
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Checker::Modules::Conflict do
|
4
|
+
it 'checks all files' do
|
5
|
+
files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee']
|
6
|
+
mod = Checker::Modules::Conflict.new(files)
|
7
|
+
mod.stub(:check_one).and_return(true)
|
8
|
+
mod.should_receive(:check_one).exactly(6).times
|
9
|
+
mod.check
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does find git conflict" do
|
13
|
+
files = [fixture("conflict", "with_conflict.rb")]
|
14
|
+
mod = Checker::Modules::Conflict.new(files)
|
15
|
+
mod.check.should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does not find git conflict" do
|
19
|
+
files = [fixture("conflict", "without_conflict.rb")]
|
20
|
+
mod = Checker::Modules::Conflict.new(files)
|
21
|
+
mod.check.should be_true
|
22
|
+
end
|
23
|
+
end
|
@@ -18,4 +18,22 @@ describe Checker::Modules::Sass do
|
|
18
18
|
mod.should_not_receive(:check_one_file).with('c.r')
|
19
19
|
mod.check
|
20
20
|
end
|
21
|
+
|
22
|
+
context "different extensions" do
|
23
|
+
it "gives proper command to sass module while checking .sass files" do
|
24
|
+
files = ["a.sass"]
|
25
|
+
mod = Checker::Modules::Sass.new(files)
|
26
|
+
mod.stub(:check_for_executable).and_return(true)
|
27
|
+
mod.should_receive(:plain_command).with("sass -c .checker-cache/69cb154f5eeff19216d2879872ba6569")
|
28
|
+
mod.check
|
29
|
+
end
|
30
|
+
|
31
|
+
it "gives proper command to sass module while checking .scss files" do
|
32
|
+
files = ["a.scss"]
|
33
|
+
mod = Checker::Modules::Sass.new(files)
|
34
|
+
mod.stub(:check_for_executable).and_return(true)
|
35
|
+
mod.should_receive(:plain_command).with("sass --scss -c .checker-cache/13dbadc466ed1f9bdfbb2b545e45d012")
|
36
|
+
mod.check
|
37
|
+
end
|
38
|
+
end
|
21
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: colorize
|
@@ -35,7 +35,6 @@ email:
|
|
35
35
|
- tomasz.pewinski@netguru.pl
|
36
36
|
executables:
|
37
37
|
- checker
|
38
|
-
- prepare-commit-msg
|
39
38
|
extensions: []
|
40
39
|
extra_rdoc_files: []
|
41
40
|
files:
|
@@ -48,13 +47,15 @@ files:
|
|
48
47
|
- README.md
|
49
48
|
- Rakefile
|
50
49
|
- bin/checker
|
51
|
-
- bin/prepare-commit-msg
|
52
50
|
- checker.gemspec
|
53
51
|
- lib/checker.rb
|
54
52
|
- lib/checker/cli.rb
|
55
53
|
- lib/checker/core_ext.rb
|
54
|
+
- lib/checker/helper.rb
|
55
|
+
- lib/checker/installator.rb
|
56
56
|
- lib/checker/modules/base.rb
|
57
57
|
- lib/checker/modules/coffeescript.rb
|
58
|
+
- lib/checker/modules/conflict.rb
|
58
59
|
- lib/checker/modules/haml.rb
|
59
60
|
- lib/checker/modules/javascript.rb
|
60
61
|
- lib/checker/modules/pry.rb
|
@@ -64,6 +65,8 @@ files:
|
|
64
65
|
- lib/checker/modules/yaml.rb
|
65
66
|
- lib/checker/version.rb
|
66
67
|
- spec/checker/cli_spec.rb
|
68
|
+
- spec/checker/fixtures/conflict/with_conflict.rb
|
69
|
+
- spec/checker/fixtures/conflict/without_conflict.rb
|
67
70
|
- spec/checker/fixtures/pry/with_both.rb
|
68
71
|
- spec/checker/fixtures/pry/with_pry.rb
|
69
72
|
- spec/checker/fixtures/pry/with_pry_remote.rb
|
@@ -77,6 +80,7 @@ files:
|
|
77
80
|
- spec/checker/fixtures/yaml/good.yaml
|
78
81
|
- spec/checker/modules/base_spec.rb
|
79
82
|
- spec/checker/modules/coffeescript_spec.rb
|
83
|
+
- spec/checker/modules/conflict_spec.rb
|
80
84
|
- spec/checker/modules/haml_spec.rb
|
81
85
|
- spec/checker/modules/javascript_spec.rb
|
82
86
|
- spec/checker/modules/pry_spec.rb
|
@@ -85,6 +89,7 @@ files:
|
|
85
89
|
- spec/checker/modules/slim_spec.rb
|
86
90
|
- spec/checker/modules/yaml_spec.rb
|
87
91
|
- spec/spec_helper.rb
|
92
|
+
- templates/checker-prepare-commit-msg
|
88
93
|
homepage: http://github.com/netguru/checker
|
89
94
|
licenses: []
|
90
95
|
post_install_message:
|