checker 0.0.3 → 0.0.4
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/CHANGELOG +24 -0
- data/README.md +39 -0
- data/checker.gemspec +3 -2
- data/lib/checker.rb +3 -2
- data/lib/checker/cli/execute.rb +0 -19
- data/lib/checker/modules/coffeescript.rb +4 -4
- data/lib/checker/modules/haml.rb +3 -3
- data/lib/checker/modules/pry.rb +9 -4
- data/lib/checker/modules/ruby.rb +3 -7
- data/lib/checker/modules/sass.rb +8 -6
- data/lib/checker/utils.rb +50 -7
- metadata +16 -4
- data/README +0 -10
data/CHANGELOG
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
=== version 0.0.4 (released 2012-07-09)
|
2
|
+
|
3
|
+
* added colors
|
4
|
+
* fix for sass
|
5
|
+
* should work on rbenv rbenv (thx Tomasz Pewiński)
|
6
|
+
|
7
|
+
=== version 0.0.3 (released 2012-06-07)
|
8
|
+
|
9
|
+
* fix for ruby checker
|
10
|
+
* added coffeescript checker
|
11
|
+
* added sass checker
|
12
|
+
|
13
|
+
=== version 0.0.2 (released 2012-04-20)
|
14
|
+
|
15
|
+
* added ruby checker
|
16
|
+
* added pry checker
|
17
|
+
* all checker - checks all checkers
|
18
|
+
* git config for selecting checkers
|
19
|
+
|
20
|
+
|
21
|
+
=== version 0.0.1 (released 2012-04-03)
|
22
|
+
|
23
|
+
* initial version
|
24
|
+
* haml checker
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Checker
|
2
|
+
|
3
|
+
A collection of modules for which every is designed to check syntax in files to be commited via git.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### Git hook
|
8
|
+
|
9
|
+
To check your source code every time you commit, add to your .git/hooks/pre-commit line:
|
10
|
+
|
11
|
+
```
|
12
|
+
checker
|
13
|
+
```
|
14
|
+
|
15
|
+
Don't forget to make the hook file executable:
|
16
|
+
|
17
|
+
``` bash
|
18
|
+
chmod +x .git/hooks/pre-commit
|
19
|
+
```
|
20
|
+
|
21
|
+
Now checker will halt the commit if it finds problem with source code:
|
22
|
+
|
23
|
+
```
|
24
|
+
Checking app/models/user.rb...
|
25
|
+
FAIL app/models/user.rb found occurence of 'binding.pry'
|
26
|
+
46:binding.pry
|
27
|
+
```
|
28
|
+
|
29
|
+
### Advanced usage
|
30
|
+
|
31
|
+
To check only specific filetypes on commit, use `git config` :
|
32
|
+
|
33
|
+
``` bash
|
34
|
+
git config checker.check 'all'
|
35
|
+
|
36
|
+
git config checker.check 'ruby, haml, coffeescript'
|
37
|
+
```
|
38
|
+
|
39
|
+
Available options are: all, ruby, haml, pry, coffeescript, sass
|
data/checker.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'checker'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2012-
|
3
|
+
s.version = '0.0.4'
|
4
|
+
s.date = '2012-07-09'
|
5
5
|
s.summary = "Syntax checker for various files"
|
6
6
|
s.description = "A collection of modules which every is designed to check syntax for specific files."
|
7
7
|
s.authors = ["Jacek Jakubik"]
|
@@ -10,4 +10,5 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
s.homepage = 'http://github.com/netguru/checker'
|
13
|
+
s.add_dependency 'colorize', '0.5.8'
|
13
14
|
end
|
data/lib/checker.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'colorize'
|
2
2
|
|
3
|
+
require 'checker/core_ext'
|
3
4
|
|
4
5
|
require "checker/modules/all"
|
5
6
|
require "checker/modules/ruby"
|
6
7
|
require "checker/modules/haml"
|
7
8
|
require "checker/modules/pry"
|
8
9
|
require "checker/modules/coffeescript"
|
9
|
-
require "checker/modules/sass"
|
10
|
+
require "checker/modules/sass"
|
data/lib/checker/cli/execute.rb
CHANGED
@@ -1,22 +1,3 @@
|
|
1
|
-
class CoreExt
|
2
|
-
def self.constantize(camel_cased_word)
|
3
|
-
names = camel_cased_word.split('::')
|
4
|
-
names.shift if names.empty? || names.first.empty?
|
5
|
-
|
6
|
-
constant = Object
|
7
|
-
names.each do |name|
|
8
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
9
|
-
end
|
10
|
-
constant
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class String
|
15
|
-
def constantize
|
16
|
-
CoreExt.constantize(self)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
1
|
module Checker
|
21
2
|
class CLI
|
22
3
|
module Execute
|
@@ -2,10 +2,10 @@ module Checker
|
|
2
2
|
module Modules
|
3
3
|
class Coffeescript
|
4
4
|
def self.check
|
5
|
-
|
5
|
+
Utils.color("> Coffeescript syntax <\n", :light_blue)
|
6
6
|
|
7
7
|
unless Coffeescript.check_for_executable
|
8
|
-
|
8
|
+
Utils.color("coffee executable NOT FOUND, OMITTING...\n", :yellow)
|
9
9
|
return true
|
10
10
|
end
|
11
11
|
|
@@ -13,7 +13,7 @@ module Checker
|
|
13
13
|
files.delete_if {|f| !f.ends_with?(".coffee")}
|
14
14
|
|
15
15
|
files.map! do |f|
|
16
|
-
|
16
|
+
Utils.color("Checking #{f}...", :yellow)
|
17
17
|
Coffeescript.check_one(f)
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ module Checker
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.check_one(file)
|
24
|
-
|
24
|
+
Utils.plain_command("cat #{file} | egrep -v '^//=' | coffee -sc > /dev/null")
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.check_for_executable
|
data/lib/checker/modules/haml.rb
CHANGED
@@ -2,13 +2,13 @@ module Checker
|
|
2
2
|
module Modules
|
3
3
|
class Haml
|
4
4
|
def self.check
|
5
|
-
|
5
|
+
Utils.color("> HAML syntax <\n", :light_blue)
|
6
6
|
|
7
7
|
files = Utils.files_modified
|
8
8
|
files.delete_if {|f| !f.ends_with?(".haml")}
|
9
9
|
|
10
10
|
files.map! do |f|
|
11
|
-
|
11
|
+
Utils.color("Checking #{f}...", :yellow)
|
12
12
|
Haml.check_one(f)
|
13
13
|
end
|
14
14
|
|
@@ -16,7 +16,7 @@ module Checker
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.check_one(file)
|
19
|
-
|
19
|
+
Utils.plain_command("haml #{file} > /dev/null")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/checker/modules/pry.rb
CHANGED
@@ -2,12 +2,12 @@ module Checker
|
|
2
2
|
module Modules
|
3
3
|
class Pry
|
4
4
|
def self.check
|
5
|
-
|
5
|
+
Utils.color("> binding.pry occurence <\n", :light_blue)
|
6
6
|
|
7
7
|
files = Utils.files_modified
|
8
8
|
|
9
9
|
files.map! do |f|
|
10
|
-
|
10
|
+
Utils.color("Checking #{f}...", :yellow)
|
11
11
|
[Pry.check_for_binding_pry(f), Pry.check_for_binding_remote_pry(f)].all_true?
|
12
12
|
end
|
13
13
|
|
@@ -18,8 +18,10 @@ module Checker
|
|
18
18
|
result = `grep -n "binding.pry" #{file}`.chomp
|
19
19
|
|
20
20
|
unless result.empty?
|
21
|
-
puts "
|
21
|
+
puts " pry -> FAIL, ".red
|
22
22
|
puts result
|
23
|
+
else
|
24
|
+
print " pry -> OK, ".green
|
23
25
|
end
|
24
26
|
|
25
27
|
result.empty?
|
@@ -29,9 +31,12 @@ module Checker
|
|
29
31
|
result = `grep -n "binding.remote_pry" #{file}`.chomp
|
30
32
|
|
31
33
|
unless result.empty?
|
32
|
-
puts "
|
34
|
+
puts " remote_pry -> FAIL".red
|
33
35
|
puts result
|
36
|
+
else
|
37
|
+
print " remote_pry -> OK".green
|
34
38
|
end
|
39
|
+
puts ""
|
35
40
|
|
36
41
|
result.empty?
|
37
42
|
end
|
data/lib/checker/modules/ruby.rb
CHANGED
@@ -2,13 +2,13 @@ module Checker
|
|
2
2
|
module Modules
|
3
3
|
class Ruby
|
4
4
|
def self.check
|
5
|
-
|
5
|
+
Utils.color("> Ruby syntax <\n", :light_blue)
|
6
6
|
|
7
7
|
files = Utils.files_modified
|
8
8
|
files.delete_if {|f| !f.ends_with?(".rb")}
|
9
9
|
|
10
10
|
files.map! do |f|
|
11
|
-
|
11
|
+
Utils.color("Checking #{f}...", :yellow)
|
12
12
|
Ruby.check_one(f)
|
13
13
|
end
|
14
14
|
|
@@ -16,11 +16,7 @@ module Checker
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.check_one(file)
|
19
|
-
|
20
|
-
Utils.rvm_command("ruby -c #{file}")
|
21
|
-
else
|
22
|
-
Utils.command("ruby -c #{file}")
|
23
|
-
end
|
19
|
+
Utils.command("ruby -c #{file}", :append => ">> /dev/null")
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
data/lib/checker/modules/sass.rb
CHANGED
@@ -2,10 +2,10 @@ module Checker
|
|
2
2
|
module Modules
|
3
3
|
class Sass
|
4
4
|
def self.check
|
5
|
-
|
5
|
+
Utils.color("> Sass syntax <\n", :light_blue)
|
6
6
|
|
7
7
|
unless Sass.check_for_executable
|
8
|
-
|
8
|
+
Utils.color("sass executable NOT FOUND, OMITTING...\n", :magenta)
|
9
9
|
return true
|
10
10
|
end
|
11
11
|
|
@@ -13,7 +13,7 @@ module Checker
|
|
13
13
|
files.delete_if {|f| !f.ends_with?(".scss") and !f.ends_with?(".sass")}
|
14
14
|
|
15
15
|
files.map! do |f|
|
16
|
-
|
16
|
+
Utils.color("Checking #{f}...", :yellow)
|
17
17
|
Sass.check_one(f)
|
18
18
|
end
|
19
19
|
|
@@ -21,13 +21,15 @@ module Checker
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.check_one(file)
|
24
|
-
|
24
|
+
cmd = "sass #{file}"
|
25
|
+
Utils.command(cmd, :use_bundler => true, :append => ">> /dev/null")
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.check_for_executable
|
29
|
+
return @exitstatus unless @exitstatus.nil?
|
28
30
|
cmd = "sass -v"
|
29
|
-
|
30
|
-
$?.exitstatus == 0
|
31
|
+
Utils.command(cmd, :use_bundler => true, :show_output => false, :append => ">> /dev/null")
|
32
|
+
@exitstatus = ($?.exitstatus == 0)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/checker/utils.rb
CHANGED
@@ -4,19 +4,57 @@ class Utils
|
|
4
4
|
@files_modified.dup
|
5
5
|
end
|
6
6
|
|
7
|
+
def self.use_bundler?
|
8
|
+
File.exists?("Gemfile.lock")
|
9
|
+
end
|
10
|
+
|
7
11
|
def self.use_rvm?
|
8
|
-
File.exists?(".rvmrc")
|
12
|
+
File.exists?(".rvmrc") && File.exists?(rvm_shell)
|
9
13
|
end
|
10
14
|
|
11
15
|
def self.rvm_command(command)
|
12
16
|
rvm_version = `echo $rvm_ruby_string`.chomp
|
13
|
-
puts "Using '#{rvm_version}' version"
|
14
|
-
cmd = "
|
15
|
-
|
17
|
+
# puts "Using '#{rvm_version}' version"
|
18
|
+
cmd = "#{rvm_shell} '#{rvm_version}' -c '#{command}'"
|
19
|
+
cmd
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.rvm_shell
|
23
|
+
File.join(ENV.fetch('rvm_path', ''), 'bin/rvm-shell')
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.show_output(exitstatus, options)
|
27
|
+
unless options[:show_output] == false
|
28
|
+
if exitstatus
|
29
|
+
puts " [OK]".green
|
30
|
+
else
|
31
|
+
puts " [FAIL]".red
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.plain_command(cmd, options = {})
|
37
|
+
exitstatus = system(cmd)
|
38
|
+
Utils.show_output(exitstatus, options)
|
39
|
+
exitstatus
|
16
40
|
end
|
17
41
|
|
18
|
-
def self.command(cmd)
|
19
|
-
|
42
|
+
def self.command(cmd, options = {})
|
43
|
+
if options[:use_bundler] == true
|
44
|
+
if Utils.use_bundler?
|
45
|
+
cmd = "bundle exec #{cmd}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
cmd = Utils.rvm_command(cmd) if Utils.use_rvm?
|
50
|
+
cmd << " #{options[:append]}" if options[:append]
|
51
|
+
exitstatus = Utils.execute(cmd)
|
52
|
+
Utils.show_output(exitstatus, options)
|
53
|
+
exitstatus
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.execute(cmd)
|
57
|
+
# system("echo #{cmd}")
|
20
58
|
system(cmd)
|
21
59
|
end
|
22
60
|
|
@@ -37,4 +75,9 @@ class Utils
|
|
37
75
|
def self.get_modules_to_check
|
38
76
|
`git config checker.check`.chomp.split(",").map(&:strip)
|
39
77
|
end
|
40
|
-
|
78
|
+
|
79
|
+
def self.color(str, color)
|
80
|
+
print str.colorize(color)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: &70118335122520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70118335122520
|
14
25
|
description: A collection of modules which every is designed to check syntax for specific
|
15
26
|
files.
|
16
27
|
email: jacek.jakubik@netguru.pl
|
@@ -20,7 +31,8 @@ extensions: []
|
|
20
31
|
extra_rdoc_files: []
|
21
32
|
files:
|
22
33
|
- .gitignore
|
23
|
-
-
|
34
|
+
- CHANGELOG
|
35
|
+
- README.md
|
24
36
|
- bin/checker
|
25
37
|
- checker.gemspec
|
26
38
|
- lib/checker.rb
|