Skip to content

Instantly share code, notes, and snippets.

@sterpe
Last active November 29, 2016 19:41
Show Gist options
  • Select an option

  • Save sterpe/f94ff110ce4e7a41fc0613361196d744 to your computer and use it in GitHub Desktop.

Select an option

Save sterpe/f94ff110ce4e7a41fc0613361196d744 to your computer and use it in GitHub Desktop.
Overcommit Pre-commit hook: Editorconfig
module Overcommit::Hook::PreCommit
# Runs `editorconfig-tools check` against any modified files
#
# @see https://github.com/slang800/editorconfig-tools
class Editorconfig < Base
# There is no consistent message format unfortunately
MESSAGE_REGEX =/^.*$/
def run
result = execute(command, args: applicable_files)
output = result.stdout.chomp
return :pass if result.success? && output.empty?
# example message:
# message formats are all over the place
extract_messages(
output.split("\n").grep(MESSAGE_REGEX),
MESSAGE_REGEX
)
end
end
end
#
# .overcommit.yml
#
# PreCommit:
# Editorconfig:
# enabled: true
# required_executable: "./bin/editorconfig-tools.sh"
# command: [
# "./bin/editorconfig-tools.sh",
# "check"
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment