checker 0.6.4 → 0.6.5.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG +17 -1
  3. data/README.md +29 -8
  4. data/checker.gemspec +1 -1
  5. data/lib/checker.rb +14 -2
  6. data/lib/checker/cli.rb +5 -3
  7. data/lib/checker/core_ext.rb +25 -0
  8. data/lib/checker/helper.rb +2 -1
  9. data/lib/checker/installator.rb +23 -4
  10. data/lib/checker/modules/base.rb +49 -20
  11. data/lib/checker/modules/coffeescript.rb +1 -1
  12. data/lib/checker/modules/conflict.rb +4 -3
  13. data/lib/checker/modules/console_log.rb +20 -0
  14. data/lib/checker/modules/haml.rb +1 -1
  15. data/lib/checker/modules/javascript.rb +9 -4
  16. data/lib/checker/modules/pry.rb +4 -3
  17. data/lib/checker/modules/ruby.rb +1 -1
  18. data/lib/checker/modules/sass.rb +55 -1
  19. data/lib/checker/modules/slim.rb +1 -1
  20. data/lib/checker/modules/yaml.rb +2 -3
  21. data/lib/checker/options.rb +22 -0
  22. data/lib/checker/result.rb +21 -0
  23. data/lib/checker/results/console_log.rb +13 -0
  24. data/lib/checker/results/default.rb +13 -0
  25. data/lib/checker/results/javascript.rb +24 -0
  26. data/lib/checker/rvm.rb +16 -0
  27. data/lib/checker/version.rb +1 -1
  28. data/spec/assets/stylesheets/empty +0 -0
  29. data/spec/checker/fixtures/console_log/with_console_log.js +3 -0
  30. data/spec/checker/fixtures/console_log/without_console_log.js +2 -0
  31. data/spec/checker/modules/coffeescript_spec.rb +1 -1
  32. data/spec/checker/modules/conflict_spec.rb +1 -1
  33. data/spec/checker/modules/console_log_spec.rb +49 -0
  34. data/spec/checker/modules/haml_spec.rb +1 -1
  35. data/spec/checker/modules/javascript_spec.rb +52 -1
  36. data/spec/checker/modules/pry_spec.rb +1 -1
  37. data/spec/checker/modules/ruby_spec.rb +1 -1
  38. data/spec/checker/modules/sass_spec.rb +40 -4
  39. data/spec/checker/modules/slim_spec.rb +1 -1
  40. data/spec/checker/modules/yaml_spec.rb +1 -1
  41. data/templates/checker-prepare-commit-msg +2 -2
  42. metadata +20 -14
@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
+ - 2.0.0
6
7
  - ree
7
8
  notifications:
8
9
  email:
data/CHANGELOG CHANGED
@@ -1,3 +1,19 @@
1
+ === version 0.6.5.rc1 (released 2013-02-21)
2
+
3
+ * release candidate version because of quite much changes
4
+
5
+ KNOWN ISSUES
6
+ * might not work with rbenv
7
+
8
+ CHANGES
9
+ * new state: warning. it is using by couple of checks (console.log, javascript)
10
+ * added two more options: commit-on-warning and rails-for-sass (see readme for docs)
11
+ * added check for console.log existance - returns warning if found
12
+ * added reinstall script for git hook
13
+ * updated sass check to use rails runner if project is using asset-pipeline
14
+ * fixed bug when checker was running from system ruby version from git hook, not current rvm one
15
+ (checker reinstall required)
16
+
1
17
  === version 0.6.4 (released 2012-09-24)
2
18
 
3
19
  * fix a prepare-commit-msg hook so it won't destroy line endings in the commit message
@@ -66,4 +82,4 @@
66
82
  === version 0.0.1 (released 2012-04-03)
67
83
 
68
84
  * initial version
69
- * haml checker
85
+ * haml checker
data/README.md CHANGED
@@ -25,15 +25,18 @@ All you need to do is type in `checker install` and it will automatically instal
25
25
  to your current git project. It will look like this:
26
26
 
27
27
  ```
28
- #!/bin/bash
28
+ #!/bin/bash
29
+
30
+ #### Begin of checker script
29
31
  checker
30
32
 
31
- if [ $? == 1 ]; then
33
+ if [ $? = 1 ]; then
32
34
  exit 1
33
35
  fi
34
36
 
35
37
  text=`echo -n ':checkered_flag: '; cat $1`
36
- echo $text > $1
38
+ echo "$text" > $1
39
+ #### End of checker script
37
40
  ```
38
41
 
39
42
  If you don't want your commits be prepended by checkered flag you can remove two last lines from the prepare-commit-msg hook.
@@ -66,13 +69,31 @@ Syntax error: Invalid CSS after "qwe:": expected pseudoclass or pseudoelement, w
66
69
 
67
70
  ### Advanced usage
68
71
 
69
- To check only specific filetypes on commit, use `git config` :
72
+ You can specify checker behaviour for your project by changing the git config for checker.
73
+ Available options are:
74
+
75
+ * check
76
+
77
+ List of modules, seperated by comma, which checker will use. Defaults to all modules.
78
+ Example: `git config checker.check 'ruby, haml, coffeescript'`
79
+
80
+ * commit-on-warning
81
+
82
+ Boolean value. If given false, checker will not commit when any module returns warning.
83
+ Defaults to true.
84
+ Example: `git config checker.commit-on-warning 'false'`
85
+
86
+ * rails-for-sass
87
+
88
+ Boolean value. Will use rails runner to check for sass syntax using sprockets.
89
+ Works work rails >= 3.1. Defaults to true.
90
+ Example: `git config checker.rails-for-sass 'true'`
91
+
92
+
93
+ As for 17.02.2013, `commit-on-warnings` and `rails-for-sass` are not yet working
70
94
 
71
- ``` bash
72
- git config checker.check 'ruby, haml, coffeescript'
73
- ```
74
95
 
75
- ### Available options
96
+ ### Available modules
76
97
 
77
98
  #### ruby
78
99
  Checks for correct syntax in ruby (.rb) files
@@ -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-09-24'
7
+ s.date = '2013-02-21'
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"]
@@ -2,18 +2,30 @@ require 'colorize'
2
2
  require 'digest/md5'
3
3
 
4
4
  require 'checker/core_ext'
5
+ require 'checker/rvm'
5
6
  require 'checker/version'
6
7
  require 'checker/installator'
7
8
  require 'checker/helper'
9
+ require 'checker/options'
10
+ require 'checker/result'
8
11
 
9
- %w[base ruby haml slim pry coffeescript javascript sass yaml conflict].each do |mod|
12
+ %w[base ruby haml slim pry coffeescript javascript sass yaml conflict console_log].each do |mod|
10
13
  require "checker/modules/#{mod}"
11
14
  end
12
15
 
16
+ %w[default console_log javascript].each do |res|
17
+ require "checker/results/#{res}"
18
+ end
19
+
13
20
  def debug_mode?
14
21
  ENV['CHECKER_DEBUG'].to_s == "1"
15
22
  end
16
23
 
17
24
  if debug_mode?
18
25
  puts "Running checker with debug mode!".colorize(:yellow)
19
- end
26
+ end
27
+
28
+ def debug(msg)
29
+ puts "[DEBUG] - #{msg}".colorize(:yellow) if debug_mode?
30
+ end
31
+
@@ -9,6 +9,8 @@ module Checker
9
9
  else
10
10
  if ARGV[0] == "install"
11
11
  Checker::Installator.install!
12
+ elsif ARGV[0] == "reinstall"
13
+ Checker::Installator.reinstall!
12
14
  elsif ARGV[0] == "help"
13
15
  Checker::Helper.show_help!
14
16
  elsif ARGV[0] == "modules"
@@ -32,7 +34,7 @@ module Checker
32
34
  module_instances = []
33
35
  files = modified_files
34
36
  modules.each do |mod|
35
- klass = "Checker::Modules::#{mod.downcase.capitalize}".constantize
37
+ klass = "Checker::Modules::#{mod.classify}".constantize
36
38
  module_instances << klass.new(files.dup)
37
39
  end
38
40
 
@@ -45,7 +47,7 @@ module Checker
45
47
 
46
48
  protected
47
49
  def available_modules
48
- Checker::Modules.constants.map(&:to_s).map(&:downcase) - ['base']
50
+ Checker::Modules.constants.map(&:to_s).map(&:underscore) - ['base']
49
51
  end
50
52
 
51
53
  def check_module_availability(modules)
@@ -58,7 +60,7 @@ module Checker
58
60
  end
59
61
 
60
62
  def get_modules_to_check
61
- `git config checker.check`.chomp.split(",").map(&:strip)
63
+ Checker::Options.modules_to_check
62
64
  end
63
65
 
64
66
  def modified_files
@@ -9,6 +9,23 @@ class CoreExt
9
9
  end
10
10
  constant
11
11
  end
12
+
13
+ def self.classify(underscored_word)
14
+ words = underscored_word.split("_")
15
+ words.each do |word|
16
+ word.capitalize!
17
+ end.join("")
18
+ end
19
+
20
+ def self.underscore(camel_cased_word)
21
+ word = camel_cased_word.to_s.dup
22
+ word.gsub!(/::/, '/')
23
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
24
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
25
+ word.tr!("-", "_")
26
+ word.downcase!
27
+ word
28
+ end
12
29
  end
13
30
 
14
31
  class String
@@ -16,6 +33,14 @@ class String
16
33
  CoreExt.constantize(self)
17
34
  end
18
35
 
36
+ def classify
37
+ CoreExt.classify(self)
38
+ end
39
+
40
+ def underscore
41
+ CoreExt.underscore(self)
42
+ end
43
+
19
44
  def ends_with?(patt)
20
45
  patt = Regexp.new(Regexp.escape(patt) + "$")
21
46
  self.match patt
@@ -3,6 +3,7 @@ module Checker
3
3
  def self.show_help!
4
4
  puts "Checker version #{Checker::VERSION}"
5
5
  puts "* install - type 'checker install' to install git pre-commit-hook"
6
+ puts "* reinstall - type 'checker reinstall' to purge current hook git pre-commit-hook and install new one"
6
7
  puts "* modules - type 'checker modules' to see available modules"
7
8
  puts "* checks - type 'checker [module name]' to check your current git stage"
8
9
  puts "* help - type 'checker help' to see this message :)"
@@ -14,4 +15,4 @@ module Checker
14
15
  exit 0
15
16
  end
16
17
  end
17
- end
18
+ end
@@ -2,16 +2,35 @@ module Checker
2
2
  class Installator
3
3
  def self.template
4
4
  dir = File.dirname(__FILE__) + "/../.."
5
- open(dir + "/templates/checker-prepare-commit-msg").read
5
+ temp = open(dir + "/templates/checker-prepare-commit-msg").read
6
+ temp.gsub(/CHECKER_COMMAND/, Checker::RVM.rvm_command("checker"))
6
7
  end
7
8
 
8
- def self.install!
9
- hooks_dir = "#{Dir.pwd}/.git/hooks"
9
+ def self.hooks_dir
10
+ "#{Dir.pwd}/.git/hooks"
11
+ end
10
12
 
13
+ def self.check_hook!
11
14
  unless Dir.exist?(hooks_dir)
12
15
  puts "Git Hooks dir not found. Are you sure you are inside project with git?"
13
16
  exit 1
14
17
  end
18
+ end
19
+
20
+ def self.reinstall!
21
+ check_hook!
22
+
23
+ pre_commit = "#{hooks_dir}/prepare-commit-msg"
24
+ if File.exists?(pre_commit)
25
+ puts "Removing current git precommit hook..."
26
+ File.delete(pre_commit)
27
+ end
28
+
29
+ install!
30
+ end
31
+
32
+ def self.install!
33
+ check_hook!
15
34
 
16
35
  pre_commit = "#{hooks_dir}/prepare-commit-msg"
17
36
  if File.exist?(pre_commit)
@@ -43,4 +62,4 @@ module Checker
43
62
  end
44
63
  end
45
64
  end
46
- end
65
+ end
@@ -25,6 +25,10 @@ module Checker
25
25
  end
26
26
  end
27
27
 
28
+ def classname
29
+ self.class.to_s.split('::').last
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def print_module_header
@@ -57,9 +61,9 @@ module Checker
57
61
  @results = files_to_check.map do |file_name|
58
62
  color " Checking #{file_name}...", :yellow
59
63
  result = check_one_file(file_name)
60
- show_status(result)
61
- flush_and_forget_output(result)
62
- result
64
+ show_status result.status
65
+ flush_and_forget_output result.status
66
+ result.success?
63
67
  end
64
68
  end
65
69
  end
@@ -71,7 +75,7 @@ module Checker
71
75
 
72
76
  def check_one_file file_name
73
77
  checksum = ::Digest::MD5.hexdigest(file_name)
74
- puts file_name if debug_mode?
78
+ debug(file_name)
75
79
  checkout_file(file_name, checksum)
76
80
  check_one(checkout_file_name(checksum), :extension => File.extname(file_name))
77
81
  end
@@ -87,7 +91,7 @@ module Checker
87
91
 
88
92
  def plain_command(cmd, options = {})
89
93
  cmd = parse_command(cmd, options)
90
- execute(cmd)
94
+ execute(cmd, options)
91
95
  end
92
96
 
93
97
  def silent_command(cmd, options = {})
@@ -96,26 +100,44 @@ module Checker
96
100
  execute(cmd)
97
101
  end
98
102
 
99
- def flush_and_forget_output(success)
100
- print @buffer.to_s unless success
103
+ def flush_and_forget_output(status)
104
+ print @buffer.to_s if (status == :warning or status == :fail)
101
105
  @buffer = ""
102
106
  end
103
107
 
104
- def show_status(success)
105
- if success
106
- puts " [OK]".green
108
+ def print_success_message
109
+ puts " [OK]".green
110
+ end
111
+
112
+ def print_warning_message
113
+ puts " [WARNING]".magenta
114
+ end
115
+
116
+ def print_fail_message
117
+ puts " [FAIL]".red
118
+ end
119
+
120
+ def show_status(status)
121
+ if status == :ok
122
+ print_success_message
123
+ elsif status == :warning
124
+ print_warning_message
107
125
  else
108
- puts " [FAIL]".red
126
+ print_fail_message
109
127
  end
110
128
  end
111
129
 
112
- def execute(cmd)
113
- puts cmd if debug_mode?
130
+ def execute(cmd, options = {})
131
+ debug("executing: #{cmd}")
114
132
  io = IO.popen(cmd)
115
133
  Process.wait(io.pid)
116
134
  @buffer ||= ""
117
135
  @buffer << io.read
118
- success?
136
+ options[:return_boolean] ? success? : exitstatus
137
+ end
138
+
139
+ def exitstatus
140
+ $? && $?.exitstatus
119
141
  end
120
142
 
121
143
  def success?
@@ -135,7 +157,7 @@ module Checker
135
157
  end
136
158
 
137
159
  def name
138
- self.class.to_s.split('::').last.upcase
160
+ classname.underscore.upcase
139
161
  end
140
162
 
141
163
  def use_bundler?
@@ -150,15 +172,20 @@ module Checker
150
172
  File.exists?(rvm_shell)
151
173
  end
152
174
 
153
- def rvm_command(command)
154
- rvm_gem = ENV['GEM_HOME'].to_s
155
- rvm_version = rvm_gem.gsub(/.+rvm\/gems\//, "")
175
+ def rails_project?
176
+ use_bundler? && File.read("Gemfile.lock").match(/ rails /)
177
+ end
178
+
179
+ def rails_with_ap?
180
+ rails_project? && File.exists?("app/assets")
181
+ end
156
182
 
157
- "#{rvm_shell} '#{rvm_version}' -c '#{command}'"
183
+ def rvm_command(command)
184
+ Checker::RVM.rvm_command(command)
158
185
  end
159
186
 
160
187
  def rvm_shell
161
- File.join(ENV['rvm_path'].to_s, 'bin/rvm-shell')
188
+ Checker::RVM.rvm_shell
162
189
  end
163
190
 
164
191
  def with_checker_cache
@@ -167,6 +194,8 @@ module Checker
167
194
  yield if block_given?
168
195
  ensure
169
196
  `rm -rf .checker-cache > /dev/null 2>&1`
197
+ ## for sass check
198
+ `rm -rf app/assets/stylesheets/checker-cache*` if rails_with_ap?
170
199
  end
171
200
  end
172
201
 
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'coffee'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("cat #{file} | egrep -v '^//=' | coffee -sc > /dev/null")
7
+ Checker::Result.result(self, plain_command("cat #{file} | egrep -v '^//=' | coffee -sc > /dev/null"))
8
8
  end
9
9
 
10
10
  def check_for_executable
@@ -4,15 +4,16 @@ module Checker
4
4
 
5
5
  private
6
6
  def check_one(file, opts = {})
7
- [check_for_conflict_start(file), check_for_conflict_end(file)].all_true?
7
+ status = [check_for_conflict_start(file), check_for_conflict_end(file)].all_true?
8
+ Checker::Result.result(self, status ? 0 : 1)
8
9
  end
9
10
 
10
11
  def check_for_conflict_start(file)
11
- !plain_command("grep -n \"<<<<<<< \" #{file}", :bundler => false)
12
+ !plain_command("grep -n \"<<<<<<< \" #{file}", :bundler => false, :return_boolean => true)
12
13
  end
13
14
 
14
15
  def check_for_conflict_end(file)
15
- !plain_command("grep -n \">>>>>>> \" #{file}", :bundler => false)
16
+ !plain_command("grep -n \">>>>>>> \" #{file}", :bundler => false, :return_boolean => true)
16
17
  end
17
18
  end
18
19
  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))
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
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'haml'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("haml --check #{file} >> /dev/null")
7
+ Checker::Result.result(self, plain_command("haml --check #{file} >> /dev/null"))
8
8
  end
9
9
 
10
10
  def check_for_executable
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'js'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("jsl -process #{file}")
7
+ Checker::Result.result(self, plain_command("jsl -process #{file}"))
8
8
  end
9
9
 
10
10
  def check_for_executable
@@ -18,9 +18,14 @@ module Checker
18
18
  str
19
19
  end
20
20
 
21
- # ignore exit status 1 - warnings
22
- def success?
23
- $? && ($?.exitstatus == 0 || $?.exitstatus == 1)
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
24
29
  end
25
30
  end
26
31
  end
@@ -4,15 +4,16 @@ module Checker
4
4
 
5
5
  private
6
6
  def check_one(file, opts = {})
7
- [check_for_binding_pry(file), check_for_binding_remote_pry(file)].all_true?
7
+ status = [check_for_binding_pry(file), check_for_binding_remote_pry(file)].all_true?
8
+ Checker::Result.result(self, status ? 0 : 1)
8
9
  end
9
10
 
10
11
  def check_for_binding_pry(file)
11
- !plain_command("grep -n \"binding\\.pry\" #{file}", :bundler => false)
12
+ !plain_command("grep -n \"binding\\.pry\" #{file}", :bundler => false, :return_boolean => true)
12
13
  end
13
14
 
14
15
  def check_for_binding_remote_pry(file)
15
- !plain_command("grep -n \"binding\\.remote_pry\" #{file}", :bundler => false)
16
+ !plain_command("grep -n \"binding\\.remote_pry\" #{file}", :bundler => false, :return_boolean => true)
16
17
  end
17
18
  end
18
19
  end
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'rb'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("ruby -c #{file}", :bundler => false)
7
+ Checker::Result.result(self, plain_command("ruby -c #{file}", :bundler => false))
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,20 @@ module Checker
4
4
  extensions 'scss', 'sass'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("sass #{"--scss" if opts[:extension] == ".scss"} -c #{file}")
7
+ if 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}"))
8
21
  end
9
22
 
10
23
  def check_for_executable
@@ -17,6 +30,47 @@ module Checker
17
30
  str << "Sass requires haml to work properly: 'gem install haml'\n"
18
31
  str
19
32
  end
33
+
34
+ ## for rails project
35
+ def checkout_file file_name, target
36
+ debug("git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null")
37
+ mkdir_if_necessary(checkout_file_name(target))
38
+ `git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null`
39
+ end
40
+
41
+ def mkdir_if_necessary(target)
42
+ dir = target.gsub(File.basename(target), '')
43
+ create_dir(dir)
44
+ end
45
+
46
+ def create_dir(dir)
47
+ debug("Creating dir #{dir}")
48
+ Dir.mkdir(dir) unless File.exists?(dir)
49
+ end
50
+
51
+ def stylesheets_dir
52
+ "app/assets/stylesheets/"
53
+ end
54
+
55
+ def checkout_file_name target
56
+ (Checker::Options.use_rails_for_sass && rails_with_ap?) ? "#{stylesheets_dir}checker-cache#{target}" : super
57
+ end
58
+
59
+ def proper_path file_name
60
+ file_name.gsub(/app\/assets\/stylesheets\//, '')
61
+ end
62
+
63
+ def check_one_file file_name
64
+ if (Checker::Options.use_rails_for_sass && rails_with_ap?)
65
+ color " (using rails runner)... ", :blue
66
+ debug(file_name)
67
+ debug(proper_path(file_name))
68
+ checkout_file(file_name, proper_path(file_name))
69
+ check_one(checkout_file_name(proper_path(file_name)), :extension => File.extname(file_name))
70
+ else
71
+ super
72
+ end
73
+ end
20
74
  end
21
75
  end
22
76
  end
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'slim'
5
5
  private
6
6
  def check_one(file, opts = {})
7
- plain_command("slimrb --compile #{file} >> /dev/null")
7
+ Checker::Result.result(self, plain_command("slimrb --compile #{file} >> /dev/null"))
8
8
  end
9
9
 
10
10
  def check_for_executable
@@ -8,12 +8,11 @@ module Checker
8
8
  def check_one(file, opts = {})
9
9
  ret = begin
10
10
  YAML.load_file(file)
11
- true
11
+ Checker::Result.result(self, 0)
12
12
  rescue Exception => e
13
13
  puts e
14
- false
14
+ Checker::Result.result(self, 1)
15
15
  end
16
- ret
17
16
  end
18
17
  end
19
18
  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,13 @@
1
+ module Checker
2
+ module Results
3
+ class ConsoleLog < Default
4
+ def success?
5
+ (Checker::Options.prevent_commit_on_warning && exitstatus == 0) ? false : true
6
+ end
7
+
8
+ def status
9
+ exitstatus == 1 ? :ok : :warning
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Checker
2
+ module Results
3
+ class Default < Struct.new(:exitstatus)
4
+ def success?
5
+ exitstatus == 0
6
+ end
7
+
8
+ def status
9
+ exitstatus == 0 ? :ok : :fail
10
+ end
11
+ end
12
+ end
13
+ 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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Checker
2
- VERSION = '0.6.4'
2
+ VERSION = '0.6.5.rc1'
3
3
  end
File without changes
@@ -0,0 +1,3 @@
1
+ (function() {
2
+ console.log("test");
3
+ });
@@ -5,7 +5,7 @@ describe Checker::Modules::Coffeescript do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee']
6
6
  mod = Checker::Modules::Coffeescript.new(files)
7
7
  mod.stub(:check_for_executable).and_return(true)
8
- mod.should_receive(:check_one_file).with('f.coffee')
8
+ mod.should_receive(:check_one_file).with('f.coffee').and_return(stub(:success? => true, :status => :ok))
9
9
  mod.should_not_receive(:check_one_file).with('e.yaml')
10
10
  mod.should_not_receive(:check_one_file).with('d.yml')
11
11
  mod.should_not_receive(:check_one_file).with('a.rb')
@@ -4,7 +4,7 @@ describe Checker::Modules::Conflict do
4
4
  it 'checks all files' do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee']
6
6
  mod = Checker::Modules::Conflict.new(files)
7
- mod.stub(:check_one).and_return(true)
7
+ mod.stub(:check_one).and_return(stub(:success? => true, :status => :ok))
8
8
  mod.should_receive(:check_one).exactly(6).times
9
9
  mod.check
10
10
  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
@@ -5,7 +5,7 @@ describe Checker::Modules::Haml do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml']
6
6
  mod = Checker::Modules::Haml.new(files)
7
7
  mod.stub(:check_for_executable).and_return(true)
8
- mod.stub(:check_one_file).and_return(true)
8
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
9
9
  mod.should_receive(:check_one_file).with('g.haml')
10
10
  mod.should_not_receive(:check_one_file).with('f.coffee')
11
11
  mod.should_not_receive(:check_one_file).with('e.yaml')
@@ -5,7 +5,7 @@ describe Checker::Modules::Javascript do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml', 'h.js']
6
6
  mod = Checker::Modules::Javascript.new(files)
7
7
  mod.stub(:check_for_executable).and_return(true)
8
- mod.should_receive(:check_one_file).with('h.js').and_return(true)
8
+ mod.should_receive(:check_one_file).with('h.js').and_return(stub(:success? => true, :status => :ok))
9
9
  mod.should_not_receive(:check_one_file).with('g.haml')
10
10
  mod.should_not_receive(:check_one_file).with('f.coffee')
11
11
  mod.should_not_receive(:check_one_file).with('e.yaml')
@@ -15,4 +15,55 @@ describe Checker::Modules::Javascript do
15
15
  mod.should_not_receive(:check_one_file).with('c.r')
16
16
  mod.check
17
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
+ it "results to be true" do
27
+ @mod.check.should be_true
28
+ end
29
+
30
+ it "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
+ it "results to be true" do
44
+ @mod.check.should be_true
45
+ end
46
+
47
+ it "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
+ it "results to be true" do
61
+ @mod.check.should be_false
62
+ end
63
+
64
+ it "prints proper message" do
65
+ @mod.should_receive(:print_fail_message)
66
+ @mod.check
67
+ end
68
+ end
18
69
  end
@@ -4,7 +4,7 @@ describe Checker::Modules::Pry do
4
4
  it 'should check all files' do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee']
6
6
  mod = Checker::Modules::Pry.new(files)
7
- mod.stub(:check_one).and_return(true)
7
+ mod.stub(:check_one).and_return(stub(:success? => true, :status => :ok))
8
8
  mod.should_receive(:check_one).exactly(6).times
9
9
  mod.check
10
10
  end
@@ -4,7 +4,7 @@ describe Checker::Modules::Ruby do
4
4
  it 'should only check .rb files' do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r']
6
6
  mod = Checker::Modules::Ruby.new(files)
7
- mod.stub(:check_one_file).and_return(true)
7
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
8
8
  mod.should_receive(:check_one_file).with('a.rb')
9
9
  mod.should_not_receive(:check_one_file).with('b.js.erb')
10
10
  mod.should_not_receive(:check_one_file).with('c.r')
@@ -5,7 +5,7 @@ describe Checker::Modules::Sass do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml', 'h.js', 'i.scss', 'j.sass']
6
6
  mod = Checker::Modules::Sass.new(files)
7
7
  mod.stub(:check_for_executable).and_return(true)
8
- mod.stub(:check_one_file).and_return(true)
8
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
9
9
  mod.should_receive(:check_one_file).with('j.sass')
10
10
  mod.should_receive(:check_one_file).with('i.scss')
11
11
  mod.should_not_receive(:check_one_file).with('h.js')
@@ -19,20 +19,56 @@ describe Checker::Modules::Sass do
19
19
  mod.check
20
20
  end
21
21
 
22
- context "different extensions" do
22
+ context "normal check" do
23
+ before do
24
+ Checker::Options.stub(:use_rails_for_sass).and_return(false)
25
+ end
26
+
27
+ it "gives proper command to sass module while checking .sass files" do
28
+ files = ["a.sass"]
29
+ mod = Checker::Modules::Sass.new(files)
30
+ mod.stub(:check_for_executable).and_return(true)
31
+ mod.should_receive(:plain_command).with("sass -c .checker-cache/69cb154f5eeff19216d2879872ba6569").and_return(0)
32
+ mod.check
33
+ end
34
+
35
+ it "gives proper command to sass module while checking .scss files" do
36
+ files = ["a.scss"]
37
+ mod = Checker::Modules::Sass.new(files)
38
+ mod.stub(:check_for_executable).and_return(true)
39
+ mod.should_receive(:plain_command).with("sass --scss -c .checker-cache/13dbadc466ed1f9bdfbb2b545e45d012").and_return(0)
40
+ mod.check
41
+ end
42
+ end
43
+
44
+ context "rails check" do
45
+ before do
46
+ Checker::Options.stub(:use_rails_for_sass).and_return(true)
47
+ end
48
+
49
+ after do
50
+ `rm -rf spec/assets/stylesheets/checker-cache*`
51
+ end
52
+
23
53
  it "gives proper command to sass module while checking .sass files" do
24
54
  files = ["a.sass"]
25
55
  mod = Checker::Modules::Sass.new(files)
56
+ mod.stub(:rails_project?).and_return(true)
57
+ mod.stub(:rails_with_ap?).and_return(true)
26
58
  mod.stub(:check_for_executable).and_return(true)
27
- mod.should_receive(:plain_command).with("sass -c .checker-cache/69cb154f5eeff19216d2879872ba6569")
59
+ mod.stub(:stylesheets_dir).and_return("spec/assets/stylesheets/")
60
+ mod.should_receive(:plain_command).with("rails runner \"Rails.application.assets.find_asset(\\\"#{Dir.pwd}/spec/assets/stylesheets/checker-cachea.sass\\\").to_s\"").and_return(0)
28
61
  mod.check
29
62
  end
30
63
 
31
64
  it "gives proper command to sass module while checking .scss files" do
32
65
  files = ["a.scss"]
33
66
  mod = Checker::Modules::Sass.new(files)
67
+ mod.stub(:rails_project?).and_return(true)
68
+ mod.stub(:rails_with_ap?).and_return(true)
34
69
  mod.stub(:check_for_executable).and_return(true)
35
- mod.should_receive(:plain_command).with("sass --scss -c .checker-cache/13dbadc466ed1f9bdfbb2b545e45d012")
70
+ mod.stub(:stylesheets_dir).and_return("spec/assets/stylesheets/")
71
+ mod.should_receive(:plain_command).with("rails runner \"Rails.application.assets.find_asset(\\\"#{Dir.pwd}/spec/assets/stylesheets/checker-cachea.scss\\\").to_s\"").and_return(0)
36
72
  mod.check
37
73
  end
38
74
  end
@@ -5,7 +5,7 @@ describe Checker::Modules::Slim do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.slim']
6
6
  mod = Checker::Modules::Slim.new(files)
7
7
  mod.stub(:check_for_executable).and_return(true)
8
- mod.stub(:check_one_file).and_return(true)
8
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
9
9
  mod.should_receive(:check_one_file).with('g.slim')
10
10
  mod.should_not_receive(:check_one_file).with('f.coffee')
11
11
  mod.should_not_receive(:check_one_file).with('e.yaml')
@@ -4,7 +4,7 @@ describe Checker::Modules::Yaml do
4
4
  it 'should only check .yaml and .yml files' do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml']
6
6
  mod = Checker::Modules::Yaml.new(files)
7
- mod.stub(:check_one_file).and_return(true)
7
+ mod.stub(:check_one_file).and_return(stub(:success? => true, :status => :ok))
8
8
  mod.should_receive(:check_one_file).with('d.yml')
9
9
  mod.should_receive(:check_one_file).with('e.yaml')
10
10
  mod.should_not_receive(:check_one_file).with('a.rb')
@@ -1,8 +1,8 @@
1
1
 
2
2
  #### Begin of checker script
3
- checker
3
+ CHECKER_COMMAND
4
4
 
5
- if [ $? == 1 ]; then
5
+ if [ $? = 1 ]; then
6
6
  exit 1
7
7
  fi
8
8
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
5
- prerelease:
4
+ version: 0.6.5.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jacek Jakubik
@@ -10,24 +10,19 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-24 00:00:00.000000000 Z
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colorize
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &70220750990620 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - '='
20
+ - - =
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.5.8
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - '='
29
- - !ruby/object:Gem::Version
30
- version: 0.5.8
25
+ version_requirements: *70220750990620
31
26
  description: A collection of modules which every is designed to check syntax for specific
32
27
  files.
33
28
  email:
@@ -56,6 +51,7 @@ files:
56
51
  - lib/checker/modules/base.rb
57
52
  - lib/checker/modules/coffeescript.rb
58
53
  - lib/checker/modules/conflict.rb
54
+ - lib/checker/modules/console_log.rb
59
55
  - lib/checker/modules/haml.rb
60
56
  - lib/checker/modules/javascript.rb
61
57
  - lib/checker/modules/pry.rb
@@ -63,10 +59,19 @@ files:
63
59
  - lib/checker/modules/sass.rb
64
60
  - lib/checker/modules/slim.rb
65
61
  - lib/checker/modules/yaml.rb
62
+ - lib/checker/options.rb
63
+ - lib/checker/result.rb
64
+ - lib/checker/results/console_log.rb
65
+ - lib/checker/results/default.rb
66
+ - lib/checker/results/javascript.rb
67
+ - lib/checker/rvm.rb
66
68
  - lib/checker/version.rb
69
+ - spec/assets/stylesheets/empty
67
70
  - spec/checker/cli_spec.rb
68
71
  - spec/checker/fixtures/conflict/with_conflict.rb
69
72
  - spec/checker/fixtures/conflict/without_conflict.rb
73
+ - spec/checker/fixtures/console_log/with_console_log.js
74
+ - spec/checker/fixtures/console_log/without_console_log.js
70
75
  - spec/checker/fixtures/pry/with_both.rb
71
76
  - spec/checker/fixtures/pry/with_pry.rb
72
77
  - spec/checker/fixtures/pry/with_pry_remote.rb
@@ -81,6 +86,7 @@ files:
81
86
  - spec/checker/modules/base_spec.rb
82
87
  - spec/checker/modules/coffeescript_spec.rb
83
88
  - spec/checker/modules/conflict_spec.rb
89
+ - spec/checker/modules/console_log_spec.rb
84
90
  - spec/checker/modules/haml_spec.rb
85
91
  - spec/checker/modules/javascript_spec.rb
86
92
  - spec/checker/modules/pry_spec.rb
@@ -105,12 +111,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
111
  required_rubygems_version: !ruby/object:Gem::Requirement
106
112
  none: false
107
113
  requirements:
108
- - - ! '>='
114
+ - - ! '>'
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: 1.3.1
111
117
  requirements: []
112
118
  rubyforge_project:
113
- rubygems_version: 1.8.24
119
+ rubygems_version: 1.8.10
114
120
  signing_key:
115
121
  specification_version: 3
116
122
  summary: Syntax checker for various files