題名の通り。git commit
にHookして、変更がある*.swift
ファイルにのみLintをかける。Lintでコケたらcommitされなくて便利。
#!/usr/bin/env ruby require 'yaml' LINT_CONFIG_FILE_NAME = '.swiftlint.yml' updated_swiftfiles = `git diff --cached --name-only --diff-filter=AM -- '*.swift'`.split("\n") exit if updated_swiftfiles.empty? lint_config = YAML.load_file(LINT_CONFIG_FILE_NAME) default_included = lint_config['included'] lint_config['included'] = updated_swiftfiles open(LINT_CONFIG_FILE_NAME, 'w') do |file| YAML.dump(lint_config, file) end `swiftlint lint` lint_config['included'] = default_included open(LINT_CONFIG_FILE_NAME, 'w') do |file| YAML.dump(lint_config, file) end
こういう内容を "your-repo/.git/hooks/pre-commit" に書いておくだけ。