class Overcommit::Hook::PreCommit::CodeSpellCheck

Runs ‘alfonsox` spell-checking tool against any modified code file.

@see github.com/diegojromerolopez/alfonsox

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_commit/code_spell_check.rb, line 8
def run
  # Create default file config if it does not exist

  # Run spell-check
  result = execute(command, args: applicable_files)
  return :pass if result.success?

  spellchecking_errors = result.stderr.split("\n")
  spellchecking_errors.pop

  error_messages(spellchecking_errors)
end

Private Instance Methods

error_messages(spellchecking_errors) click to toggle source

Create the error messages

# File lib/overcommit/hook/pre_commit/code_spell_check.rb, line 24
def error_messages(spellchecking_errors)
  messages = []
  spellchecking_errors.each do |spellchecking_error_i|
    error_location, word = spellchecking_error_i.split(' ')
    error_file_path, line = error_location.split(':')
    messages << Overcommit::Hook::Message.new(
      :error, error_file_path, line, "#{error_location}: #{word}"
    )
  end
  messages
end