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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGELOG +103 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +64 -0
  8. data/LICENCE +21 -0
  9. data/README.md +142 -0
  10. data/Rakefile +4 -0
  11. data/bin/checker +1 -0
  12. data/checker.gemspec +11 -4
  13. data/lib/checker.rb +28 -3
  14. data/lib/checker/cli.rb +88 -4
  15. data/lib/checker/core_ext.rb +25 -2
  16. data/lib/checker/helper.rb +20 -0
  17. data/lib/checker/installator.rb +65 -0
  18. data/lib/checker/modules/base.rb +224 -0
  19. data/lib/checker/modules/coffeescript.rb +22 -0
  20. data/lib/checker/modules/conflict.rb +20 -0
  21. data/lib/checker/modules/console_log.rb +20 -0
  22. data/lib/checker/modules/haml.rb +12 -14
  23. data/lib/checker/modules/javascript.rb +32 -0
  24. data/lib/checker/modules/pry.rb +20 -0
  25. data/lib/checker/modules/rubocop.rb +17 -0
  26. data/lib/checker/modules/ruby.rb +5 -21
  27. data/lib/checker/modules/sass.rb +80 -0
  28. data/lib/checker/modules/slim.rb +21 -0
  29. data/lib/checker/modules/yaml.rb +19 -0
  30. data/lib/checker/options.rb +22 -0
  31. data/lib/checker/result.rb +21 -0
  32. data/lib/checker/results/console_log.rb +13 -0
  33. data/lib/checker/results/default.rb +13 -0
  34. data/lib/checker/results/javascript.rb +24 -0
  35. data/lib/checker/results/rubocop.rb +6 -0
  36. data/lib/checker/rvm.rb +16 -0
  37. data/lib/checker/version.rb +3 -0
  38. data/spec/assets/stylesheets/empty +0 -0
  39. data/spec/checker/cli_spec.rb +37 -0
  40. data/spec/checker/fixtures/conflict/with_conflict.rb +5 -0
  41. data/spec/checker/fixtures/conflict/without_conflict.rb +2 -0
  42. data/spec/checker/fixtures/console_log/with_console_log.js +3 -0
  43. data/spec/checker/fixtures/console_log/without_console_log.js +2 -0
  44. data/spec/checker/fixtures/pry/with_both.rb +4 -0
  45. data/spec/checker/fixtures/pry/with_pry.rb +3 -0
  46. data/spec/checker/fixtures/pry/with_pry_remote.rb +3 -0
  47. data/spec/checker/fixtures/pry/without_pry.rb +2 -0
  48. data/spec/checker/fixtures/ruby/bad.rb +2 -0
  49. data/spec/checker/fixtures/ruby/good.rb +3 -0
  50. data/spec/checker/fixtures/yaml/bad.yaml +18 -0
  51. data/spec/checker/fixtures/yaml/good.yaml +18 -0
  52. data/spec/checker/modules/base_spec.rb +53 -0
  53. data/spec/checker/modules/coffeescript_spec.rb +16 -0
  54. data/spec/checker/modules/conflict_spec.rb +23 -0
  55. data/spec/checker/modules/console_log_spec.rb +49 -0
  56. data/spec/checker/modules/haml_spec.rb +18 -0
  57. data/spec/checker/modules/javascript_spec.rb +69 -0
  58. data/spec/checker/modules/pry_spec.rb +35 -0
  59. data/spec/checker/modules/ruby_spec.rb +26 -0
  60. data/spec/checker/modules/sass_spec.rb +101 -0
  61. data/spec/checker/modules/slim_spec.rb +18 -0
  62. data/spec/checker/modules/yaml_spec.rb +27 -0
  63. data/spec/spec_helper.rb +27 -0
  64. data/templates/checker-prepare-commit-msg +15 -0
  65. metadata +125 -15
  66. data/README +0 -4
  67. data/lib/checker/cli/execute.rb +0 -61
  68. data/lib/checker/modules/all.rb +0 -16
  69. data/lib/checker/utils.rb +0 -48
@@ -0,0 +1,16 @@
1
+ module Checker
2
+ class RVM
3
+ class << self
4
+ def rvm_command(command)
5
+ rvm_gem = ENV['GEM_HOME'].to_s
6
+ rvm_version = rvm_gem.gsub(/.+rvm\/gems\//, "")
7
+
8
+ "#{rvm_shell} '#{rvm_version}' -c '#{command}'"
9
+ end
10
+
11
+ def rvm_shell
12
+ File.join(ENV['rvm_path'].to_s, 'bin/rvm-shell')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Checker
2
+ VERSION = '0.7.0'
3
+ end
File without changes
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module Checker
4
+ module Modules
5
+ class Bogus < Base
6
+ extensions '.test'
7
+ private
8
+ def check_one(file)
9
+ true
10
+ end
11
+
12
+ def check_for_executable
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ describe Checker::CLI do
20
+ context "running without arguments" do
21
+ it "should run checks on modules from git config" do
22
+ ARGV.stub(:size).and_return 0
23
+ Checker::CLI.should_receive(:get_modules_to_check).and_return(["bogus"])
24
+ Checker::CLI.should_receive(:exit).with(0).and_return true
25
+ Checker::CLI.execute
26
+ end
27
+ end
28
+
29
+ context "running with argument" do
30
+ it "should run check on modules from argument" do
31
+ stub_const("ARGV", ["pry"])
32
+ Checker::CLI.should_not_receive(:get_modules_to_check)
33
+ Checker::CLI.should_receive(:exit).with(0).and_return true
34
+ Checker::CLI.execute
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ def test
2
+ <<<<<<< Updated upstream
3
+ =======
4
+ end
5
+ >>>>>>> Stashed changes
@@ -0,0 +1,2 @@
1
+ def test
2
+ end
@@ -0,0 +1,3 @@
1
+ (function() {
2
+ console.log("test");
3
+ });
@@ -0,0 +1,2 @@
1
+ (function() {
2
+ });
@@ -0,0 +1,4 @@
1
+ binding.pry
2
+ def test
3
+ end
4
+ binding.remote_pry
@@ -0,0 +1,3 @@
1
+ def test
2
+ binding.pry
3
+ end
@@ -0,0 +1,3 @@
1
+ def test
2
+ binding.remote_pry
3
+ end
@@ -0,0 +1,2 @@
1
+ def test
2
+ end
@@ -0,0 +1,2 @@
1
+ def test
2
+ {:some => 'random', :hash => 'qwe'}
@@ -0,0 +1,3 @@
1
+ def test
2
+ {some: 'random', hash: 'qwe'}
3
+ end
@@ -0,0 +1,18 @@
1
+ defaults: &defaults
2
+ mobile_ipad: "iPad"
3
+ mobile_agents:
4
+ - "AppleWebKit.+Mobile"
5
+ - "webOS"
6
+ - "SymbianOS"
7
+ - "AppleWebKit.+midori"
8
+ new_search_config:
9
+ options:
10
+ suffix: "/search"
11
+ params:
12
+ a: "a"
13
+ b: "b"
14
+
15
+ test:
16
+ <<: *defaults
17
+ discount: 0.12
18
+ host: test.test
@@ -0,0 +1,18 @@
1
+ defaults: &defaults
2
+ mobile_ipad: "iPad"
3
+ mobile_agents:
4
+ - "AppleWebKit.+Mobile"
5
+ - "webOS"
6
+ - "SymbianOS"
7
+ - "AppleWebKit.+midori"
8
+ new_search_config:
9
+ options:
10
+ suffix: "/search"
11
+ params:
12
+ a: "a"
13
+ b: "b"
14
+
15
+ test:
16
+ <<: *defaults
17
+ discount: 0.12
18
+ host: test.test
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Base do
4
+ describe "rvm_command method" do
5
+ context "properly fetches the ruby version from the environment variables" do
6
+ before do
7
+ ENV.stub!(:[]).with("rvm_path").and_return "/Users/test/.rvm"
8
+ end
9
+
10
+ it "uses no gemsets" do
11
+ ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version"
12
+
13
+ Checker::Modules::Base.new.send(:rvm_command, "test").should == "/Users/test/.rvm/bin/rvm-shell 'some_ruby_version' -c 'test'"
14
+ end
15
+
16
+ it "uses global gemset" do
17
+ ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version@global"
18
+
19
+ Checker::Modules::Base.new.send(:rvm_command, "test").should == "/Users/test/.rvm/bin/rvm-shell 'some_ruby_version@global' -c 'test'"
20
+ end
21
+
22
+ it "uses some other gemset" do
23
+ ENV.stub!(:[]).with("GEM_HOME").and_return "/Users/test/.rvm/gems/some_ruby_version@v2"
24
+
25
+ Checker::Modules::Base.new.send(:rvm_command, "test").should == "/Users/test/.rvm/bin/rvm-shell 'some_ruby_version@v2' -c 'test'"
26
+ end
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
52
+ end
53
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Coffeescript do
4
+ it 'should only check .coffee files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee']
6
+ mod = Checker::Modules::Coffeescript.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.should_receive(:check_one_file).with('f.coffee').and_return(stub(:success? => true, :status => :ok))
9
+ mod.should_not_receive(:check_one_file).with('e.yaml')
10
+ mod.should_not_receive(:check_one_file).with('d.yml')
11
+ mod.should_not_receive(:check_one_file).with('a.rb')
12
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
13
+ mod.should_not_receive(:check_one_file).with('c.r')
14
+ mod.check
15
+ end
16
+ 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(stub(:success? => true, :status => :ok))
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
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::ConsoleLog do
4
+ it 'checks coffee and js files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee', 'g.js']
6
+ mod = Checker::Modules::ConsoleLog.new(files)
7
+ mod.stub(:check_one).and_return(stub(:success? => true, :status => :ok))
8
+ mod.should_receive(:check_one).exactly(2).times
9
+ mod.check
10
+ end
11
+
12
+ describe "does find console.log" do
13
+ before do
14
+ files = [fixture("console_log", "with_console_log.js")]
15
+ @mod = Checker::Modules::ConsoleLog.new(files)
16
+ end
17
+
18
+ it "results to be true if prevent_commit_on_warning is set to false" do
19
+ Checker::Options.stub(:prevent_commit_on_warning).and_return(false)
20
+ @mod.check.should be_true
21
+ end
22
+
23
+ it "results to be false if prevent_commit_on_warning is set to true" do
24
+ Checker::Options.stub(:prevent_commit_on_warning).and_return(true)
25
+ @mod.check.should be_false
26
+ end
27
+
28
+ it "prints proper message" do
29
+ @mod.should_receive(:print_warning_message)
30
+ @mod.check
31
+ end
32
+ end
33
+
34
+ describe "does not find console.log" do
35
+ before do
36
+ files = [fixture("console_log", "without_console_log.js")]
37
+ @mod = Checker::Modules::ConsoleLog.new(files)
38
+ end
39
+
40
+ it "results to be true" do
41
+ @mod.check.should be_true
42
+ end
43
+
44
+ it "prints proper message" do
45
+ @mod.should_receive(:print_success_message)
46
+ @mod.check
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Haml do
4
+ it 'should only check .haml files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml']
6
+ mod = Checker::Modules::Haml.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
9
+ mod.should_receive(:check_one_file).with('g.haml')
10
+ mod.should_not_receive(:check_one_file).with('f.coffee')
11
+ mod.should_not_receive(:check_one_file).with('e.yaml')
12
+ mod.should_not_receive(:check_one_file).with('d.yml')
13
+ mod.should_not_receive(:check_one_file).with('a.rb')
14
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
15
+ mod.should_not_receive(:check_one_file).with('c.r')
16
+ mod.check
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Javascript do
4
+ it 'should only check .js files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml', 'h.js']
6
+ mod = Checker::Modules::Javascript.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.should_receive(:check_one_file).with('h.js').and_return(stub(:success? => true, :status => :ok))
9
+ mod.should_not_receive(:check_one_file).with('g.haml')
10
+ mod.should_not_receive(:check_one_file).with('f.coffee')
11
+ mod.should_not_receive(:check_one_file).with('e.yaml')
12
+ mod.should_not_receive(:check_one_file).with('d.yml')
13
+ mod.should_not_receive(:check_one_file).with('a.rb')
14
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
15
+ mod.should_not_receive(:check_one_file).with('c.r')
16
+ mod.check
17
+ end
18
+
19
+ describe "good js file" do
20
+ before do
21
+ files = ['good.js']
22
+ @mod = Checker::Modules::Javascript.new(files)
23
+ @mod.should_receive(:check_one_file).with('good.js').and_return(stub(:success? => true, :status => :ok))
24
+ end
25
+
26
+ xit "results to be true" do
27
+ @mod.check.should be_true
28
+ end
29
+
30
+ xit "prints proper message" do
31
+ @mod.should_receive(:print_success_message)
32
+ @mod.check
33
+ end
34
+ end
35
+
36
+ describe "js with warnings" do
37
+ before do
38
+ files = ['warning.js']
39
+ @mod = Checker::Modules::Javascript.new(files)
40
+ @mod.should_receive(:check_one_file).with('warning.js').and_return(stub(:success? => true, :status => :warning))
41
+ end
42
+
43
+ xit "results to be true" do
44
+ @mod.check.should be_true
45
+ end
46
+
47
+ xit "prints proper message" do
48
+ @mod.should_receive(:print_warning_message)
49
+ @mod.check
50
+ end
51
+ end
52
+
53
+ describe "bad js with errors" do
54
+ before do
55
+ files = ['bad.js']
56
+ @mod = Checker::Modules::Javascript.new(files)
57
+ @mod.should_receive(:check_one_file).with('bad.js').and_return(stub(:success? => false, :status => :fail))
58
+ end
59
+
60
+ xit "results to be true" do
61
+ @mod.check.should be_false
62
+ end
63
+
64
+ xit "prints proper message" do
65
+ @mod.should_receive(:print_fail_message)
66
+ @mod.check
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Pry do
4
+ it 'should check all files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee']
6
+ mod = Checker::Modules::Pry.new(files)
7
+ mod.stub(:check_one).and_return(stub(:success? => true, :status => :ok))
8
+ mod.should_receive(:check_one).exactly(6).times
9
+ mod.check
10
+ end
11
+
12
+ it "should not find the pry or remote_pry" do
13
+ files = [fixture("pry", "without_pry.rb")]
14
+ mod = Checker::Modules::Pry.new(files)
15
+ mod.check.should be_true
16
+ end
17
+
18
+ it "should find the pry or remote_pry" do
19
+ files = [fixture("pry", "with_pry.rb")]
20
+ mod = Checker::Modules::Pry.new(files)
21
+ mod.check.should be_false
22
+ end
23
+
24
+ it "should find the pry or remote_pry" do
25
+ files = [fixture("pry", "with_pry_remote.rb")]
26
+ mod = Checker::Modules::Pry.new(files)
27
+ mod.check.should be_false
28
+ end
29
+
30
+ it "should find the pry or remote_pry" do
31
+ files = [fixture("pry", "with_both.rb")]
32
+ mod = Checker::Modules::Pry.new(files)
33
+ mod.check.should be_false
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Ruby do
4
+ it 'should only check .rb files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r']
6
+ mod = Checker::Modules::Ruby.new(files)
7
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
8
+ mod.should_receive(:check_one_file).with('a.rb')
9
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
10
+ mod.should_not_receive(:check_one_file).with('c.r')
11
+ mod.check
12
+ end
13
+
14
+
15
+ it "should pass the syntax check" do
16
+ files = [fixture("ruby", "good.rb")]
17
+ mod = Checker::Modules::Ruby.new(files)
18
+ mod.check.should be_true
19
+ end
20
+
21
+ it "should not pass the syntax check" do
22
+ files = [fixture("ruby", "bad.rb")]
23
+ mod = Checker::Modules::Ruby.new(files)
24
+ mod.check.should be_false
25
+ end
26
+ end