overcommit-jeygeethanmedia 0.53.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/overcommit +50 -0
- data/config/default.yml +1356 -0
- data/config/starter.yml +33 -0
- data/lib/overcommit.rb +26 -0
- data/lib/overcommit/cli.rb +223 -0
- data/lib/overcommit/command_splitter.rb +146 -0
- data/lib/overcommit/configuration.rb +350 -0
- data/lib/overcommit/configuration_loader.rb +96 -0
- data/lib/overcommit/configuration_validator.rb +186 -0
- data/lib/overcommit/constants.rb +12 -0
- data/lib/overcommit/exceptions.rb +52 -0
- data/lib/overcommit/git_config.rb +22 -0
- data/lib/overcommit/git_repo.rb +286 -0
- data/lib/overcommit/git_version.rb +17 -0
- data/lib/overcommit/hook/base.rb +294 -0
- data/lib/overcommit/hook/commit_msg/base.rb +14 -0
- data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +25 -0
- data/lib/overcommit/hook/commit_msg/empty_message.rb +12 -0
- data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +22 -0
- data/lib/overcommit/hook/commit_msg/hard_tabs.rb +17 -0
- data/lib/overcommit/hook/commit_msg/message_format.rb +31 -0
- data/lib/overcommit/hook/commit_msg/russian_novel.rb +16 -0
- data/lib/overcommit/hook/commit_msg/single_line_subject.rb +16 -0
- data/lib/overcommit/hook/commit_msg/spell_check.rb +45 -0
- data/lib/overcommit/hook/commit_msg/text_width.rb +56 -0
- data/lib/overcommit/hook/commit_msg/trailing_period.rb +16 -0
- data/lib/overcommit/hook/post_checkout/base.rb +22 -0
- data/lib/overcommit/hook/post_checkout/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_checkout/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_checkout/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/base.rb +12 -0
- data/lib/overcommit/hook/post_commit/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/commitplease.rb +16 -0
- data/lib/overcommit/hook/post_commit/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +43 -0
- data/lib/overcommit/hook/post_commit/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_commit/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_commit/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/base.rb +12 -0
- data/lib/overcommit/hook/post_merge/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_merge/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_merge/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/base.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/index_tags.rb +19 -0
- data/lib/overcommit/hook/post_rewrite/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/yarn_install.rb +13 -0
- data/lib/overcommit/hook/pre_commit/author_email.rb +26 -0
- data/lib/overcommit/hook/pre_commit/author_name.rb +25 -0
- data/lib/overcommit/hook/pre_commit/base.rb +19 -0
- data/lib/overcommit/hook/pre_commit/berksfile_check.rb +24 -0
- data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +17 -0
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +24 -0
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +32 -0
- data/lib/overcommit/hook/pre_commit/bundle_outdated.rb +25 -0
- data/lib/overcommit/hook/pre_commit/case_conflicts.rb +27 -0
- data/lib/overcommit/hook/pre_commit/chamber_compare.rb +43 -0
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +15 -0
- data/lib/overcommit/hook/pre_commit/chamber_verification.rb +36 -0
- data/lib/overcommit/hook/pre_commit/code_spell_check.rb +36 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +35 -0
- data/lib/overcommit/hook/pre_commit/cook_style.rb +35 -0
- data/lib/overcommit/hook/pre_commit/credo.rb +27 -0
- data/lib/overcommit/hook/pre_commit/css_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/dogma.rb +33 -0
- data/lib/overcommit/hook/pre_commit/es_lint.rb +38 -0
- data/lib/overcommit/hook/pre_commit/execute_permissions.rb +76 -0
- data/lib/overcommit/hook/pre_commit/fasterer.rb +25 -0
- data/lib/overcommit/hook/pre_commit/file_size.rb +47 -0
- data/lib/overcommit/hook/pre_commit/fix_me.rb +17 -0
- data/lib/overcommit/hook/pre_commit/flay.rb +38 -0
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +149 -0
- data/lib/overcommit/hook/pre_commit/forbidden_branches.rb +26 -0
- data/lib/overcommit/hook/pre_commit/ginkgo_focus.rb +23 -0
- data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
- data/lib/overcommit/hook/pre_commit/go_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/go_vet.rb +24 -0
- data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
- data/lib/overcommit/hook/pre_commit/hadolint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +15 -0
- data/lib/overcommit/hook/pre_commit/hlint.rb +34 -0
- data/lib/overcommit/hook/pre_commit/html_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/html_tidy.rb +30 -0
- data/lib/overcommit/hook/pre_commit/image_optim.rb +28 -0
- data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +27 -0
- data/lib/overcommit/hook/pre_commit/js_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/js_lint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/jscs.rb +27 -0
- data/lib/overcommit/hook/pre_commit/jsl.rb +28 -0
- data/lib/overcommit/hook/pre_commit/json_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/kt_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/license_finder.rb +14 -0
- data/lib/overcommit/hook/pre_commit/license_header.rb +48 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +77 -0
- data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +16 -0
- data/lib/overcommit/hook/pre_commit/mdl.rb +29 -0
- data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +16 -0
- data/lib/overcommit/hook/pre_commit/nginx_test.rb +26 -0
- data/lib/overcommit/hook/pre_commit/pep257.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pep8.rb +23 -0
- data/lib/overcommit/hook/pre_commit/php_cs.rb +43 -0
- data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +57 -0
- data/lib/overcommit/hook/pre_commit/php_lint.rb +44 -0
- data/lib/overcommit/hook/pre_commit/php_stan.rb +30 -0
- data/lib/overcommit/hook/pre_commit/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_commit/puppet_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/pycodestyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pydocstyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pyflakes.rb +32 -0
- data/lib/overcommit/hook/pre_commit/pylint.rb +32 -0
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +32 -0
- data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +34 -0
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +58 -0
- data/lib/overcommit/hook/pre_commit/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_commit/reek.rb +26 -0
- data/lib/overcommit/hook/pre_commit/rst_lint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/rubo_cop.rb +35 -0
- data/lib/overcommit/hook/pre_commit/ruby_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/ruby_syntax.rb +27 -0
- data/lib/overcommit/hook/pre_commit/scalariform.rb +22 -0
- data/lib/overcommit/hook/pre_commit/scalastyle.rb +31 -0
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +43 -0
- data/lib/overcommit/hook/pre_commit/semi_standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/shell_check.rb +23 -0
- data/lib/overcommit/hook/pre_commit/slim_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/sqlint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/stylelint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/swift_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/terraform_format.rb +19 -0
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
- data/lib/overcommit/hook/pre_commit/travis_lint.rb +15 -0
- data/lib/overcommit/hook/pre_commit/ts_lint.rb +28 -0
- data/lib/overcommit/hook/pre_commit/vint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/w3c_css.rb +67 -0
- data/lib/overcommit/hook/pre_commit/w3c_html.rb +64 -0
- data/lib/overcommit/hook/pre_commit/xml_lint.rb +24 -0
- data/lib/overcommit/hook/pre_commit/xml_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +18 -0
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +20 -0
- data/lib/overcommit/hook/pre_commit/yard_coverage.rb +90 -0
- data/lib/overcommit/hook/pre_commit/yarn_check.rb +37 -0
- data/lib/overcommit/hook/pre_push/base.rb +33 -0
- data/lib/overcommit/hook/pre_push/brakeman.rb +15 -0
- data/lib/overcommit/hook/pre_push/cargo_test.rb +12 -0
- data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
- data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
- data/lib/overcommit/hook/pre_push/minitest.rb +20 -0
- data/lib/overcommit/hook/pre_push/php_unit.rb +16 -0
- data/lib/overcommit/hook/pre_push/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_push/protected_branches.rb +74 -0
- data/lib/overcommit/hook/pre_push/pytest.rb +16 -0
- data/lib/overcommit/hook/pre_push/python_nose.rb +16 -0
- data/lib/overcommit/hook/pre_push/r_spec.rb +16 -0
- data/lib/overcommit/hook/pre_push/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_push/test_unit.rb +16 -0
- data/lib/overcommit/hook/pre_rebase/base.rb +14 -0
- data/lib/overcommit/hook/pre_rebase/merged_commits.rb +31 -0
- data/lib/overcommit/hook/prepare_commit_msg/base.rb +25 -0
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +57 -0
- data/lib/overcommit/hook/shared/bower_install.rb +15 -0
- data/lib/overcommit/hook/shared/bundle_install.rb +15 -0
- data/lib/overcommit/hook/shared/composer_install.rb +15 -0
- data/lib/overcommit/hook/shared/index_tags.rb +14 -0
- data/lib/overcommit/hook/shared/npm_install.rb +15 -0
- data/lib/overcommit/hook/shared/pronto.rb +21 -0
- data/lib/overcommit/hook/shared/rake_target.rb +26 -0
- data/lib/overcommit/hook/shared/submodule_status.rb +32 -0
- data/lib/overcommit/hook/shared/yarn_install.rb +15 -0
- data/lib/overcommit/hook_context.rb +19 -0
- data/lib/overcommit/hook_context/base.rb +139 -0
- data/lib/overcommit/hook_context/commit_msg.rb +48 -0
- data/lib/overcommit/hook_context/post_checkout.rb +36 -0
- data/lib/overcommit/hook_context/post_commit.rb +33 -0
- data/lib/overcommit/hook_context/post_merge.rb +37 -0
- data/lib/overcommit/hook_context/post_rewrite.rb +49 -0
- data/lib/overcommit/hook_context/pre_commit.rb +212 -0
- data/lib/overcommit/hook_context/pre_push.rb +89 -0
- data/lib/overcommit/hook_context/pre_rebase.rb +38 -0
- data/lib/overcommit/hook_context/prepare_commit_msg.rb +34 -0
- data/lib/overcommit/hook_context/run_all.rb +48 -0
- data/lib/overcommit/hook_loader/base.rb +48 -0
- data/lib/overcommit/hook_loader/built_in_hook_loader.rb +14 -0
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +102 -0
- data/lib/overcommit/hook_runner.rb +219 -0
- data/lib/overcommit/hook_signer.rb +123 -0
- data/lib/overcommit/installer.rb +193 -0
- data/lib/overcommit/interrupt_handler.rb +91 -0
- data/lib/overcommit/logger.rb +92 -0
- data/lib/overcommit/message_processor.rb +148 -0
- data/lib/overcommit/os.rb +38 -0
- data/lib/overcommit/printer.rb +145 -0
- data/lib/overcommit/subprocess.rb +98 -0
- data/lib/overcommit/utils.rb +309 -0
- data/lib/overcommit/utils/file_utils.rb +71 -0
- data/lib/overcommit/utils/messages_utils.rb +77 -0
- data/lib/overcommit/version.rb +6 -0
- data/libexec/gerrit-change-id +174 -0
- data/libexec/index-tags +17 -0
- data/template-dir/hooks/commit-msg +116 -0
- data/template-dir/hooks/overcommit-hook +116 -0
- data/template-dir/hooks/post-checkout +116 -0
- data/template-dir/hooks/post-commit +116 -0
- data/template-dir/hooks/post-merge +116 -0
- data/template-dir/hooks/post-rewrite +116 -0
- data/template-dir/hooks/pre-commit +116 -0
- data/template-dir/hooks/pre-push +116 -0
- data/template-dir/hooks/pre-rebase +116 -0
- data/template-dir/hooks/prepare-commit-msg +116 -0
- metadata +303 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Checks for unresolved merge conflicts
|
5
|
+
class MergeConflicts < Base
|
6
|
+
def run
|
7
|
+
result = execute(command, args: applicable_files)
|
8
|
+
|
9
|
+
unless result.stdout.empty?
|
10
|
+
return :fail, "Merge conflict markers detected:\n#{result.stdout}"
|
11
|
+
end
|
12
|
+
|
13
|
+
:pass
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `nginx -t` against any modified Nginx config files.
|
5
|
+
#
|
6
|
+
# @see https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
|
7
|
+
class NginxTest < Base
|
8
|
+
MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)$/
|
9
|
+
|
10
|
+
def run
|
11
|
+
messages = []
|
12
|
+
|
13
|
+
applicable_files.each do |file|
|
14
|
+
result = execute(command + ['-c', file])
|
15
|
+
next if result.success?
|
16
|
+
|
17
|
+
messages += extract_messages(
|
18
|
+
result.stderr.split("\n").grep(MESSAGE_REGEX),
|
19
|
+
MESSAGE_REGEX
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
messages
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pep257` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see https://pypi.python.org/pypi/pep257
|
7
|
+
class Pep257 < Base
|
8
|
+
def run
|
9
|
+
result = execute(command, args: applicable_files)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stderr.chomp
|
13
|
+
|
14
|
+
# example message:
|
15
|
+
# path/to/file.py:1 in public method `foo`:
|
16
|
+
# D102: Docstring missing
|
17
|
+
extract_messages(
|
18
|
+
output.gsub(/:\s+/, ': ').split("\n"),
|
19
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pep8` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see https://pypi.python.org/pypi/pep8
|
7
|
+
class Pep8 < Base
|
8
|
+
def run
|
9
|
+
result = execute(command, args: applicable_files)
|
10
|
+
output = result.stdout.chomp
|
11
|
+
|
12
|
+
return :pass if result.success? && output.empty?
|
13
|
+
|
14
|
+
# example message:
|
15
|
+
# path/to/file.py:88:5: E301 expected 1 blank line, found 0
|
16
|
+
extract_messages(
|
17
|
+
output.split("\n"),
|
18
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+):\d+:\s(?<type>E|W)/,
|
19
|
+
lambda { |type| type.include?('W') ? :warning : :error }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `phpcs` against any modified PHP files.
|
5
|
+
class PhpCs < Base
|
6
|
+
# Parse `phpcs` csv mode output
|
7
|
+
MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/
|
8
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
9
|
+
'error'.include?(type) ? :error : :warning
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
messages = []
|
14
|
+
|
15
|
+
result = execute(command, args: applicable_files)
|
16
|
+
if result.status
|
17
|
+
messages = result.stdout.split("\n")
|
18
|
+
# Discard the csv header
|
19
|
+
messages.shift
|
20
|
+
end
|
21
|
+
|
22
|
+
return :fail if messages.empty? && !result.success?
|
23
|
+
return :pass if messages.empty?
|
24
|
+
|
25
|
+
parse_messages(messages)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Transform the CSV output into a tidy human readable message
|
29
|
+
def parse_messages(messages)
|
30
|
+
output = []
|
31
|
+
|
32
|
+
messages.map do |message|
|
33
|
+
message.scan(MESSAGE_REGEX).map do |file, line, type, msg|
|
34
|
+
type = MESSAGE_TYPE_CATEGORIZER.call(type)
|
35
|
+
text = " #{file}:#{line}\n #{msg}"
|
36
|
+
output << Overcommit::Hook::Message.new(type, file, line.to_i, text)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
output
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `php-cs-fixer` against any modified PHP files.
|
5
|
+
class PhpCsFixer < Base
|
6
|
+
MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/
|
7
|
+
|
8
|
+
def run
|
9
|
+
messages = []
|
10
|
+
feedback = ''
|
11
|
+
|
12
|
+
# Exit status for all of the runs. Should be zero!
|
13
|
+
exit_status_sum = 0
|
14
|
+
|
15
|
+
applicable_files.each do |file|
|
16
|
+
result = execute(command, args: [file])
|
17
|
+
output = result.stdout.chomp
|
18
|
+
exit_status_sum += result.status
|
19
|
+
|
20
|
+
if result.status
|
21
|
+
messages = output.lstrip.split("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
unless messages.empty?
|
26
|
+
feedback = parse_messages(messages)
|
27
|
+
end
|
28
|
+
|
29
|
+
:pass if exit_status_sum == 0
|
30
|
+
:pass if feedback.empty?
|
31
|
+
|
32
|
+
feedback
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_messages(messages)
|
36
|
+
output = []
|
37
|
+
|
38
|
+
messages.map do |message|
|
39
|
+
message.scan(MESSAGE_REGEX).map do |file, violated_rules|
|
40
|
+
type = :error
|
41
|
+
unless violated_rules.nil?
|
42
|
+
type = :warning
|
43
|
+
end
|
44
|
+
text = if type == :error
|
45
|
+
"Cannot process #{file}: Syntax error"
|
46
|
+
else
|
47
|
+
"#{file} has been fixed"
|
48
|
+
end
|
49
|
+
|
50
|
+
output << Overcommit::Hook::Message.new(type, file, 0, text)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
output
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `php -l` against any modified PHP files.
|
5
|
+
class PhpLint < Base
|
6
|
+
# Sample String
|
7
|
+
# rubocop:disable Metrics/LineLength
|
8
|
+
# PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
|
9
|
+
# rubocop:enable Metrics/LineLength
|
10
|
+
MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/
|
11
|
+
|
12
|
+
def run
|
13
|
+
# A list of error messages
|
14
|
+
messages = []
|
15
|
+
|
16
|
+
# Exit status for all of the runs. Should be zero!
|
17
|
+
exit_status_sum = 0
|
18
|
+
|
19
|
+
# Run for each of our applicable files
|
20
|
+
applicable_files.each do |file|
|
21
|
+
result = execute(command, args: [file])
|
22
|
+
output = result.stdout.chomp
|
23
|
+
exit_status_sum += result.status
|
24
|
+
if result.status
|
25
|
+
# `php -l` returns with a leading newline, and we only need the first
|
26
|
+
# line, there is usually some redundancy
|
27
|
+
messages << output.lstrip.split("\n").first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# If the sum of all lint status is zero, then none had exit status
|
32
|
+
return :pass if exit_status_sum == 0
|
33
|
+
|
34
|
+
# No messages is great news for us
|
35
|
+
return :pass if messages.empty?
|
36
|
+
|
37
|
+
# Return the list of message objects
|
38
|
+
extract_messages(
|
39
|
+
messages,
|
40
|
+
MESSAGE_REGEX
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `phpstan` against any modified PHP files.
|
5
|
+
# For running `phpstan` with Laravel, it requires setup with `ide_helper`.
|
6
|
+
#
|
7
|
+
# References:
|
8
|
+
# https://github.com/phpstan/phpstan/issues/239
|
9
|
+
# https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2
|
10
|
+
class PhpStan < Base
|
11
|
+
MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/
|
12
|
+
|
13
|
+
def run
|
14
|
+
messages = []
|
15
|
+
|
16
|
+
result = execute(command, args: applicable_files)
|
17
|
+
|
18
|
+
unless result.success?
|
19
|
+
messages += result.stdout.lstrip.split("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
return :pass if messages.empty?
|
23
|
+
|
24
|
+
extract_messages(
|
25
|
+
messages,
|
26
|
+
MESSAGE_REGEX
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'overcommit/hook/shared/pronto'
|
4
|
+
|
5
|
+
module Overcommit::Hook::PreCommit
|
6
|
+
# Runs `pronto`
|
7
|
+
#
|
8
|
+
# @see https://github.com/mmozuras/pronto
|
9
|
+
class Pronto < Base
|
10
|
+
include Overcommit::Hook::Shared::Pronto
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs 'puppet-lint' against any modified Puppet files.
|
5
|
+
#
|
6
|
+
# @see http://puppet-lint.com/
|
7
|
+
class PuppetLint < Base
|
8
|
+
MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/
|
9
|
+
|
10
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
11
|
+
type == 'ERROR' ? :error : :warning
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
result = execute(command, args: applicable_files)
|
16
|
+
output = result.stdout.chomp.gsub(/^"|"$/, '')
|
17
|
+
return :pass if result.success? && output.empty?
|
18
|
+
|
19
|
+
extract_messages(
|
20
|
+
output.split("\n"),
|
21
|
+
MESSAGE_REGEX,
|
22
|
+
MESSAGE_TYPE_CATEGORIZER
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
#
|
5
|
+
# Run's the Puppet metadata linter. It has support for adding options
|
6
|
+
# in the .overcommit.yaml
|
7
|
+
#
|
8
|
+
# @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/
|
9
|
+
#
|
10
|
+
class PuppetMetadataJsonLint < Base
|
11
|
+
MESSAGE_REGEX = /\((?<type>.*)\).*/
|
12
|
+
|
13
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
14
|
+
type == 'WARN' ? :warning : :error
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
result = execute(command, args: applicable_files)
|
19
|
+
output = result.stdout.chomp.gsub(/^"|"$/, '')
|
20
|
+
return :pass if result.success? && output.empty?
|
21
|
+
|
22
|
+
extract_messages(
|
23
|
+
output.split("\n"),
|
24
|
+
MESSAGE_REGEX,
|
25
|
+
MESSAGE_TYPE_CATEGORIZER
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pycodestyle` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see https://pypi.python.org/pypi/pycodestyle
|
7
|
+
class Pycodestyle < Base
|
8
|
+
def run
|
9
|
+
result = execute(command, args: applicable_files)
|
10
|
+
output = result.stdout.chomp
|
11
|
+
|
12
|
+
return :pass if result.success? && output.empty?
|
13
|
+
|
14
|
+
# example message:
|
15
|
+
# path/to/file.py:88:5: E301 expected 1 blank line, found 0
|
16
|
+
extract_messages(
|
17
|
+
output.split("\n"),
|
18
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+):\d+:\s(?<type>E|W)/,
|
19
|
+
lambda { |type| type.include?('W') ? :warning : :error }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pydocstyle` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see https://pypi.python.org/pypi/pydocstyle
|
7
|
+
class Pydocstyle < Base
|
8
|
+
def run
|
9
|
+
result = execute(command, args: applicable_files)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stderr.chomp
|
13
|
+
|
14
|
+
# example message:
|
15
|
+
# path/to/file.py:1 in public method `foo`:
|
16
|
+
# D102: Docstring missing
|
17
|
+
extract_messages(
|
18
|
+
output.gsub(/:\s+/, ': ').split("\n"),
|
19
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pyflakes` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see https://pypi.python.org/pypi/pyflakes
|
7
|
+
class Pyflakes < Base
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/
|
9
|
+
|
10
|
+
def run
|
11
|
+
result = execute(command, args: applicable_files)
|
12
|
+
return :pass if result.success?
|
13
|
+
|
14
|
+
errors = get_messages(result.stderr, :error)
|
15
|
+
warnings = get_messages(result.stdout, :warning)
|
16
|
+
|
17
|
+
errors + warnings
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_messages(output, type)
|
23
|
+
# example message:
|
24
|
+
# path/to/file.py:57: local variable 'x' is assigned to but never used
|
25
|
+
extract_messages(
|
26
|
+
output.split("\n").grep(MESSAGE_REGEX),
|
27
|
+
MESSAGE_REGEX,
|
28
|
+
proc { type }
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `pylint` against any modified Python files.
|
5
|
+
#
|
6
|
+
# @see http://www.pylint.org/
|
7
|
+
class Pylint < Base
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])/
|
9
|
+
|
10
|
+
# Classify 'E' and 'F' message codes as errors,
|
11
|
+
# everything else as warnings.
|
12
|
+
# http://pylint.readthedocs.org/en/latest/tutorial.html#getting-started
|
13
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
14
|
+
'EF'.include?(type) ? :error : :warning
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
result = execute(command, args: applicable_files)
|
19
|
+
return :pass if result.success?
|
20
|
+
|
21
|
+
output = result.stdout.chomp
|
22
|
+
|
23
|
+
# example message:
|
24
|
+
# path/to/file.py:64:C: Missing function docstring (missing-docstring)
|
25
|
+
extract_messages(
|
26
|
+
output.split("\n").grep(MESSAGE_REGEX),
|
27
|
+
MESSAGE_REGEX,
|
28
|
+
MESSAGE_TYPE_CATEGORIZER
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|