overcommit-jeygeethanmedia 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs 'sqlint' against any modified SQL files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/purcell/sqlint
|
|
7
|
+
class Sqlint < 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
|
|
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,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `standard` against any modified JavaScript files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/feross/standard
|
|
7
|
+
class Standard < Base
|
|
8
|
+
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
result = execute(command, args: applicable_files)
|
|
12
|
+
output = result.stdout.chomp
|
|
13
|
+
return :pass if result.success? && output.empty?
|
|
14
|
+
|
|
15
|
+
# example message:
|
|
16
|
+
# path/to/file.js:1:1: Error message (ruleName)
|
|
17
|
+
extract_messages(
|
|
18
|
+
output.split("\n").grep(MESSAGE_REGEX), # ignore header line
|
|
19
|
+
MESSAGE_REGEX
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `stylelint` against any modified CSS file.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/stylelint/stylelint
|
|
7
|
+
class Stylelint < Base
|
|
8
|
+
# example of output:
|
|
9
|
+
# index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)
|
|
10
|
+
|
|
11
|
+
MESSAGE_REGEX = /^(?<file>.+):\D*(?<line>\d+).*$/
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
result = execute(command, args: applicable_files)
|
|
15
|
+
output = result.stdout.chomp
|
|
16
|
+
return :pass if result.success? && output.empty?
|
|
17
|
+
extract_messages(
|
|
18
|
+
output.split("\n"),
|
|
19
|
+
MESSAGE_REGEX
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `swiftlint lint` against modified Swift files.
|
|
5
|
+
# @see https://github.com/realm/SwiftLint
|
|
6
|
+
class SwiftLint < Base
|
|
7
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+):(?<message>.*)/
|
|
8
|
+
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command, args: applicable_files)
|
|
11
|
+
return :pass if result.success?
|
|
12
|
+
|
|
13
|
+
extract_messages(
|
|
14
|
+
result.stdout.split("\n").grep(MESSAGE_REGEX),
|
|
15
|
+
MESSAGE_REGEX
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs 'terraform fmt' against any modified *.tf files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://www.terraform.io/docs/commands/fmt.html
|
|
7
|
+
class TerraformFormat < Base
|
|
8
|
+
def run
|
|
9
|
+
messages = []
|
|
10
|
+
applicable_files.each do |f|
|
|
11
|
+
result = execute(command, args: [f])
|
|
12
|
+
unless result.success?
|
|
13
|
+
messages << Overcommit::Hook::Message.new(:error, f, nil, "violation found in #{f}")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
messages
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Checks for trailing whitespace in files.
|
|
5
|
+
class TrailingWhitespace < Base
|
|
6
|
+
def run
|
|
7
|
+
result = execute(command, args: applicable_files)
|
|
8
|
+
|
|
9
|
+
extract_messages(
|
|
10
|
+
result.stdout.split("\n"),
|
|
11
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `travis-lint` against any modified Travis CI files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/travis-ci/travis.rb
|
|
7
|
+
class TravisLint < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command, args: applicable_files)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
[:fail, (result.stdout + result.stderr).strip]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `tslint` against modified TypeScript files.
|
|
5
|
+
# @see http://palantir.github.io/tslint/
|
|
6
|
+
class TsLint < Base
|
|
7
|
+
# example message:
|
|
8
|
+
# "src/file/anotherfile.ts[298, 1]: exceeds maximum line length of 140"
|
|
9
|
+
# or
|
|
10
|
+
# "ERROR: src/AccountController.ts[4, 28]: expected call-signature to have a typedef"
|
|
11
|
+
MESSAGE_REGEX = /^(?<type>.+: )?(?<file>.+?(?=\[))[^\d]+(?<line>\d+).*?/
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
result = execute(command, args: applicable_files)
|
|
15
|
+
output = result.stdout.chomp
|
|
16
|
+
return :pass if result.success? && output.empty?
|
|
17
|
+
|
|
18
|
+
output_lines = output.split("\n").map(&:strip).reject(&:empty?)
|
|
19
|
+
type_categorizer = ->(type) { type.nil? || type.include?('ERROR') ? :error : :warning }
|
|
20
|
+
|
|
21
|
+
extract_messages(
|
|
22
|
+
output_lines,
|
|
23
|
+
MESSAGE_REGEX,
|
|
24
|
+
type_categorizer
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `vint` against any modified Vim script files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/Kuniwak/vint
|
|
7
|
+
class Vint < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command, args: applicable_files)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
return [:fail, result.stderr] unless result.stderr.empty?
|
|
13
|
+
|
|
14
|
+
# example message:
|
|
15
|
+
# path/to/file.vim:1:1: Error message
|
|
16
|
+
extract_messages(
|
|
17
|
+
result.stdout.split("\n"),
|
|
18
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `w3c_validators` against any modified CSS files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/alexdunae/w3c_validators
|
|
7
|
+
class W3cCss < Base
|
|
8
|
+
def run
|
|
9
|
+
collect_messages
|
|
10
|
+
rescue W3CValidators::ParsingError,
|
|
11
|
+
W3CValidators::ValidatorUnavailable => e
|
|
12
|
+
[:fail, e.message]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def collect_messages
|
|
18
|
+
applicable_files.collect do |path|
|
|
19
|
+
results = validator.validate_file(path)
|
|
20
|
+
messages = results.errors + results.warnings
|
|
21
|
+
messages.collect do |msg|
|
|
22
|
+
# Some warnings are not per-line, so use 0 as a default
|
|
23
|
+
line = Integer(msg.line || 0)
|
|
24
|
+
|
|
25
|
+
# Build message by hand to reduce noise from the validator response
|
|
26
|
+
text = "#{msg.type.to_s.upcase}; URI: #{path}; line #{line}: #{msg.message.strip}"
|
|
27
|
+
Overcommit::Hook::Message.new(msg.type, path, line, text)
|
|
28
|
+
end
|
|
29
|
+
end.flatten
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def validator
|
|
33
|
+
unless @validator
|
|
34
|
+
@validator = W3CValidators::CSSValidator.new(opts)
|
|
35
|
+
@validator.set_language!(language) unless language.nil?
|
|
36
|
+
@validator.set_profile!(profile) unless profile.nil?
|
|
37
|
+
@validator.set_warn_level!(warn_level) unless warn_level.nil?
|
|
38
|
+
end
|
|
39
|
+
@validator
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def opts
|
|
43
|
+
@opts ||= {
|
|
44
|
+
validator_uri: config['validator_uri'],
|
|
45
|
+
proxy_server: config['proxy_server'],
|
|
46
|
+
proxy_port: config['proxy_port'],
|
|
47
|
+
proxy_user: config['proxy_user'],
|
|
48
|
+
proxy_pass: config['proxy_pass']
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def language
|
|
53
|
+
@language ||= config['language']
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Values specified at
|
|
57
|
+
# http://www.rubydoc.info/gems/w3c_validators/1.2/W3CValidators#CSS_PROFILES
|
|
58
|
+
def profile
|
|
59
|
+
@profile ||= config['profile']
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# One of 0, 1, 2, 'no'
|
|
63
|
+
def warn_level
|
|
64
|
+
@warn_level ||= config['warn_level']
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `w3c_validators` against any modified HTML files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/alexdunae/w3c_validators
|
|
7
|
+
class W3cHtml < Base
|
|
8
|
+
def run
|
|
9
|
+
collect_messages
|
|
10
|
+
rescue W3CValidators::ParsingError,
|
|
11
|
+
W3CValidators::ValidatorUnavailable => e
|
|
12
|
+
[:fail, e.message]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def collect_messages
|
|
18
|
+
applicable_files.collect do |path|
|
|
19
|
+
results = validator.validate_file(path)
|
|
20
|
+
messages = results.errors + results.warnings
|
|
21
|
+
messages.collect do |msg|
|
|
22
|
+
# Some warnings are not per-line, so use 0 as a default
|
|
23
|
+
line = Integer(msg.line || 0)
|
|
24
|
+
|
|
25
|
+
# Build message by hand to reduce noise from the validator response
|
|
26
|
+
text = "#{msg.type.to_s.upcase}; URI: #{path}; line #{line}: #{msg.message.strip}"
|
|
27
|
+
Overcommit::Hook::Message.new(msg.type, path, line, text)
|
|
28
|
+
end
|
|
29
|
+
end.flatten
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def validator
|
|
33
|
+
unless @validator
|
|
34
|
+
@validator = W3CValidators::MarkupValidator.new(opts)
|
|
35
|
+
@validator.set_charset!(charset, true) unless charset.nil?
|
|
36
|
+
@validator.set_doctype!(doctype, true) unless doctype.nil?
|
|
37
|
+
@validator.set_debug!
|
|
38
|
+
end
|
|
39
|
+
@validator
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def opts
|
|
43
|
+
@opts ||= {
|
|
44
|
+
validator_uri: config['validator_uri'],
|
|
45
|
+
proxy_server: config['proxy_server'],
|
|
46
|
+
proxy_port: config['proxy_port'],
|
|
47
|
+
proxy_user: config['proxy_user'],
|
|
48
|
+
proxy_pass: config['proxy_pass']
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Values specified at
|
|
53
|
+
# http://www.rubydoc.info/gems/w3c_validators/1.2/W3CValidators#CHARSETS
|
|
54
|
+
def charset
|
|
55
|
+
@charset ||= config['charset']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Values specified at
|
|
59
|
+
# http://www.rubydoc.info/gems/w3c_validators/1.2/W3CValidators#DOCTYPES
|
|
60
|
+
def doctype
|
|
61
|
+
@doctype ||= config['doctype']
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `xmllint` against any modified XML files.
|
|
5
|
+
#
|
|
6
|
+
# @see http://xmlsoft.org/xmllint.html
|
|
7
|
+
class XmlLint < Base
|
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
result = execute(command, args: applicable_files)
|
|
12
|
+
output = result.stderr.chomp
|
|
13
|
+
|
|
14
|
+
return :pass if result.success? && output.empty?
|
|
15
|
+
|
|
16
|
+
# example message:
|
|
17
|
+
# path/to/file.xml:1: parser error : Error message
|
|
18
|
+
extract_messages(
|
|
19
|
+
output.split("\n").grep(MESSAGE_REGEX),
|
|
20
|
+
MESSAGE_REGEX
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Checks the syntax of any modified XML files.
|
|
5
|
+
class XmlSyntax < Base
|
|
6
|
+
def run
|
|
7
|
+
messages = []
|
|
8
|
+
|
|
9
|
+
applicable_files.each do |file|
|
|
10
|
+
begin
|
|
11
|
+
REXML::Document.new(IO.read(file))
|
|
12
|
+
rescue REXML::ParseException => e
|
|
13
|
+
error = "Error parsing #{file}: #{e.message}"
|
|
14
|
+
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
messages
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `YAMLLint` against any modified YAML files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/adrienverge/yamllint
|
|
7
|
+
class YamlLint < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command, args: applicable_files)
|
|
10
|
+
|
|
11
|
+
if result.success?
|
|
12
|
+
:pass
|
|
13
|
+
else
|
|
14
|
+
return [:warn, result.stdout]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Checks the syntax of any modified YAML files.
|
|
5
|
+
class YamlSyntax < Base
|
|
6
|
+
def run
|
|
7
|
+
messages = []
|
|
8
|
+
|
|
9
|
+
applicable_files.each do |file|
|
|
10
|
+
begin
|
|
11
|
+
YAML.load_file(file)
|
|
12
|
+
rescue ArgumentError, Psych::SyntaxError => e
|
|
13
|
+
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
messages
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Overcommit::Hook::PreCommit
|
|
5
|
+
# Class to check yard documentation coverage.
|
|
6
|
+
#
|
|
7
|
+
# Use option "min_coverage_percentage" in your YardCoverage configuration
|
|
8
|
+
# to set your desired documentation coverage percentage.
|
|
9
|
+
#
|
|
10
|
+
class YardCoverage < Base
|
|
11
|
+
def run
|
|
12
|
+
# Run a no-stats yard command to get the coverage
|
|
13
|
+
args = flags + applicable_files
|
|
14
|
+
result = execute(command, args: args)
|
|
15
|
+
|
|
16
|
+
warnings_and_stats_text, undocumented_objects_text =
|
|
17
|
+
result.stdout.split('Undocumented Objects:')
|
|
18
|
+
|
|
19
|
+
warnings_and_stats = warnings_and_stats_text.strip.split("\n")
|
|
20
|
+
|
|
21
|
+
# Stats are the last 7 lines before the undocumented objects
|
|
22
|
+
stats = warnings_and_stats.slice(-7, 7)
|
|
23
|
+
|
|
24
|
+
# If no stats present (shouldn't happen), warn the user and end
|
|
25
|
+
if stats.class != Array || stats.length != 7
|
|
26
|
+
return [:warn, 'Impossible to read the yard stats. Please, check your yard installation.']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Check the yard coverage
|
|
30
|
+
yard_coverage = check_yard_coverage(stats)
|
|
31
|
+
if yard_coverage == :warn
|
|
32
|
+
return [
|
|
33
|
+
:warn,
|
|
34
|
+
'Impossible to read yard doc coverage. Please, check your yard installation.'
|
|
35
|
+
]
|
|
36
|
+
end
|
|
37
|
+
return :pass if yard_coverage == :pass
|
|
38
|
+
|
|
39
|
+
error_messages(yard_coverage, undocumented_objects_text)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Check the yard coverage
|
|
45
|
+
#
|
|
46
|
+
# Return a :pass if the coverage is enough, :warn if it couldn't be read,
|
|
47
|
+
# otherwise, it has been read successfully.
|
|
48
|
+
#
|
|
49
|
+
def check_yard_coverage(stat_lines)
|
|
50
|
+
if config['min_coverage_percentage']
|
|
51
|
+
match = stat_lines.last.match(/^\s*([\d.]+)%\s+documented\s*$/)
|
|
52
|
+
unless match
|
|
53
|
+
return :warn
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
yard_coverage = match.captures[0].to_f
|
|
57
|
+
if yard_coverage >= config['min_coverage_percentage'].to_f
|
|
58
|
+
return :pass
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
yard_coverage
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Create the error messages
|
|
66
|
+
def error_messages(yard_coverage, error_text)
|
|
67
|
+
first_message = "You have a #{yard_coverage}% yard documentation coverage. "\
|
|
68
|
+
"#{config['min_coverage_percentage']}% is the minimum required."
|
|
69
|
+
|
|
70
|
+
# Add the undocumented objects text as error messages
|
|
71
|
+
messages = [Overcommit::Hook::Message.new(:error, nil, nil, first_message)]
|
|
72
|
+
|
|
73
|
+
errors = error_text.strip.split("\n")
|
|
74
|
+
errors.each do |undocumented_object|
|
|
75
|
+
undocumented_object_message, file_info = undocumented_object.split(/:?\s+/)
|
|
76
|
+
file_info_match = file_info.match(/^\(([^:]+):(\d+)\)/)
|
|
77
|
+
|
|
78
|
+
# In case any compacted error does not follow the format, ignore it
|
|
79
|
+
if file_info_match
|
|
80
|
+
file = file_info_match.captures[0]
|
|
81
|
+
line = file_info_match.captures[1]
|
|
82
|
+
messages << Overcommit::Hook::Message.new(
|
|
83
|
+
:error, file, line, "#{file}:#{line}: #{undocumented_object_message}"
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
messages
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|