Sha256: 7dd47c1d59f80c716506f1c5ffb0c438fe8d8e5dba89d93123290ffc60ee8254

Contents?: true

Size: 1019 Bytes

Versions: 28

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Runs `alfonsox` spell-checking tool against any modified code file.
  #
  # @see https://github.com/diegojromerolopez/alfonsox
  class CodeSpellCheck < Base
    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

    # Create the error messages
    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
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
overcommit-0.67.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.66.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.65.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.64.1 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.64.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.63.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.62.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.61.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.60.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.59.1 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.59.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-jeygeethanmedia-0.58.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.58.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.57.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.56.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.55.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.54.1 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-0.54.0 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-jeygeethanmedia-0.53.1.2 lib/overcommit/hook/pre_commit/code_spell_check.rb
overcommit-jeygeethanmedia-0.53.1.1 lib/overcommit/hook/pre_commit/code_spell_check.rb