pre-commit 0.5.0 → 0.6.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.
@@ -27,18 +27,19 @@ class PreCommit
27
27
  }
28
28
 
29
29
  Checks = {
30
- :white_space => WhiteSpace,
31
- :console_log => ConsoleLog,
32
- :js_lint_all => JslintCheck.new(:all),
33
- :js_lint_new => JslintCheck.new(:new),
34
- :jshint => JshintCheck.new,
35
- :debugger => DebuggerCheck,
36
- :tabs => Tabs,
37
- :closure_syntax_check => ClosureSyntaxCheck,
38
- :merge_conflict => MergeConflict,
39
- :migrations => MigrationCheck.new,
40
- :ci => CiCheck.new,
41
- :php => PhpCheck.new
30
+ :white_space => WhiteSpace,
31
+ :console_log => ConsoleLog,
32
+ :js_lint_all => JslintCheck.new(:all),
33
+ :js_lint_new => JslintCheck.new(:new),
34
+ :jshint => JshintCheck.new,
35
+ :debugger => DebuggerCheck,
36
+ :tabs => Tabs,
37
+ :closure_syntax_check => ClosureSyntaxCheck,
38
+ :merge_conflict => MergeConflict,
39
+ :migrations => MigrationCheck.new,
40
+ :ci => CiCheck.new,
41
+ :php => PhpCheck.new,
42
+ :ruby_symbol_hashrockets => RubySymbolHashrockets
42
43
  }
43
44
 
44
45
  # Can not delete this method with out a deprecation strategy.
@@ -0,0 +1,49 @@
1
+ class RubySymbolHashrockets
2
+ attr_accessor :staged_files, :error_message
3
+
4
+ HASHROCKET_PATTERN = ':(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*'
5
+
6
+ def self.call
7
+ check = new
8
+ check.staged_files = Utils.staged_files('*')
9
+ result = check.run
10
+
11
+ if !result
12
+ $stderr.puts check.error_message
13
+ $stderr.puts
14
+ $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
15
+ $stderr.puts
16
+ end
17
+
18
+ result
19
+ end
20
+
21
+ def run
22
+ # There is nothing to check
23
+ return true if staged_files.empty?
24
+
25
+ if detected_bad_code?
26
+ @error_message = "pre-commit: detected :symbol => value hashrocket:\n"
27
+ @error_message += violations[:lines]
28
+
29
+ @passed = false
30
+ else
31
+ @passed = true
32
+ end
33
+
34
+ @passed
35
+ end
36
+
37
+ def detected_bad_code?
38
+ violations[:success]
39
+ end
40
+
41
+ def violations
42
+ @violations ||= begin
43
+ lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files}`
44
+ success = $?.exitstatus == 0
45
+
46
+ { :lines => lines, :success => success}
47
+ end
48
+ end
49
+ end
@@ -40,19 +40,10 @@ class Tabs
40
40
  LEADING_TAB_PATTERN = '^ *\t'
41
41
 
42
42
  def detected_bad_code?
43
- system("#{grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}")
43
+ system("#{Utils.grep} -q '#{LEADING_TAB_PATTERN}' #{staged_files}")
44
44
  end
45
45
 
46
46
  def violations
47
- `#{grep} '#{LEADING_TAB_PATTERN}' #{staged_files}`
48
- end
49
-
50
- def grep
51
- grep_version = `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'`
52
- if grep_version =~ /FreeBSD/
53
- "grep -EnIH"
54
- else
55
- "grep -PnIH"
56
- end
47
+ `#{Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files}`
57
48
  end
58
49
  end
@@ -16,4 +16,13 @@ class Utils
16
16
  dirs.reject { |dir| !File.exist?(dir) }
17
17
  end
18
18
 
19
+ def self.grep
20
+ grep_version = `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'`
21
+ if grep_version =~ /FreeBSD/
22
+ "grep -EnIH"
23
+ else
24
+ "grep -PnIH"
25
+ end
26
+ end
27
+
19
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-08 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
@@ -45,6 +45,7 @@ files:
45
45
  - lib/pre-commit/checks/merge_conflict.rb
46
46
  - lib/pre-commit/checks/migration_check.rb
47
47
  - lib/pre-commit/checks/php_check.rb
48
+ - lib/pre-commit/checks/ruby_symbol_hashrockets.rb
48
49
  - lib/pre-commit/checks/tabs.rb
49
50
  - lib/pre-commit/checks.rb
50
51
  - lib/pre-commit/cli.rb