class Overcommit::Hook::CommitMsg::SpellCheck

Checks the commit message for potential misspellings with ‘hunspell`.

@see hunspell.sourceforge.net/

Constants

MISSPELLING_REGEX
Misspelling

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/commit_msg/spell_check.rb, line 14
def run
  result = execute(command + [uncommented_commit_msg_file])
  return [:fail, "Error running spellcheck: #{result.stderr.chomp}"] unless result.success?

  misspellings = parse_misspellings(result.stdout)
  return :pass if misspellings.empty?

  messages = misspellings.map do |misspelled|
    msg = "Potential misspelling: #{misspelled.word}."
    msg += " Suggestions: #{misspelled.suggestions}" unless misspelled.suggestions.nil?
    msg
  end

  [:warn, messages.join("\n")]
end

Private Instance Methods

parse_misspellings(output) click to toggle source
# File lib/overcommit/hook/commit_msg/spell_check.rb, line 39
def parse_misspellings(output)
  output.scan(MISSPELLING_REGEX).map do |word, suggestions|
    Misspelling.new(word, suggestions)
  end
end
uncommented_commit_msg_file() click to toggle source
# File lib/overcommit/hook/commit_msg/spell_check.rb, line 32
def uncommented_commit_msg_file
  ::Tempfile.open('commit-msg') do |file|
    file.write(commit_message)
    file.path
  end
end