Class: PreCommit::RubySymbolHashrockets
- Inherits:
-
Object
- Object
- PreCommit::RubySymbolHashrockets
- Defined in:
- lib/pre-commit/checks/ruby_symbol_hashrockets.rb
Constant Summary collapse
- HASHROCKET_PATTERN =
'[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)'
Instance Attribute Summary collapse
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#staged_files ⇒ Object
Returns the value of attribute staged_files.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#error_message ⇒ Object
Returns the value of attribute error_message.
6 7 8 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 6 def @error_message end |
#staged_files ⇒ Object
Returns the value of attribute staged_files.
6 7 8 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 6 def staged_files @staged_files end |
Class Method Details
.call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 10 def self.call check = new check.staged_files = Utils.staged_files('*') result = check.run if !result $stderr.puts check. $stderr.puts $stderr.puts 'pre-commit: You can bypass this check using `git commit -n`' $stderr.puts end result end |
Instance Method Details
#detected_bad_code? ⇒ Boolean
41 42 43 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 41 def detected_bad_code? violations[:success] end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 25 def run # There is nothing to check return true if staged_files.empty? if detected_bad_code? @error_message = "pre-commit: detected :symbol => value hashrocket:\n" @error_message += violations[:lines] @passed = false else @passed = true end @passed end |
#violations ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/pre-commit/checks/ruby_symbol_hashrockets.rb', line 45 def violations @violations ||= begin lines = `#{Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files}` success = $?.exitstatus == 0 { :lines => lines, :success => success} end end |