checker 0.0.1 → 0.7.0
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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/CHANGELOG +103 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +64 -0
- data/LICENCE +21 -0
- data/README.md +142 -0
- data/Rakefile +4 -0
- data/bin/checker +1 -0
- data/checker.gemspec +11 -4
- data/lib/checker.rb +28 -3
- data/lib/checker/cli.rb +88 -4
- data/lib/checker/core_ext.rb +25 -2
- data/lib/checker/helper.rb +20 -0
- data/lib/checker/installator.rb +65 -0
- data/lib/checker/modules/base.rb +224 -0
- data/lib/checker/modules/coffeescript.rb +22 -0
- data/lib/checker/modules/conflict.rb +20 -0
- data/lib/checker/modules/console_log.rb +20 -0
- data/lib/checker/modules/haml.rb +12 -14
- data/lib/checker/modules/javascript.rb +32 -0
- data/lib/checker/modules/pry.rb +20 -0
- data/lib/checker/modules/rubocop.rb +17 -0
- data/lib/checker/modules/ruby.rb +5 -21
- data/lib/checker/modules/sass.rb +80 -0
- data/lib/checker/modules/slim.rb +21 -0
- data/lib/checker/modules/yaml.rb +19 -0
- data/lib/checker/options.rb +22 -0
- data/lib/checker/result.rb +21 -0
- data/lib/checker/results/console_log.rb +13 -0
- data/lib/checker/results/default.rb +13 -0
- data/lib/checker/results/javascript.rb +24 -0
- data/lib/checker/results/rubocop.rb +6 -0
- data/lib/checker/rvm.rb +16 -0
- data/lib/checker/version.rb +3 -0
- data/spec/assets/stylesheets/empty +0 -0
- data/spec/checker/cli_spec.rb +37 -0
- data/spec/checker/fixtures/conflict/with_conflict.rb +5 -0
- data/spec/checker/fixtures/conflict/without_conflict.rb +2 -0
- data/spec/checker/fixtures/console_log/with_console_log.js +3 -0
- data/spec/checker/fixtures/console_log/without_console_log.js +2 -0
- data/spec/checker/fixtures/pry/with_both.rb +4 -0
- data/spec/checker/fixtures/pry/with_pry.rb +3 -0
- data/spec/checker/fixtures/pry/with_pry_remote.rb +3 -0
- data/spec/checker/fixtures/pry/without_pry.rb +2 -0
- data/spec/checker/fixtures/ruby/bad.rb +2 -0
- data/spec/checker/fixtures/ruby/good.rb +3 -0
- data/spec/checker/fixtures/yaml/bad.yaml +18 -0
- data/spec/checker/fixtures/yaml/good.yaml +18 -0
- data/spec/checker/modules/base_spec.rb +53 -0
- data/spec/checker/modules/coffeescript_spec.rb +16 -0
- data/spec/checker/modules/conflict_spec.rb +23 -0
- data/spec/checker/modules/console_log_spec.rb +49 -0
- data/spec/checker/modules/haml_spec.rb +18 -0
- data/spec/checker/modules/javascript_spec.rb +69 -0
- data/spec/checker/modules/pry_spec.rb +35 -0
- data/spec/checker/modules/ruby_spec.rb +26 -0
- data/spec/checker/modules/sass_spec.rb +101 -0
- data/spec/checker/modules/slim_spec.rb +18 -0
- data/spec/checker/modules/yaml_spec.rb +27 -0
- data/spec/spec_helper.rb +27 -0
- data/templates/checker-prepare-commit-msg +15 -0
- metadata +125 -15
- data/README +0 -4
- data/lib/checker/cli/execute.rb +0 -61
- data/lib/checker/modules/all.rb +0 -16
- data/lib/checker/utils.rb +0 -48
@@ -0,0 +1,22 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Coffeescript < Base
|
4
|
+
extensions 'coffee'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("cat #{file} | egrep -v '^//=' | coffee -sc > /dev/null"))
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_for_executable
|
11
|
+
silent_command('coffee -v', :bundler => false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def dependency_message
|
15
|
+
str = "Executable not found\n"
|
16
|
+
str << "Install coffeescript from npm: 'npm install -g coffee-script'\n"
|
17
|
+
str << "More info: https://github.com/jashkenas/coffee-script/\n"
|
18
|
+
str
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Conflict < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
status = [check_for_conflict_start(file), check_for_conflict_end(file)].all_true?
|
8
|
+
Checker::Result.result(self, status ? 0 : 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_for_conflict_start(file)
|
12
|
+
!plain_command("grep -n \"<<<<<<< \" #{file}", :bundler => false, :return_boolean => true, :rvm => false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_for_conflict_end(file)
|
16
|
+
!plain_command("grep -n \">>>>>>> \" #{file}", :bundler => false, :return_boolean => true, :rvm => false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class ConsoleLog < Base
|
4
|
+
extensions 'coffee', 'js'
|
5
|
+
|
6
|
+
private
|
7
|
+
def check_one(file, opts = {})
|
8
|
+
Checker::Result.result(self, plain_command("grep -n \"console\\.log\" #{file}", :bundler => false, :rvm => false))
|
9
|
+
end
|
10
|
+
|
11
|
+
def show_status(status)
|
12
|
+
if status == :ok
|
13
|
+
print_success_message
|
14
|
+
else
|
15
|
+
print_warning_message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/checker/modules/haml.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
|
-
class Haml
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
files.map! do |f|
|
11
|
-
puts "Checking #{f}..."
|
12
|
-
Haml.check_one(f)
|
13
|
-
end
|
3
|
+
class Haml < Base
|
4
|
+
extensions 'haml'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("haml --check #{file} >> /dev/null"))
|
8
|
+
end
|
14
9
|
|
15
|
-
|
10
|
+
def check_for_executable
|
11
|
+
silent_command("haml -v")
|
16
12
|
end
|
17
13
|
|
18
|
-
def
|
19
|
-
|
14
|
+
def dependency_message
|
15
|
+
str = "Executable not found\n"
|
16
|
+
str << "Install haml from rubygems: 'gem install haml'\n"
|
17
|
+
str
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Javascript < Base
|
4
|
+
extensions 'js'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("jsl -process #{file}"))
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_for_executable
|
11
|
+
silent_command('jsl -help:conf', :bundler => false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def dependency_message
|
15
|
+
str = "Executable not found\n"
|
16
|
+
str << "Install jsl linter binary\n"
|
17
|
+
str << "More info: http://www.javascriptlint.com/download.htm\n"
|
18
|
+
str
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_status(status)
|
22
|
+
if status == :ok
|
23
|
+
print_success_message
|
24
|
+
elsif status == :warning
|
25
|
+
print_warning_message
|
26
|
+
else
|
27
|
+
print_fail_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Pry < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
status = [check_for_binding_pry(file), check_for_binding_remote_pry(file)].all_true?
|
8
|
+
Checker::Result.result(self, status ? 0 : 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_for_binding_pry(file)
|
12
|
+
!plain_command("grep -n \"binding\\.pry\" #{file}", :bundler => false, :return_boolean => true, :rvm => false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_for_binding_remote_pry(file)
|
16
|
+
!plain_command("grep -n \"binding\\.remote_pry\" #{file}", :bundler => false, :return_boolean => true, :rvm => false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Rubocop < Base
|
4
|
+
extensions 'rb'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("rubocop #{file}", :bundler => false))
|
8
|
+
end
|
9
|
+
|
10
|
+
def dependency_message
|
11
|
+
str = "Executable not found\n"
|
12
|
+
str << "Install rubocop using rubygems: 'gem install rubocop'"
|
13
|
+
str
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/checker/modules/ruby.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
module Checker
|
2
2
|
module Modules
|
3
|
-
class Ruby
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
files.delete_if {|f| !f.ends_with?(".rb")}
|
9
|
-
|
10
|
-
files.map! do |f|
|
11
|
-
puts "Checking #{f}..."
|
12
|
-
Ruby.check_one(f)
|
13
|
-
end
|
14
|
-
|
15
|
-
files.all_true?
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.check_one(file)
|
19
|
-
if Utils.use_rvm?
|
20
|
-
Utils.rvm_command("ruby -c #{file}")
|
21
|
-
else
|
22
|
-
Utils.command("ruby -c #{file}")
|
23
|
-
end
|
3
|
+
class Ruby < Base
|
4
|
+
extensions 'rb'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("ruby -c #{file}", :bundler => false))
|
24
8
|
end
|
25
9
|
end
|
26
10
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Sass < Base
|
4
|
+
extensions 'scss', 'sass'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
if preconditions_for_rails?(file) && Checker::Options.use_rails_for_sass
|
8
|
+
rails_check(file, opts)
|
9
|
+
else
|
10
|
+
normal_check(file, opts)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def rails_check(file, opts)
|
15
|
+
debug("Rails project detected") if rails_project?
|
16
|
+
Checker::Result.result(self, plain_command(%(rails runner "Rails.application.assets.find_asset(\\"#{Dir.pwd}/#{file}\\").to_s")))
|
17
|
+
end
|
18
|
+
|
19
|
+
def normal_check(file, opts)
|
20
|
+
Checker::Result.result(self, plain_command("sass #{"--scss" if opts[:extension] == ".scss"} -c #{file}"))
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_for_executable
|
24
|
+
silent_command("sass -v")
|
25
|
+
end
|
26
|
+
|
27
|
+
def dependency_message
|
28
|
+
str = "Executable not found\n"
|
29
|
+
str << "Install sass from rubygems: 'gem install sass'\n"
|
30
|
+
str << "Sass requires haml to work properly: 'gem install haml'\n"
|
31
|
+
str
|
32
|
+
end
|
33
|
+
|
34
|
+
def preconditions_for_rails?(file)
|
35
|
+
File.read(file).include? "@import"
|
36
|
+
end
|
37
|
+
|
38
|
+
## for rails project
|
39
|
+
def checkout_file file_name, target
|
40
|
+
debug("git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null")
|
41
|
+
mkdir_if_necessary(checkout_file_name(target))
|
42
|
+
`git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null`
|
43
|
+
end
|
44
|
+
|
45
|
+
def mkdir_if_necessary(target)
|
46
|
+
dir = target.gsub(File.basename(target), '')
|
47
|
+
create_dir(dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_dir(dir)
|
51
|
+
debug("Creating dir #{dir}")
|
52
|
+
Dir.mkdir(dir) unless File.exists?(dir)
|
53
|
+
end
|
54
|
+
|
55
|
+
def stylesheets_dir
|
56
|
+
"app/assets/stylesheets/"
|
57
|
+
end
|
58
|
+
|
59
|
+
def checkout_file_name target
|
60
|
+
(Checker::Options.use_rails_for_sass && rails_with_ap?) ? "#{stylesheets_dir}checker-cache#{target}" : super
|
61
|
+
end
|
62
|
+
|
63
|
+
def proper_path file_name
|
64
|
+
file_name.gsub(/app\/assets\/stylesheets\//, '')
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_one_file file_name
|
68
|
+
if (Checker::Options.use_rails_for_sass && rails_with_ap?)
|
69
|
+
color " (using rails runner)... ", :blue
|
70
|
+
debug(file_name)
|
71
|
+
debug(proper_path(file_name))
|
72
|
+
checkout_file(file_name, proper_path(file_name))
|
73
|
+
check_one(checkout_file_name(proper_path(file_name)), :extension => File.extname(file_name))
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Slim < Base
|
4
|
+
extensions 'slim'
|
5
|
+
private
|
6
|
+
def check_one(file, opts = {})
|
7
|
+
Checker::Result.result(self, plain_command("slimrb --compile #{file} >> /dev/null"))
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_for_executable
|
11
|
+
silent_command("slimrb -v")
|
12
|
+
end
|
13
|
+
|
14
|
+
def dependency_message
|
15
|
+
str = "Executable not found\n"
|
16
|
+
str << "Install slim from rubygems: 'gem install slim'\n"
|
17
|
+
str
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Checker
|
4
|
+
module Modules
|
5
|
+
class Yaml < Base
|
6
|
+
extensions 'yaml', 'yml'
|
7
|
+
private
|
8
|
+
def check_one(file, opts = {})
|
9
|
+
ret = begin
|
10
|
+
YAML.load_file(file)
|
11
|
+
Checker::Result.result(self, 0)
|
12
|
+
rescue Exception => e
|
13
|
+
puts e
|
14
|
+
Checker::Result.result(self, 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Checker
|
2
|
+
class Options
|
3
|
+
class << self
|
4
|
+
def get_config(conf, default = nil)
|
5
|
+
config = `git config checker.#{conf}`.chomp
|
6
|
+
(config.empty? && !default.nil?) ? default : config
|
7
|
+
end
|
8
|
+
|
9
|
+
def modules_to_check
|
10
|
+
get_config("check", "all").split(",").map(&:strip)
|
11
|
+
end
|
12
|
+
|
13
|
+
def prevent_commit_on_warning
|
14
|
+
get_config("commit-on-warning", "true") == "false"
|
15
|
+
end
|
16
|
+
|
17
|
+
def use_rails_for_sass
|
18
|
+
get_config("rails-for-sass", "true") == "true"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Checker
|
2
|
+
class Result
|
3
|
+
class << self
|
4
|
+
def result(klass, exitstatus)
|
5
|
+
debug klass
|
6
|
+
debug exitstatus
|
7
|
+
result_class(klass.classname).new(exitstatus)
|
8
|
+
end
|
9
|
+
|
10
|
+
def result_class(klass)
|
11
|
+
"Checker::Results::#{klass}".constantize
|
12
|
+
rescue NameError => e
|
13
|
+
default_result_class
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_result_class
|
17
|
+
Checker::Results::Default
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Checker
|
2
|
+
module Results
|
3
|
+
class Javascript < Default
|
4
|
+
def success?
|
5
|
+
case exitstatus
|
6
|
+
when 0 then true
|
7
|
+
when 1 then
|
8
|
+
Checker::Options.prevent_commit_on_warning ? false : true
|
9
|
+
else
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
case exitstatus
|
16
|
+
when 0 then :ok
|
17
|
+
when 1 then :warning
|
18
|
+
else
|
19
|
+
:fail
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|