overcommit-jeygeethanmedia 0.53.1.2 → 0.58.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/overcommit +6 -5
- data/config/default.yml +37 -5
- data/lib/overcommit/cli.rb +14 -13
- data/lib/overcommit/command_splitter.rb +2 -0
- data/lib/overcommit/configuration.rb +1 -1
- data/lib/overcommit/configuration_loader.rb +11 -8
- data/lib/overcommit/exceptions.rb +19 -16
- data/lib/overcommit/git_config.rb +1 -0
- data/lib/overcommit/git_repo.rb +14 -13
- data/lib/overcommit/hook/commit_msg/base.rb +1 -1
- data/lib/overcommit/hook/commit_msg/spell_check.rb +1 -1
- data/lib/overcommit/hook/commit_msg/text_width.rb +1 -1
- data/lib/overcommit/hook/post_checkout/base.rb +1 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +2 -1
- data/lib/overcommit/hook/pre_commit/author_name.rb +2 -2
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +1 -1
- data/lib/overcommit/hook/pre_commit/chamber_compare.rb +5 -5
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +1 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/css_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/dart_analyzer.rb +22 -0
- data/lib/overcommit/hook/pre_commit/erb_lint.rb +20 -0
- data/lib/overcommit/hook/pre_commit/es_lint.rb +3 -6
- data/lib/overcommit/hook/pre_commit/fasterer.rb +1 -1
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +3 -1
- data/lib/overcommit/hook/pre_commit/hlint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/html_tidy.rb +1 -1
- data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +1 -1
- data/lib/overcommit/hook/pre_commit/js_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/jsl.rb +1 -1
- data/lib/overcommit/hook/pre_commit/kt_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +3 -2
- data/lib/overcommit/hook/pre_commit/nginx_test.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_cs.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_lint.rb +3 -3
- data/lib/overcommit/hook/pre_commit/php_stan.rb +1 -1
- data/lib/overcommit/hook/pre_commit/puppet_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/pyflakes.rb +1 -1
- data/lib/overcommit/hook/pre_commit/pylint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
- data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +2 -2
- data/lib/overcommit/hook/pre_commit/rst_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scalariform.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scalastyle.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +3 -3
- data/lib/overcommit/hook/pre_commit/semi_standard.rb +1 -1
- data/lib/overcommit/hook/pre_commit/sqlint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/standard.rb +1 -1
- data/lib/overcommit/hook/pre_commit/stylelint.rb +2 -1
- data/lib/overcommit/hook/pre_commit/swift_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/ts_lint.rb +4 -4
- data/lib/overcommit/hook/pre_commit/w3c_css.rb +4 -4
- data/lib/overcommit/hook/pre_commit/w3c_html.rb +4 -4
- data/lib/overcommit/hook/pre_commit/xml_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +25 -4
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +7 -3
- data/lib/overcommit/hook/pre_commit/yard_coverage.rb +0 -1
- data/lib/overcommit/hook/pre_push/cargo_test.rb +1 -0
- data/lib/overcommit/hook/pre_push/flutter_test.rb +16 -0
- data/lib/overcommit/hook/pre_push/pub_test.rb +16 -0
- data/lib/overcommit/hook/prepare_commit_msg/base.rb +1 -0
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +38 -4
- data/lib/overcommit/hook/shared/bower_install.rb +1 -0
- data/lib/overcommit/hook/shared/bundle_install.rb +1 -0
- data/lib/overcommit/hook/shared/composer_install.rb +1 -0
- data/lib/overcommit/hook/shared/npm_install.rb +1 -0
- data/lib/overcommit/hook/shared/pronto.rb +7 -3
- data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
- data/lib/overcommit/hook_context/commit_msg.rb +7 -0
- data/lib/overcommit/hook_context/helpers/file_modifications.rb +79 -0
- data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +144 -0
- data/lib/overcommit/hook_context/post_commit.rb +1 -0
- data/lib/overcommit/hook_context/pre_commit.rb +5 -199
- data/lib/overcommit/hook_context/pre_push.rb +1 -0
- data/lib/overcommit/hook_context/run_all.rb +1 -0
- data/lib/overcommit/hook_context.rb +3 -3
- data/lib/overcommit/hook_loader/base.rb +3 -3
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +3 -3
- data/lib/overcommit/hook_runner.rb +8 -7
- data/lib/overcommit/hook_signer.rb +1 -0
- data/lib/overcommit/installer.rb +2 -1
- data/lib/overcommit/subprocess.rb +24 -2
- data/lib/overcommit/utils/messages_utils.rb +1 -0
- data/lib/overcommit/version.rb +1 -1
- data/libexec/index-tags +6 -4
- data/template-dir/hooks/commit-msg +27 -20
- data/template-dir/hooks/overcommit-hook +27 -20
- data/template-dir/hooks/post-checkout +27 -20
- data/template-dir/hooks/post-commit +27 -20
- data/template-dir/hooks/post-merge +27 -20
- data/template-dir/hooks/post-rewrite +27 -20
- data/template-dir/hooks/pre-commit +27 -20
- data/template-dir/hooks/pre-push +27 -20
- data/template-dir/hooks/pre-rebase +27 -20
- data/template-dir/hooks/prepare-commit-msg +27 -20
- metadata +27 -7
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://www.jslint.com/
|
7
7
|
class JsLint < Base
|
8
|
-
MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://www.javascriptlint.com/
|
7
7
|
class Jsl < Base
|
8
|
-
MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)
|
8
|
+
MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/.freeze
|
9
9
|
|
10
10
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
11
11
|
type.match?(/warning/) ? :warning : :error
|
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
|
|
4
4
|
# Runs `ktlint` against modified Kotlin files.
|
5
5
|
# @see https://github.com/shyiko/ktlint
|
6
6
|
class KtLint < Base
|
7
|
-
MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))
|
7
|
+
MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))/.freeze
|
8
8
|
|
9
9
|
def run
|
10
10
|
result = execute(command, args: applicable_files)
|
@@ -12,14 +12,14 @@ module Overcommit::Hook::PreCommit
|
|
12
12
|
file = File.open(file_name)
|
13
13
|
begin
|
14
14
|
messages += check_file(file, file_name)
|
15
|
-
rescue ArgumentError =>
|
15
|
+
rescue ArgumentError => e
|
16
16
|
# File is likely a binary file which this check should ignore, but
|
17
17
|
# print a warning just in case
|
18
18
|
messages << Overcommit::Hook::Message.new(
|
19
19
|
:warning,
|
20
20
|
file_name,
|
21
21
|
file.lineno,
|
22
|
-
"#{file_name}:#{file.lineno}:#{
|
22
|
+
"#{file_name}:#{file.lineno}:#{e.message}"
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end
|
@@ -59,6 +59,7 @@ module Overcommit::Hook::PreCommit
|
|
59
59
|
i = info.split.first
|
60
60
|
next if i == 'l/-text' # ignore binary files
|
61
61
|
next if i == "l/#{eol}"
|
62
|
+
|
62
63
|
path
|
63
64
|
end.compact
|
64
65
|
end
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
|
7
7
|
class NginxTest < Base
|
8
|
-
MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)$/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
messages = []
|
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
|
|
4
4
|
# Runs `phpcs` against any modified PHP files.
|
5
5
|
class PhpCs < Base
|
6
6
|
# Parse `phpcs` csv mode output
|
7
|
-
MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"
|
7
|
+
MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/.freeze
|
8
8
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
9
9
|
'error'.include?(type) ? :error : :warning
|
10
10
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Overcommit::Hook::PreCommit
|
4
4
|
# Runs `php-cs-fixer` against any modified PHP files.
|
5
5
|
class PhpCsFixer < Base
|
6
|
-
MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))
|
6
|
+
MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/.freeze
|
7
7
|
|
8
8
|
def run
|
9
9
|
messages = []
|
@@ -4,10 +4,10 @@ module Overcommit::Hook::PreCommit
|
|
4
4
|
# Runs `php -l` against any modified PHP files.
|
5
5
|
class PhpLint < Base
|
6
6
|
# Sample String
|
7
|
-
# rubocop:disable
|
7
|
+
# rubocop:disable Layout/LineLength
|
8
8
|
# PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
|
9
|
-
# rubocop:enable
|
10
|
-
MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)
|
9
|
+
# rubocop:enable Layout/LineLength
|
10
|
+
MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/.freeze
|
11
11
|
|
12
12
|
def run
|
13
13
|
# A list of error messages
|
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
# https://github.com/phpstan/phpstan/issues/239
|
9
9
|
# https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2
|
10
10
|
class PhpStan < Base
|
11
|
-
MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)
|
11
|
+
MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/.freeze
|
12
12
|
|
13
13
|
def run
|
14
14
|
messages = []
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://puppet-lint.com/
|
7
7
|
class PuppetLint < Base
|
8
|
-
MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)
|
8
|
+
MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/.freeze
|
9
9
|
|
10
10
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
11
11
|
type == 'ERROR' ? :error : :warning
|
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
# @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/
|
9
9
|
#
|
10
10
|
class PuppetMetadataJsonLint < Base
|
11
|
-
MESSAGE_REGEX = /\((?<type>.*)\)
|
11
|
+
MESSAGE_REGEX = /\((?<type>.*)\).*/.freeze
|
12
12
|
|
13
13
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
14
14
|
type == 'WARN' ? :warning : :error
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://pypi.python.org/pypi/pyflakes
|
7
7
|
class Pyflakes < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://www.pylint.org/
|
7
7
|
class Pylint < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])/.freeze
|
9
9
|
|
10
10
|
# Classify 'E' and 'F' message codes as errors,
|
11
11
|
# everything else as warnings.
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://pypi.python.org/pypi/flake8
|
7
7
|
class PythonFlake8 < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/.freeze
|
9
9
|
|
10
10
|
# Classify 'Exxx' and 'Fxxx' message codes as errors,
|
11
11
|
# everything else as warnings.
|
@@ -7,7 +7,7 @@ module Overcommit
|
|
7
7
|
#
|
8
8
|
# @see https://github.com/railsbp/rails_best_practices
|
9
9
|
class RailsBestPractices < Base
|
10
|
-
ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)
|
10
|
+
ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/.freeze
|
11
11
|
|
12
12
|
def run
|
13
13
|
result = execute(command, args: applicable_files)
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
# failure. The exception is if the schema is at version 0 (i.e before any
|
7
7
|
# migrations have been run). In this case it is OK if there are no migrations.
|
8
8
|
class RailsSchemaUpToDate < Base
|
9
|
-
def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
9
|
+
def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
10
10
|
if migration_files.any? && schema_files.none?
|
11
11
|
return :fail, "It looks like you're adding a migration, but did not update the schema file"
|
12
12
|
elsif migration_files.none? && schema_files.any? && non_zero_schema_version?
|
@@ -18,7 +18,7 @@ module Overcommit::Hook::PreCommit
|
|
18
18
|
# their username.
|
19
19
|
latest_version = migration_files.map do |file|
|
20
20
|
File.basename(file)[/\d+/]
|
21
|
-
end.
|
21
|
+
end.max
|
22
22
|
|
23
23
|
up_to_date = schema.include?(latest_version)
|
24
24
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/mdr/scalariform
|
7
7
|
class Scalariform < Base
|
8
|
-
MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)
|
8
|
+
MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -18,9 +18,9 @@ module Overcommit::Hook::PreCommit
|
|
18
18
|
|
19
19
|
begin
|
20
20
|
collect_lint_messages(JSON.parse(result.stdout))
|
21
|
-
rescue JSON::ParserError =>
|
22
|
-
|
23
|
-
"STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"
|
21
|
+
rescue JSON::ParserError => e
|
22
|
+
[:fail, "Unable to parse JSON returned by SCSS-Lint: #{e.message}\n" \
|
23
|
+
"STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/Flet/semistandard
|
7
7
|
class SemiStandard < Base
|
8
|
-
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/purcell/sqlint
|
7
7
|
class Sqlint < Base
|
8
|
-
MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)
|
8
|
+
MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/.freeze
|
9
9
|
|
10
10
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
11
11
|
type == 'ERROR' ? :error : :warning
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/feross/standard
|
7
7
|
class Standard < Base
|
8
|
-
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -8,12 +8,13 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
# example of output:
|
9
9
|
# index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)
|
10
10
|
|
11
|
-
MESSAGE_REGEX = /^(?<file
|
11
|
+
MESSAGE_REGEX = /^(?<file>[^:]+):\D*(?<line>\d+).*$/.freeze
|
12
12
|
|
13
13
|
def run
|
14
14
|
result = execute(command, args: applicable_files)
|
15
15
|
output = result.stdout.chomp
|
16
16
|
return :pass if result.success? && output.empty?
|
17
|
+
|
17
18
|
extract_messages(
|
18
19
|
output.split("\n"),
|
19
20
|
MESSAGE_REGEX
|
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
|
|
4
4
|
# Runs `swiftlint lint` against modified Swift files.
|
5
5
|
# @see https://github.com/realm/SwiftLint
|
6
6
|
class SwiftLint < Base
|
7
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+):(?<message>.*)
|
7
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+):(?<message>.*)/.freeze
|
8
8
|
|
9
9
|
def run
|
10
10
|
result = execute(command, args: applicable_files)
|
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
# "src/file/anotherfile.ts[298, 1]: exceeds maximum line length of 140"
|
9
9
|
# or
|
10
10
|
# "ERROR: src/AccountController.ts[4, 28]: expected call-signature to have a typedef"
|
11
|
-
MESSAGE_REGEX = /^(?<type>.+: )?(?<file>.+?(?=\[))[^\d]+(?<line>\d+)
|
11
|
+
MESSAGE_REGEX = /^(?<type>.+: )?(?<file>.+?(?=\[))[^\d]+(?<line>\d+).*?/.freeze
|
12
12
|
|
13
13
|
def run
|
14
14
|
result = execute(command, args: applicable_files)
|
@@ -19,9 +19,9 @@ module Overcommit::Hook::PreCommit
|
|
19
19
|
type_categorizer = ->(type) { type.nil? || type.include?('ERROR') ? :error : :warning }
|
20
20
|
|
21
21
|
extract_messages(
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
output_lines,
|
23
|
+
MESSAGE_REGEX,
|
24
|
+
type_categorizer
|
25
25
|
)
|
26
26
|
end
|
27
27
|
end
|
@@ -42,10 +42,10 @@ module Overcommit::Hook::PreCommit
|
|
42
42
|
def opts
|
43
43
|
@opts ||= {
|
44
44
|
validator_uri: config['validator_uri'],
|
45
|
-
proxy_server:
|
46
|
-
proxy_port:
|
47
|
-
proxy_user:
|
48
|
-
proxy_pass:
|
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
49
|
}
|
50
50
|
end
|
51
51
|
|
@@ -42,10 +42,10 @@ module Overcommit::Hook::PreCommit
|
|
42
42
|
def opts
|
43
43
|
@opts ||= {
|
44
44
|
validator_uri: config['validator_uri'],
|
45
|
-
proxy_server:
|
46
|
-
proxy_port:
|
47
|
-
proxy_user:
|
48
|
-
proxy_pass:
|
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
49
|
}
|
50
50
|
end
|
51
51
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://xmlsoft.org/xmllint.html
|
7
7
|
class XmlLint < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -5,13 +5,34 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/adrienverge/yamllint
|
7
7
|
class YamlLint < Base
|
8
|
+
MESSAGE_REGEX = /
|
9
|
+
^(?<file>.+)
|
10
|
+
:(?<line>\d+)
|
11
|
+
:(?<col>\d+)
|
12
|
+
:\s\[(?<type>\w+)\]
|
13
|
+
\s(?<msg>.+)$
|
14
|
+
/x.freeze
|
15
|
+
|
8
16
|
def run
|
9
17
|
result = execute(command, args: applicable_files)
|
18
|
+
parse_messages(result.stdout)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_messages(output)
|
24
|
+
repo_root = Overcommit::Utils.repo_root
|
25
|
+
|
26
|
+
output.scan(MESSAGE_REGEX).map do |file, line, col, type, msg|
|
27
|
+
line = line.to_i
|
28
|
+
type = type.to_sym
|
29
|
+
# Obtain the path relative to the root of the repository
|
30
|
+
# for nicer output:
|
31
|
+
relpath = file.dup
|
32
|
+
relpath.slice!("#{repo_root}/")
|
10
33
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
return [:warn, result.stdout]
|
34
|
+
text = "#{relpath}:#{line}:#{col}:#{type} #{msg}"
|
35
|
+
Overcommit::Hook::Message.new(type, file, line, text)
|
15
36
|
end
|
16
37
|
end
|
17
38
|
end
|
@@ -8,9 +8,13 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
|
9
9
|
applicable_files.each do |file|
|
10
10
|
begin
|
11
|
-
YAML.load_file(file)
|
12
|
-
rescue ArgumentError
|
13
|
-
|
11
|
+
YAML.load_file(file, aliases: true)
|
12
|
+
rescue ArgumentError
|
13
|
+
begin
|
14
|
+
YAML.load_file(file)
|
15
|
+
rescue ArgumentError, Psych::SyntaxError => e
|
16
|
+
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs Flutter test suite (`flutter test`) before push
|
5
|
+
#
|
6
|
+
# @see https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html
|
7
|
+
class FlutterTest < Base
|
8
|
+
def run
|
9
|
+
result = execute(command)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs Dart test suite (`pub run test`) before push
|
5
|
+
#
|
6
|
+
# @see https://pub.dev/packages/test#running-tests
|
7
|
+
class PubTest < Base
|
8
|
+
def run
|
9
|
+
result = execute(command)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -12,6 +12,7 @@ module Overcommit::Hook::PrepareCommitMsg
|
|
12
12
|
|
13
13
|
def modify_commit_message
|
14
14
|
raise 'This expects a block!' unless block_given?
|
15
|
+
|
15
16
|
# NOTE: this assumes all the hooks of the same type share the context's
|
16
17
|
# memory. If that's not the case, this won't work.
|
17
18
|
lock.synchronize do
|
@@ -2,11 +2,37 @@
|
|
2
2
|
|
3
3
|
module Overcommit::Hook::PrepareCommitMsg
|
4
4
|
# Prepends the commit message with a message based on the branch name.
|
5
|
+
#
|
6
|
+
# === What to prepend
|
7
|
+
#
|
5
8
|
# It's possible to reference parts of the branch name through the captures in
|
6
9
|
# the `branch_pattern` regex.
|
10
|
+
#
|
11
|
+
# For instance, if your current branch is `123-topic` then this config
|
12
|
+
#
|
13
|
+
# branch_pattern: '(\d+)-(\w+)'
|
14
|
+
# replacement_text: '[#\1]'
|
15
|
+
#
|
16
|
+
# would make this hook prepend commit messages with `[#123]`.
|
17
|
+
#
|
18
|
+
# Similarly, a replacement text of `[\1][\2]` would result in `[123][topic]`.
|
19
|
+
#
|
20
|
+
# == When to run this hook
|
21
|
+
#
|
22
|
+
# You can configure this to run only for specific types of commits by setting
|
23
|
+
# the `skipped_commit_types`. The allowed types are
|
24
|
+
#
|
25
|
+
# - 'message' - if message is given via `-m`, `-F`
|
26
|
+
# - 'template' - if `-t` is given or `commit.template` is set
|
27
|
+
# - 'commit' - if `-c`, `-C`, or `--amend` is given
|
28
|
+
# - 'merge' - if merging
|
29
|
+
# - 'squash' - if squashing
|
30
|
+
#
|
7
31
|
class ReplaceBranch < Base
|
32
|
+
DEFAULT_BRANCH_PATTERN = /\A(\d+)-(\w+).*\z/.freeze
|
33
|
+
|
8
34
|
def run
|
9
|
-
return :pass if
|
35
|
+
return :pass if skip?
|
10
36
|
|
11
37
|
Overcommit::Utils.log.debug(
|
12
38
|
"Checking if '#{Overcommit::GitRepo.current_branch}' matches #{branch_pattern}"
|
@@ -17,21 +43,25 @@ module Overcommit::Hook::PrepareCommitMsg
|
|
17
43
|
Overcommit::Utils.log.debug("Writing #{commit_message_filename} with #{new_template}")
|
18
44
|
|
19
45
|
modify_commit_message do |old_contents|
|
20
|
-
"#{new_template}
|
46
|
+
"#{new_template}#{old_contents}"
|
21
47
|
end
|
22
48
|
|
23
49
|
:pass
|
24
50
|
end
|
25
51
|
|
26
52
|
def new_template
|
27
|
-
@new_template ||=
|
53
|
+
@new_template ||=
|
54
|
+
begin
|
55
|
+
curr_branch = Overcommit::GitRepo.current_branch
|
56
|
+
curr_branch.gsub(branch_pattern, replacement_text).strip
|
57
|
+
end
|
28
58
|
end
|
29
59
|
|
30
60
|
def branch_pattern
|
31
61
|
@branch_pattern ||=
|
32
62
|
begin
|
33
63
|
pattern = config['branch_pattern']
|
34
|
-
Regexp.new((pattern || '').empty? ?
|
64
|
+
Regexp.new((pattern || '').empty? ? DEFAULT_BRANCH_PATTERN : pattern)
|
35
65
|
end
|
36
66
|
end
|
37
67
|
|
@@ -53,5 +83,9 @@ module Overcommit::Hook::PrepareCommitMsg
|
|
53
83
|
def skipped_commit_types
|
54
84
|
@skipped_commit_types ||= config['skipped_commit_types'].map(&:to_sym)
|
55
85
|
end
|
86
|
+
|
87
|
+
def skip?
|
88
|
+
skipped_commit_types.include?(commit_message_source)
|
89
|
+
end
|
56
90
|
end
|
57
91
|
end
|
@@ -1,19 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Overcommit::Hook::Shared
|
4
|
-
# Shared code used by all Pronto hooks. Runs pronto
|
4
|
+
# Shared code used by all Pronto hooks. Runs pronto linters.
|
5
|
+
|
6
|
+
# @see https://github.com/prontolabs/pronto
|
5
7
|
module Pronto
|
6
8
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
7
9
|
type.include?('E') ? :error : :warning
|
8
10
|
end
|
9
11
|
|
12
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/.freeze
|
13
|
+
|
10
14
|
def run
|
11
15
|
result = execute(command)
|
12
16
|
return :pass if result.success?
|
13
17
|
|
14
18
|
extract_messages(
|
15
|
-
result.stdout.split("\n"),
|
16
|
-
|
19
|
+
result.stdout.split("\n").select { |line| line.match?(MESSAGE_REGEX) },
|
20
|
+
MESSAGE_REGEX,
|
17
21
|
MESSAGE_TYPE_CATEGORIZER,
|
18
22
|
)
|
19
23
|
end
|