Skip to content

Instantly share code, notes, and snippets.

@paulz
Created December 13, 2015 08:55
Show Gist options
  • Save paulz/c1aee2b520a6ffaafcc0 to your computer and use it in GitHub Desktop.
Save paulz/c1aee2b520a6ffaafcc0 to your computer and use it in GitHub Desktop.
Overcommit git pre-commit hook to check sources for Xcode template comments
PreCommit:
NoXcodeTemplateComments:
description: 'Checking for Xcode template comments'
enabled: true
quiet: true
exclude:
- 'Pods/**/*.*'
include:
- '**/*.h'
- '**/*.m'
- '**/*.c'
- '**/*.cpp'
- '**/*.swift'
module Overcommit::Hook::PreCommit
class NoXcodeTemplateComments < Base
def run
errors = []
boilerplate = ['Created by', 'Copyright']
applicable_files.each do |file|
File.open(file, 'r').each_with_index do |line, index|
break if index > 10
boilerplate.each do |text|
comment = "// #{text} "
if line.start_with?(comment)
relative = Pathname(file).relative_path_from(Pathname(Overcommit::Utils.repo_root))
errors << "#{relative}:#{index} starts with #{comment}"
end
end
end
end
return :fail, errors.join("\n") if errors.any?
:pass
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment