Class: Overcommit::Hook::CommitMsg::SpellCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/commit_msg/spell_check.rb

Overview

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

Defined Under Namespace

Classes: Misspelling

Constant Summary collapse

MISSPELLING_REGEX =
/^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/.freeze

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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