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.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/bin/overcommit +50 -0
  3. data/config/default.yml +1356 -0
  4. data/config/starter.yml +33 -0
  5. data/lib/overcommit.rb +26 -0
  6. data/lib/overcommit/cli.rb +223 -0
  7. data/lib/overcommit/command_splitter.rb +146 -0
  8. data/lib/overcommit/configuration.rb +350 -0
  9. data/lib/overcommit/configuration_loader.rb +96 -0
  10. data/lib/overcommit/configuration_validator.rb +186 -0
  11. data/lib/overcommit/constants.rb +12 -0
  12. data/lib/overcommit/exceptions.rb +52 -0
  13. data/lib/overcommit/git_config.rb +22 -0
  14. data/lib/overcommit/git_repo.rb +286 -0
  15. data/lib/overcommit/git_version.rb +17 -0
  16. data/lib/overcommit/hook/base.rb +294 -0
  17. data/lib/overcommit/hook/commit_msg/base.rb +14 -0
  18. data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +25 -0
  19. data/lib/overcommit/hook/commit_msg/empty_message.rb +12 -0
  20. data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +22 -0
  21. data/lib/overcommit/hook/commit_msg/hard_tabs.rb +17 -0
  22. data/lib/overcommit/hook/commit_msg/message_format.rb +31 -0
  23. data/lib/overcommit/hook/commit_msg/russian_novel.rb +16 -0
  24. data/lib/overcommit/hook/commit_msg/single_line_subject.rb +16 -0
  25. data/lib/overcommit/hook/commit_msg/spell_check.rb +45 -0
  26. data/lib/overcommit/hook/commit_msg/text_width.rb +56 -0
  27. data/lib/overcommit/hook/commit_msg/trailing_period.rb +16 -0
  28. data/lib/overcommit/hook/post_checkout/base.rb +22 -0
  29. data/lib/overcommit/hook/post_checkout/bower_install.rb +13 -0
  30. data/lib/overcommit/hook/post_checkout/bundle_install.rb +13 -0
  31. data/lib/overcommit/hook/post_checkout/composer_install.rb +13 -0
  32. data/lib/overcommit/hook/post_checkout/index_tags.rb +12 -0
  33. data/lib/overcommit/hook/post_checkout/npm_install.rb +13 -0
  34. data/lib/overcommit/hook/post_checkout/submodule_status.rb +12 -0
  35. data/lib/overcommit/hook/post_checkout/yarn_install.rb +13 -0
  36. data/lib/overcommit/hook/post_commit/base.rb +12 -0
  37. data/lib/overcommit/hook/post_commit/bower_install.rb +13 -0
  38. data/lib/overcommit/hook/post_commit/bundle_install.rb +13 -0
  39. data/lib/overcommit/hook/post_commit/commitplease.rb +16 -0
  40. data/lib/overcommit/hook/post_commit/composer_install.rb +13 -0
  41. data/lib/overcommit/hook/post_commit/git_guilt.rb +43 -0
  42. data/lib/overcommit/hook/post_commit/index_tags.rb +12 -0
  43. data/lib/overcommit/hook/post_commit/npm_install.rb +13 -0
  44. data/lib/overcommit/hook/post_commit/submodule_status.rb +12 -0
  45. data/lib/overcommit/hook/post_commit/yarn_install.rb +13 -0
  46. data/lib/overcommit/hook/post_merge/base.rb +12 -0
  47. data/lib/overcommit/hook/post_merge/bower_install.rb +13 -0
  48. data/lib/overcommit/hook/post_merge/bundle_install.rb +13 -0
  49. data/lib/overcommit/hook/post_merge/composer_install.rb +13 -0
  50. data/lib/overcommit/hook/post_merge/index_tags.rb +12 -0
  51. data/lib/overcommit/hook/post_merge/npm_install.rb +13 -0
  52. data/lib/overcommit/hook/post_merge/submodule_status.rb +12 -0
  53. data/lib/overcommit/hook/post_merge/yarn_install.rb +13 -0
  54. data/lib/overcommit/hook/post_rewrite/base.rb +12 -0
  55. data/lib/overcommit/hook/post_rewrite/bower_install.rb +13 -0
  56. data/lib/overcommit/hook/post_rewrite/bundle_install.rb +13 -0
  57. data/lib/overcommit/hook/post_rewrite/composer_install.rb +13 -0
  58. data/lib/overcommit/hook/post_rewrite/index_tags.rb +19 -0
  59. data/lib/overcommit/hook/post_rewrite/npm_install.rb +13 -0
  60. data/lib/overcommit/hook/post_rewrite/submodule_status.rb +12 -0
  61. data/lib/overcommit/hook/post_rewrite/yarn_install.rb +13 -0
  62. data/lib/overcommit/hook/pre_commit/author_email.rb +26 -0
  63. data/lib/overcommit/hook/pre_commit/author_name.rb +25 -0
  64. data/lib/overcommit/hook/pre_commit/base.rb +19 -0
  65. data/lib/overcommit/hook/pre_commit/berksfile_check.rb +24 -0
  66. data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +17 -0
  67. data/lib/overcommit/hook/pre_commit/bundle_audit.rb +24 -0
  68. data/lib/overcommit/hook/pre_commit/bundle_check.rb +32 -0
  69. data/lib/overcommit/hook/pre_commit/bundle_outdated.rb +25 -0
  70. data/lib/overcommit/hook/pre_commit/case_conflicts.rb +27 -0
  71. data/lib/overcommit/hook/pre_commit/chamber_compare.rb +43 -0
  72. data/lib/overcommit/hook/pre_commit/chamber_security.rb +15 -0
  73. data/lib/overcommit/hook/pre_commit/chamber_verification.rb +36 -0
  74. data/lib/overcommit/hook/pre_commit/code_spell_check.rb +36 -0
  75. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +35 -0
  76. data/lib/overcommit/hook/pre_commit/cook_style.rb +35 -0
  77. data/lib/overcommit/hook/pre_commit/credo.rb +27 -0
  78. data/lib/overcommit/hook/pre_commit/css_lint.rb +26 -0
  79. data/lib/overcommit/hook/pre_commit/dogma.rb +33 -0
  80. data/lib/overcommit/hook/pre_commit/es_lint.rb +38 -0
  81. data/lib/overcommit/hook/pre_commit/execute_permissions.rb +76 -0
  82. data/lib/overcommit/hook/pre_commit/fasterer.rb +25 -0
  83. data/lib/overcommit/hook/pre_commit/file_size.rb +47 -0
  84. data/lib/overcommit/hook/pre_commit/fix_me.rb +17 -0
  85. data/lib/overcommit/hook/pre_commit/flay.rb +38 -0
  86. data/lib/overcommit/hook/pre_commit/foodcritic.rb +149 -0
  87. data/lib/overcommit/hook/pre_commit/forbidden_branches.rb +26 -0
  88. data/lib/overcommit/hook/pre_commit/ginkgo_focus.rb +23 -0
  89. data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
  90. data/lib/overcommit/hook/pre_commit/go_lint.rb +29 -0
  91. data/lib/overcommit/hook/pre_commit/go_vet.rb +24 -0
  92. data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
  93. data/lib/overcommit/hook/pre_commit/hadolint.rb +27 -0
  94. data/lib/overcommit/hook/pre_commit/haml_lint.rb +23 -0
  95. data/lib/overcommit/hook/pre_commit/hard_tabs.rb +15 -0
  96. data/lib/overcommit/hook/pre_commit/hlint.rb +34 -0
  97. data/lib/overcommit/hook/pre_commit/html_hint.rb +23 -0
  98. data/lib/overcommit/hook/pre_commit/html_tidy.rb +30 -0
  99. data/lib/overcommit/hook/pre_commit/image_optim.rb +28 -0
  100. data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +27 -0
  101. data/lib/overcommit/hook/pre_commit/js_hint.rb +23 -0
  102. data/lib/overcommit/hook/pre_commit/js_lint.rb +22 -0
  103. data/lib/overcommit/hook/pre_commit/jscs.rb +27 -0
  104. data/lib/overcommit/hook/pre_commit/jsl.rb +28 -0
  105. data/lib/overcommit/hook/pre_commit/json_syntax.rb +21 -0
  106. data/lib/overcommit/hook/pre_commit/kt_lint.rb +19 -0
  107. data/lib/overcommit/hook/pre_commit/license_finder.rb +14 -0
  108. data/lib/overcommit/hook/pre_commit/license_header.rb +48 -0
  109. data/lib/overcommit/hook/pre_commit/line_endings.rb +77 -0
  110. data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +16 -0
  111. data/lib/overcommit/hook/pre_commit/mdl.rb +29 -0
  112. data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +16 -0
  113. data/lib/overcommit/hook/pre_commit/nginx_test.rb +26 -0
  114. data/lib/overcommit/hook/pre_commit/pep257.rb +23 -0
  115. data/lib/overcommit/hook/pre_commit/pep8.rb +23 -0
  116. data/lib/overcommit/hook/pre_commit/php_cs.rb +43 -0
  117. data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +57 -0
  118. data/lib/overcommit/hook/pre_commit/php_lint.rb +44 -0
  119. data/lib/overcommit/hook/pre_commit/php_stan.rb +30 -0
  120. data/lib/overcommit/hook/pre_commit/pronto.rb +12 -0
  121. data/lib/overcommit/hook/pre_commit/puppet_lint.rb +26 -0
  122. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +29 -0
  123. data/lib/overcommit/hook/pre_commit/pycodestyle.rb +23 -0
  124. data/lib/overcommit/hook/pre_commit/pydocstyle.rb +23 -0
  125. data/lib/overcommit/hook/pre_commit/pyflakes.rb +32 -0
  126. data/lib/overcommit/hook/pre_commit/pylint.rb +32 -0
  127. data/lib/overcommit/hook/pre_commit/python_flake8.rb +32 -0
  128. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +34 -0
  129. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +58 -0
  130. data/lib/overcommit/hook/pre_commit/rake_target.rb +12 -0
  131. data/lib/overcommit/hook/pre_commit/reek.rb +26 -0
  132. data/lib/overcommit/hook/pre_commit/rst_lint.rb +27 -0
  133. data/lib/overcommit/hook/pre_commit/rubo_cop.rb +35 -0
  134. data/lib/overcommit/hook/pre_commit/ruby_lint.rb +23 -0
  135. data/lib/overcommit/hook/pre_commit/ruby_syntax.rb +27 -0
  136. data/lib/overcommit/hook/pre_commit/scalariform.rb +22 -0
  137. data/lib/overcommit/hook/pre_commit/scalastyle.rb +31 -0
  138. data/lib/overcommit/hook/pre_commit/scss_lint.rb +43 -0
  139. data/lib/overcommit/hook/pre_commit/semi_standard.rb +23 -0
  140. data/lib/overcommit/hook/pre_commit/shell_check.rb +23 -0
  141. data/lib/overcommit/hook/pre_commit/slim_lint.rb +23 -0
  142. data/lib/overcommit/hook/pre_commit/sqlint.rb +26 -0
  143. data/lib/overcommit/hook/pre_commit/standard.rb +23 -0
  144. data/lib/overcommit/hook/pre_commit/stylelint.rb +23 -0
  145. data/lib/overcommit/hook/pre_commit/swift_lint.rb +19 -0
  146. data/lib/overcommit/hook/pre_commit/terraform_format.rb +19 -0
  147. data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
  148. data/lib/overcommit/hook/pre_commit/travis_lint.rb +15 -0
  149. data/lib/overcommit/hook/pre_commit/ts_lint.rb +28 -0
  150. data/lib/overcommit/hook/pre_commit/vint.rb +22 -0
  151. data/lib/overcommit/hook/pre_commit/w3c_css.rb +67 -0
  152. data/lib/overcommit/hook/pre_commit/w3c_html.rb +64 -0
  153. data/lib/overcommit/hook/pre_commit/xml_lint.rb +24 -0
  154. data/lib/overcommit/hook/pre_commit/xml_syntax.rb +21 -0
  155. data/lib/overcommit/hook/pre_commit/yaml_lint.rb +18 -0
  156. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +20 -0
  157. data/lib/overcommit/hook/pre_commit/yard_coverage.rb +90 -0
  158. data/lib/overcommit/hook/pre_commit/yarn_check.rb +37 -0
  159. data/lib/overcommit/hook/pre_push/base.rb +33 -0
  160. data/lib/overcommit/hook/pre_push/brakeman.rb +15 -0
  161. data/lib/overcommit/hook/pre_push/cargo_test.rb +12 -0
  162. data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
  163. data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
  164. data/lib/overcommit/hook/pre_push/minitest.rb +20 -0
  165. data/lib/overcommit/hook/pre_push/php_unit.rb +16 -0
  166. data/lib/overcommit/hook/pre_push/pronto.rb +12 -0
  167. data/lib/overcommit/hook/pre_push/protected_branches.rb +74 -0
  168. data/lib/overcommit/hook/pre_push/pytest.rb +16 -0
  169. data/lib/overcommit/hook/pre_push/python_nose.rb +16 -0
  170. data/lib/overcommit/hook/pre_push/r_spec.rb +16 -0
  171. data/lib/overcommit/hook/pre_push/rake_target.rb +12 -0
  172. data/lib/overcommit/hook/pre_push/test_unit.rb +16 -0
  173. data/lib/overcommit/hook/pre_rebase/base.rb +14 -0
  174. data/lib/overcommit/hook/pre_rebase/merged_commits.rb +31 -0
  175. data/lib/overcommit/hook/prepare_commit_msg/base.rb +25 -0
  176. data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +57 -0
  177. data/lib/overcommit/hook/shared/bower_install.rb +15 -0
  178. data/lib/overcommit/hook/shared/bundle_install.rb +15 -0
  179. data/lib/overcommit/hook/shared/composer_install.rb +15 -0
  180. data/lib/overcommit/hook/shared/index_tags.rb +14 -0
  181. data/lib/overcommit/hook/shared/npm_install.rb +15 -0
  182. data/lib/overcommit/hook/shared/pronto.rb +21 -0
  183. data/lib/overcommit/hook/shared/rake_target.rb +26 -0
  184. data/lib/overcommit/hook/shared/submodule_status.rb +32 -0
  185. data/lib/overcommit/hook/shared/yarn_install.rb +15 -0
  186. data/lib/overcommit/hook_context.rb +19 -0
  187. data/lib/overcommit/hook_context/base.rb +139 -0
  188. data/lib/overcommit/hook_context/commit_msg.rb +48 -0
  189. data/lib/overcommit/hook_context/post_checkout.rb +36 -0
  190. data/lib/overcommit/hook_context/post_commit.rb +33 -0
  191. data/lib/overcommit/hook_context/post_merge.rb +37 -0
  192. data/lib/overcommit/hook_context/post_rewrite.rb +49 -0
  193. data/lib/overcommit/hook_context/pre_commit.rb +212 -0
  194. data/lib/overcommit/hook_context/pre_push.rb +89 -0
  195. data/lib/overcommit/hook_context/pre_rebase.rb +38 -0
  196. data/lib/overcommit/hook_context/prepare_commit_msg.rb +34 -0
  197. data/lib/overcommit/hook_context/run_all.rb +48 -0
  198. data/lib/overcommit/hook_loader/base.rb +48 -0
  199. data/lib/overcommit/hook_loader/built_in_hook_loader.rb +14 -0
  200. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +102 -0
  201. data/lib/overcommit/hook_runner.rb +219 -0
  202. data/lib/overcommit/hook_signer.rb +123 -0
  203. data/lib/overcommit/installer.rb +193 -0
  204. data/lib/overcommit/interrupt_handler.rb +91 -0
  205. data/lib/overcommit/logger.rb +92 -0
  206. data/lib/overcommit/message_processor.rb +148 -0
  207. data/lib/overcommit/os.rb +38 -0
  208. data/lib/overcommit/printer.rb +145 -0
  209. data/lib/overcommit/subprocess.rb +98 -0
  210. data/lib/overcommit/utils.rb +309 -0
  211. data/lib/overcommit/utils/file_utils.rb +71 -0
  212. data/lib/overcommit/utils/messages_utils.rb +77 -0
  213. data/lib/overcommit/version.rb +6 -0
  214. data/libexec/gerrit-change-id +174 -0
  215. data/libexec/index-tags +17 -0
  216. data/template-dir/hooks/commit-msg +116 -0
  217. data/template-dir/hooks/overcommit-hook +116 -0
  218. data/template-dir/hooks/post-checkout +116 -0
  219. data/template-dir/hooks/post-commit +116 -0
  220. data/template-dir/hooks/post-merge +116 -0
  221. data/template-dir/hooks/post-rewrite +116 -0
  222. data/template-dir/hooks/pre-commit +116 -0
  223. data/template-dir/hooks/pre-push +116 -0
  224. data/template-dir/hooks/pre-rebase +116 -0
  225. data/template-dir/hooks/prepare-commit-msg +116 -0
  226. metadata +303 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `flake8` against any modified Python files.
5
+ #
6
+ # @see https://pypi.python.org/pypi/flake8
7
+ class PythonFlake8 < Base
8
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/
9
+
10
+ # Classify 'Exxx' and 'Fxxx' message codes as errors,
11
+ # everything else as warnings.
12
+ # http://flake8.readthedocs.org/en/latest/warnings.html
13
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
14
+ 'EF'.include?(type[0]) ? :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:2:13: F812 list comprehension redefines name from line 1
25
+ extract_messages(
26
+ output.split("\n").grep(MESSAGE_REGEX),
27
+ MESSAGE_REGEX,
28
+ MESSAGE_TYPE_CATEGORIZER
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit
4
+ module Hook
5
+ module PreCommit
6
+ # Runs `rails_best_practices` against Ruby files
7
+ #
8
+ # @see https://github.com/railsbp/rails_best_practices
9
+ class RailsBestPractices < Base
10
+ ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/
11
+
12
+ def run
13
+ result = execute(command, args: applicable_files)
14
+
15
+ return :pass if result.success?
16
+ return [:fail, result.stderr] unless result.stderr.empty?
17
+
18
+ extract_messages(
19
+ filter_output(result.stdout),
20
+ ERROR_REGEXP
21
+ )
22
+ end
23
+
24
+ private
25
+
26
+ def filter_output(stdout)
27
+ stdout.split("\n").select do |message|
28
+ message.match ERROR_REGEXP
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Check to see whether the schema file is in line with the migrations. When a
5
+ # schema file is present but a migration file is not, this is usually a
6
+ # failure. The exception is if the schema is at version 0 (i.e before any
7
+ # migrations have been run). In this case it is OK if there are no migrations.
8
+ class RailsSchemaUpToDate < Base
9
+ def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
10
+ if migration_files.any? && schema_files.none?
11
+ return :fail, "It looks like you're adding a migration, but did not update the schema file"
12
+ elsif migration_files.none? && schema_files.any? && non_zero_schema_version?
13
+ return :fail, "You're trying to change the schema without adding a migration file"
14
+ elsif migration_files.any? && schema_files.any?
15
+ # Get the latest version from the migration filename. Use
16
+ # `File.basename` to prevent finding numbers that could appear in
17
+ # directories, such as the home directory of a user with a number in
18
+ # their username.
19
+ latest_version = migration_files.map do |file|
20
+ File.basename(file)[/\d+/]
21
+ end.sort.last
22
+
23
+ up_to_date = schema.include?(latest_version)
24
+
25
+ unless up_to_date
26
+ return :fail, "The latest migration version you're committing is " \
27
+ "#{latest_version}, but your schema file " \
28
+ "#{schema_files.join(' or ')} is on a different version."
29
+ end
30
+ end
31
+
32
+ :pass
33
+ end
34
+
35
+ private
36
+
37
+ def migration_files
38
+ @migration_files ||= applicable_files.select do |file|
39
+ file.match %r{db/migrate/.*\.rb}
40
+ end
41
+ end
42
+
43
+ def schema_files
44
+ @schema_files ||= applicable_files.select do |file|
45
+ file.match %r{db/schema\.rb|db/structure.*\.sql}
46
+ end
47
+ end
48
+
49
+ def schema
50
+ @schema ||= schema_files.map { |file| File.read(file) }.join
51
+ @schema.tr('_', '')
52
+ end
53
+
54
+ def non_zero_schema_version?
55
+ schema =~ /\d{14}/
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'overcommit/hook/shared/rake_target'
4
+
5
+ module Overcommit::Hook::PreCommit
6
+ # Runs rake targets
7
+ #
8
+ # @see Overcommit::Hook::Shared::RakeTarget
9
+ class RakeTarget < Base
10
+ include Overcommit::Hook::Shared::RakeTarget
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `reek` against any modified Ruby files.
5
+ #
6
+ # @see https://github.com/troessner/reek
7
+ class Reek < Base
8
+ def run
9
+ result = execute(command, args: applicable_files)
10
+ return :pass if result.success?
11
+
12
+ output = scrub_output(result.stdout + result.stderr)
13
+
14
+ extract_messages(
15
+ output,
16
+ /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+):/,
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ def scrub_output(raw_output)
23
+ raw_output.split("\n").grep(/^(.(?!warning))*$/)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `rst-lint` against any modified reStructuredText files
5
+ #
6
+ # @see https://github.com/twolfson/restructuredtext-lint
7
+ class RstLint < Base
8
+ MESSAGE_REGEX = /
9
+ ^(?<type>INFO|WARNING|ERROR|SEVERE)(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s(?<msg>.+)
10
+ /x
11
+
12
+ def run
13
+ result = execute(command, args: applicable_files)
14
+ output = result.stdout.chomp
15
+
16
+ return :pass if result.success?
17
+ return [:fail, result.stderr] unless result.stderr.empty?
18
+
19
+ # example message:
20
+ # WARNING README.rst:7 Title underline too short.
21
+ extract_messages(
22
+ output.split("\n"),
23
+ MESSAGE_REGEX
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `rubocop` against any modified Ruby files.
5
+ #
6
+ # @see http://batsov.com/rubocop/
7
+ class RuboCop < Base
8
+ GENERIC_MESSAGE_TYPE_CATEGORIZER = lambda do |type|
9
+ type.match?(/^warn/) ? :warning : :error
10
+ end
11
+
12
+ COP_MESSAGE_TYPE_CATEGORIZER = lambda do |type|
13
+ type.include?('W') ? :warning : :error
14
+ end
15
+
16
+ def run
17
+ result = execute(command, args: applicable_files)
18
+ return :pass if result.success?
19
+
20
+ generic_messages = extract_messages(
21
+ result.stderr.split("\n"),
22
+ /^(?<type>[a-z]+)/i,
23
+ GENERIC_MESSAGE_TYPE_CATEGORIZER,
24
+ )
25
+
26
+ cop_messages = extract_messages(
27
+ result.stdout.split("\n"),
28
+ /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):[^ ]+ (?<type>[^ ]+)/,
29
+ COP_MESSAGE_TYPE_CATEGORIZER,
30
+ )
31
+
32
+ generic_messages + cop_messages
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `ruby-lint` against any modified Ruby files.
5
+ #
6
+ # @see https://github.com/YorickPeterse/ruby-lint
7
+ class RubyLint < Base
8
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
9
+ type.include?('W') ? :warning : :error
10
+ end
11
+
12
+ def run
13
+ result = execute(command, args: applicable_files)
14
+ return :pass if result.success?
15
+
16
+ extract_messages(
17
+ result.stdout.split("\n"),
18
+ /^(?<file>(?:\w:)?[^:]+):(?<type>[^:]+):(?<line>\d+)/,
19
+ MESSAGE_TYPE_CATEGORIZER
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `ruby -c` against all Ruby files.
5
+ #
6
+ class RubySyntax < Base
7
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
8
+ type.match?(/^(syntax)?\s*error/) ? :error : :warning
9
+ end
10
+
11
+ def run
12
+ result = execute(command, args: applicable_files)
13
+
14
+ result_lines = result.stderr.split("\n")
15
+
16
+ return :pass if result_lines.length.zero?
17
+
18
+ # Example message:
19
+ # path/to/file.rb:1: syntax error, unexpected '^'
20
+ extract_messages(
21
+ result_lines,
22
+ /^(?<file>[^:]+):(?<line>\d+):\s*(?<type>[^,]+),\s*(?<message>.+)/,
23
+ MESSAGE_TYPE_CATEGORIZER
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `scalariform` against any modified Scala files.
5
+ #
6
+ # @see https://github.com/mdr/scalariform
7
+ class Scalariform < Base
8
+ MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)/
9
+
10
+ def run
11
+ result = execute(command, args: applicable_files)
12
+
13
+ # example message:
14
+ # [FAILED] path/to/file.scala
15
+ extract_messages(
16
+ result.stdout.split("\n").grep(MESSAGE_REGEX),
17
+ MESSAGE_REGEX,
18
+ lambda { |type| type == 'ERROR' ? :error : :warning }
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `scalastyle` against any modified Scala files.
5
+ #
6
+ # @see http://www.scalastyle.org/
7
+ class Scalastyle < Base
8
+ MESSAGE_REGEX = /
9
+ ^(?<type>error|warning)\s
10
+ file=(?<file>(?:\w:)?.+)\s
11
+ message=.+\s*
12
+ (line=(?<line>\d+))?
13
+ /x
14
+
15
+ def run
16
+ result = execute(command, args: applicable_files)
17
+ output = result.stdout.chomp + result.stderr.chomp
18
+ messages = output.split("\n").grep(MESSAGE_REGEX)
19
+
20
+ return [:fail, output] unless result.success? || messages.any?
21
+
22
+ # example message:
23
+ # error file=/path/to/file.scala message=Error message line=1 column=1
24
+ extract_messages(
25
+ messages,
26
+ MESSAGE_REGEX,
27
+ lambda { |type| type.to_sym }
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `scss-lint` against any modified SCSS files.
5
+ #
6
+ # @see https://github.com/sds/scss-lint
7
+ class ScssLint < Base
8
+ def run
9
+ result = execute(command, args: applicable_files)
10
+
11
+ # Status code 81 indicates the applicable files were all filtered by
12
+ # exclusions defined by the configuration. In this case, we're happy to
13
+ # return success since there were technically no lints.
14
+ return :pass if [0, 81].include?(result.status)
15
+
16
+ # Any status that isn't indicating lint warnings or errors indicates failure
17
+ return :fail, (result.stdout + result.stderr) unless [1, 2].include?(result.status)
18
+
19
+ begin
20
+ collect_lint_messages(JSON.parse(result.stdout))
21
+ rescue JSON::ParserError => ex
22
+ return :fail, "Unable to parse JSON returned by SCSS-Lint: #{ex.message}\n" \
23
+ "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def collect_lint_messages(files_to_lints)
30
+ files_to_lints.flat_map do |path, lints|
31
+ lints.map do |lint|
32
+ severity = lint['severity'] == 'warning' ? :warning : :error
33
+
34
+ message = lint['reason']
35
+ message = "#{lint['linter']}: #{message}" if lint['linter']
36
+ message = "#{path}:#{lint['line']} #{message}"
37
+
38
+ Overcommit::Hook::Message.new(severity, path, lint['line'], message)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `semistandard` against any modified JavaScript files.
5
+ #
6
+ # @see https://github.com/Flet/semistandard
7
+ class SemiStandard < 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 `shellcheck` against any modified shell script files.
5
+ #
6
+ # @see http://www.shellcheck.net/
7
+ class ShellCheck < Base
8
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
9
+ type.include?('note') ? :warning : :error
10
+ end
11
+
12
+ def run
13
+ result = execute(command, args: applicable_files)
14
+ return :pass if result.success?
15
+
16
+ extract_messages(
17
+ result.stdout.split("\n"),
18
+ /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):[^ ]+ (?<type>[^ ]+)/,
19
+ MESSAGE_TYPE_CATEGORIZER,
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `slim-lint` against any modified Slim templates.
5
+ #
6
+ # @see https://github.com/sds/slim-lint
7
+ class SlimLint < Base
8
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
9
+ type.include?('W') ? :warning : :error
10
+ end
11
+
12
+ def run
13
+ result = execute(command, args: applicable_files)
14
+ return :pass if result.success?
15
+
16
+ extract_messages(
17
+ result.stdout.split("\n"),
18
+ /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+)/,
19
+ MESSAGE_TYPE_CATEGORIZER,
20
+ )
21
+ end
22
+ end
23
+ end