Created
December 13, 2015 08:55
-
-
Save paulz/c1aee2b520a6ffaafcc0 to your computer and use it in GitHub Desktop.
Overcommit git pre-commit hook to check sources for Xcode template comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PreCommit: | |
NoXcodeTemplateComments: | |
description: 'Checking for Xcode template comments' | |
enabled: true | |
quiet: true | |
exclude: | |
- 'Pods/**/*.*' | |
include: | |
- '**/*.h' | |
- '**/*.m' | |
- '**/*.c' | |
- '**/*.cpp' | |
- '**/*.swift' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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