rails_git_hooks 0.7.2 → 0.7.4

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -12
  3. data/lib/rails_git_hooks/checks/commit_msg/jira_prefix.rb +1 -1
  4. data/lib/rails_git_hooks/checks/commit_msg/not_empty.rb +25 -0
  5. data/lib/rails_git_hooks/checks/commit_msg.rb +1 -0
  6. data/lib/rails_git_hooks/checks/post_checkout/npm_install.rb +16 -0
  7. data/lib/rails_git_hooks/checks/post_checkout/yarn_install.rb +16 -0
  8. data/lib/rails_git_hooks/checks/post_checkout.rb +2 -0
  9. data/lib/rails_git_hooks/checks/post_merge/npm_install.rb +16 -0
  10. data/lib/rails_git_hooks/checks/post_merge/yarn_install.rb +16 -0
  11. data/lib/rails_git_hooks/checks/post_merge.rb +2 -0
  12. data/lib/rails_git_hooks/checks/pre_commit/erblint.rb +30 -0
  13. data/lib/rails_git_hooks/checks/pre_commit/eslint.rb +34 -0
  14. data/lib/rails_git_hooks/checks/pre_commit/go_vet.rb +30 -0
  15. data/lib/rails_git_hooks/checks/pre_commit/golint.rb +30 -0
  16. data/lib/rails_git_hooks/checks/pre_commit/haml_lint.rb +30 -0
  17. data/lib/rails_git_hooks/checks/pre_commit/jslint.rb +34 -0
  18. data/lib/rails_git_hooks/checks/pre_commit/php_lint.rb +30 -0
  19. data/lib/rails_git_hooks/checks/pre_commit/pylint.rb +30 -0
  20. data/lib/rails_git_hooks/checks/pre_commit/rails_best_practices.rb +31 -0
  21. data/lib/rails_git_hooks/checks/pre_commit/scss_lint.rb +30 -0
  22. data/lib/rails_git_hooks/checks/pre_commit.rb +10 -0
  23. data/lib/rails_git_hooks/checks/pre_push/run_go_test.rb +24 -0
  24. data/lib/rails_git_hooks/checks/pre_push/run_pytest.rb +24 -0
  25. data/lib/rails_git_hooks/checks/pre_push.rb +2 -0
  26. data/lib/rails_git_hooks/checks/shared/npm_install_check.rb +28 -0
  27. data/lib/rails_git_hooks/checks/shared/yarn_install_check.rb +28 -0
  28. data/lib/rails_git_hooks/checks.rb +2 -0
  29. data/lib/rails_git_hooks/config/defaults.yml +261 -4
  30. data/lib/rails_git_hooks/runtime/check_registry.rb +18 -1
  31. data/lib/rails_git_hooks/runtime/runner.rb +1 -1
  32. data/lib/rails_git_hooks/version.rb +1 -1
  33. metadata +20 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f679908a499fe6aed2f61cf433d27bf93042bf0dcf1ecfe2e4854f05b0e7b9e
4
- data.tar.gz: 481df290f21058504a14d0b6995854861ed7d15099b40a34ec9ccdf6f18fcf3c
3
+ metadata.gz: 4567d9a101acfa807fc891177d9e83960106ad5dfe0f0af498dca983e9f6f394
4
+ data.tar.gz: 4f7ca0ad8c1b8c992ad62b5bf6cf687f41533947d976c50beebde5aa1fd4ce92
5
5
  SHA512:
6
- metadata.gz: 63518e1bcbca51fc17881473b90a0eb510eb2a6e62b26e6471e8890f8fd4e702392b6401f92124d4cd9cc1d398ad0aa03b3c9306a4ce34dc40313d6ab028da52
7
- data.tar.gz: c549c30ca8f646f65bdf10a7281e0f2412bb8a796e0665a80e68c05cdac6ed0a39aed58f48011e23b3eba4622db43b6764bae103e434170a601938f4e5f8291e
6
+ metadata.gz: 0f40853c4ff549beba4cbc468f23460848947d6d6c88a500fa5211257455fbc064f5a6d3308b35b95038bd01eca3b97e1ffd3cccebad691d2ca3023c6184ac62
7
+ data.tar.gz: a3f1d77abbac2ee46d6533da24972b84c132f4119837edbe79039d3b36fdb9f730d9838bb15d56ae21c1a78ffe00052ac2553982f9fe68e56490aaec8d44ea8d
data/README.md CHANGED
@@ -15,21 +15,50 @@ Git hooks for Rails and Ruby projects: sensible defaults out of the box, optiona
15
15
 
16
16
  ## Included hooks and checks
17
17
 
18
+ ### When hooks trigger
19
+
20
+ | Hook | Triggers at |
21
+ |------|-------------|
22
+ | **commit-msg** | After the user finishes editing the commit message, before the commit is created. |
23
+ | **pre-commit** | Before the commit is created (when running `git commit`). |
24
+ | **pre-push** | Before pushing to the remote (when running `git push`). |
25
+ | **post-checkout** | After switching branches or restoring files (e.g. `git checkout`). |
26
+ | **post-merge** | After a merge completes (when running `git merge`). |
27
+
28
+ ### Checks by hook
29
+
18
30
  | Hook | Check key | Enabled By Default | Description |
19
31
  |-------------|----------------------|---------|-------------|
20
32
  | **commit-msg** | `jira-prefix` | ✅ | Prefix commit messages with Jira-style ticket IDs from the branch name (e.g. `[TICKET-123]`). |
21
- | **pre-commit** | `default-branch` | ✅ | Block commits on `master` / `main`; prompt to use a feature branch. |
33
+ | **commit-msg** | `not-empty` | ✅ | Reject empty commit messages. |
34
+ | **pre-commit** | `default-branch` | ✅ | Block commits on `master` / `main`, prompt to use a feature branch. |
22
35
  | **pre-commit** | `debugger-check` | ✅ | Warn (or fail) on debugger statements in Ruby, JavaScript/TypeScript, and Python. |
23
36
  | **pre-commit** | `yaml-format-check` | ✅ | Warn on invalid `.yml` / `.yaml` files. |
24
37
  | **pre-commit** | `json-format-check` | ✅ | Warn on invalid `.json` files. |
25
38
  | **pre-commit** | `migrations-check` | ✅ | Warn when migration files are staged but schema/data_schema files are not. |
26
39
  | **pre-commit** | `whitespace-check` | Off | Fail on trailing whitespace and merge conflict markers. |
27
40
  | **pre-commit** | `rubocop-check` | Off | Run RuboCop on staged Ruby files (requires `rubocop` in the project). |
41
+ | **pre-commit** | `rails-best-practices` | Off | Warn on Rails best practices violations (requires `rails_best_practices` gem). |
42
+ | **pre-commit** | `erblint-check` | Off | Run `erblint` on staged ERB files (requires `erblint` gem). |
43
+ | **pre-commit** | `eslint-check` | Off | Run `eslint` on staged JavaScript files (.js, .jsx, .mjs, .cjs). You can set `command` in config to use an npm script (e.g. `npm run lint`). |
44
+ | **pre-commit** | `golint-check` | Off | Run `golint` on staged Go files (requires `golint`). |
45
+ | **pre-commit** | `haml-lint-check` | Off | Run `haml-lint` on staged HAML files (requires `haml_lint` gem). |
46
+ | **pre-commit** | `jslint-check` | Off | Run `jslint` on staged JavaScript files (.js, .jsx, .mjs, .cjs). |
47
+ | **pre-commit** | `php-lint-check` | Off | Run `php -l` (syntax check) on staged PHP files. |
48
+ | **pre-commit** | `pylint-check` | Off | Run `pylint` on staged Python files. |
49
+ | **pre-commit** | `scss-lint-check` | Off | Run `scss-lint` on staged SCSS files (requires `scss_lint` gem). |
50
+ | **pre-commit** | `go-vet-check` | Off | Run `go vet` on staged Go files. |
28
51
  | **pre-push** | `run-tests` | Off | Run test suite before push (default: `bundle exec rspec`). Enable in config to install pre-push. |
29
- | **post-checkout** | `bundle-install` | | Run `bundle install` when Gemfile or Gemfile.lock changed after a branch checkout. |
30
- | **post-checkout** | `db-migrate` | | Run `rails db:migrate` when migrations or schema changed after a branch checkout. |
31
- | **post-merge** | `bundle-install` | | Run `bundle install` when Gemfile or Gemfile.lock changed after a merge. |
32
- | **post-merge** | `db-migrate` | | Run `rails db:migrate` when migrations or schema changed after a merge. |
52
+ | **pre-push** | `run-pytest` | Off | Run pytest test suite before push. Enable in config to install pre-push. |
53
+ | **pre-push** | `run-go-test` | Off | Run `go test` suite before push. Enable in config to install pre-push. |
54
+ | **post-checkout** | `bundle-install` | Off | Run `bundle install` when Gemfile or Gemfile.lock changed after a branch checkout. |
55
+ | **post-checkout** | `db-migrate` | Off | Run `rails db:migrate` when migrations or schema changed after a branch checkout. |
56
+ | **post-checkout** | `npm-install` | Off | Run `npm install` when package.json or package-lock.json changed after a branch checkout. |
57
+ | **post-checkout** | `yarn-install` | Off | Run `yarn install` when package.json or yarn.lock changed after a branch checkout. |
58
+ | **post-merge** | `bundle-install` | Off | Run `bundle install` when Gemfile or Gemfile.lock changed after a merge. |
59
+ | **post-merge** | `db-migrate` | Off | Run `rails db:migrate` when migrations or schema changed after a merge. |
60
+ | **post-merge** | `npm-install` | Off | Run `npm install` when package.json or package-lock.json changed after a merge. |
61
+ | **post-merge** | `yarn-install` | Off | Run `yarn install` when package.json or yarn.lock changed after a merge. |
33
62
 
34
63
  ## Quick start
35
64
 
@@ -90,6 +119,11 @@ PreCommit:
90
119
  - "lib/**/*.rb"
91
120
  exclude:
92
121
  - "db/schema.rb"
122
+
123
+ # Run eslint via your npm script (useful if the script has its own config):
124
+ Eslint:
125
+ enabled: true
126
+ command: [npm, run, lint]
93
127
  ```
94
128
 
95
129
  ### Per-check options
@@ -105,13 +139,6 @@ PreCommit:
105
139
  | `exclude` | Glob patterns to exclude from `include`. |
106
140
  | `command` | Override the command for checks that run external commands. |
107
141
 
108
- ## CLI reference
109
-
110
- | Command | Description |
111
- |---------|--------------|
112
- | `rails_git_hooks install` | Install hooks that have at least one enabled check in the merged config (defaults + .rails_git_hooks.yml + .rails_git_hooks.local.yml). |
113
- | `rails_git_hooks init` | Create an empty `.rails_git_hooks.yml`. |
114
-
115
142
  ## Contributing
116
143
 
117
144
  Contributions are welcome. Open an [issue](https://github.com/NikitaNazarov1/rails_git_hooks/issues) for bugs or ideas, or submit a pull request.
@@ -4,7 +4,7 @@ module GitHooks
4
4
  module Checks
5
5
  module CommitMsg
6
6
  class JiraPrefix < Base
7
- TICKET_PATTERN = /([A-Z]{2,5}-\d+)/.freeze
7
+ TICKET_PATTERN = /([A-Z]{2,5}-(X+|\d+))/i.freeze
8
8
 
9
9
  check_definition key: 'jira-prefix',
10
10
  hook: :commit_msg,
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module CommitMsg
6
+ class NotEmpty < Base
7
+ check_definition key: 'not-empty',
8
+ hook: :commit_msg,
9
+ description: 'Reject empty commit messages'
10
+
11
+ def run
12
+ message_file = argv.first
13
+ return CheckResult.pass unless message_file && File.file?(message_file)
14
+
15
+ message = File.read(message_file)
16
+ # Strip comment lines (git uses # in the message template) and blank lines
17
+ content = message.lines.reject { |line| line.strip.start_with?('#') || line.strip.empty? }.join.strip
18
+ return CheckResult.pass unless content.empty?
19
+
20
+ CheckResult.fail(messages: ['Commit message must not be empty.'])
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -8,3 +8,4 @@ module GitHooks
8
8
  end
9
9
 
10
10
  require_relative 'commit_msg/jira_prefix'
11
+ require_relative 'commit_msg/not_empty'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PostCheckout
6
+ class NpmInstall < Base
7
+ include NpmInstallCheck
8
+
9
+ check_definition key: 'npm-install',
10
+ hook: :post_checkout,
11
+ description: 'Run npm install when package.json or package-lock.json changed (branch checkout)',
12
+ **NpmInstallCheck::DEFINITION_OPTIONS
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PostCheckout
6
+ class YarnInstall < Base
7
+ include YarnInstallCheck
8
+
9
+ check_definition key: 'yarn-install',
10
+ hook: :post_checkout,
11
+ description: 'Run yarn install when package.json or yarn.lock changed (branch checkout)',
12
+ **YarnInstallCheck::DEFINITION_OPTIONS
13
+ end
14
+ end
15
+ end
16
+ end
@@ -9,3 +9,5 @@ end
9
9
 
10
10
  require_relative 'post_checkout/bundle_install'
11
11
  require_relative 'post_checkout/db_migrate'
12
+ require_relative 'post_checkout/npm_install'
13
+ require_relative 'post_checkout/yarn_install'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PostMerge
6
+ class NpmInstall < Base
7
+ include NpmInstallCheck
8
+
9
+ check_definition key: 'npm-install',
10
+ hook: :post_merge,
11
+ description: 'Run npm install when package.json or package-lock.json changed (after merge)',
12
+ **NpmInstallCheck::DEFINITION_OPTIONS
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PostMerge
6
+ class YarnInstall < Base
7
+ include YarnInstallCheck
8
+
9
+ check_definition key: 'yarn-install',
10
+ hook: :post_merge,
11
+ description: 'Run yarn install when package.json or yarn.lock changed (after merge)',
12
+ **YarnInstallCheck::DEFINITION_OPTIONS
13
+ end
14
+ end
15
+ end
16
+ end
@@ -9,3 +9,5 @@ end
9
9
 
10
10
  require_relative 'post_merge/bundle_install'
11
11
  require_relative 'post_merge/db_migrate'
12
+ require_relative 'post_merge/npm_install'
13
+ require_relative 'post_merge/yarn_install'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class ErbLint < Base
7
+ check_definition key: 'erblint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run erblint on staged ERB files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['bundle'], 'libraries' => ['erblint'] },
14
+ command: %w[bundle exec erblint],
15
+ install_hint: 'Add `gem "erblint"` to your Gemfile and run bundle install'
16
+
17
+ def run
18
+ erb_files = applicable_files.select { |path| path.end_with?('.erb') && File.file?(path) }
19
+ return CheckResult.pass if erb_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *erb_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class Eslint < Base
7
+ JS_EXTENSIONS = %w[.js .jsx .mjs .cjs].freeze
8
+
9
+ check_definition key: 'eslint-check',
10
+ hook: :pre_commit,
11
+ description: 'Run eslint on staged JavaScript files',
12
+ file_based: true,
13
+ enabled: false,
14
+ quiet: true,
15
+ dependencies: { 'executables' => ['eslint'] },
16
+ command: %w[eslint],
17
+ install_hint: 'Install eslint (e.g. npm install -D eslint) or override command in config'
18
+
19
+ def run
20
+ js_files = applicable_files.select do |path|
21
+ File.file?(path) && JS_EXTENSIONS.include?(File.extname(path))
22
+ end
23
+ return CheckResult.pass if js_files.empty?
24
+
25
+ output, status = capture(*Array(config['command']), *js_files)
26
+ return CheckResult.pass if status.success?
27
+
28
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
29
+ CheckResult.fail(messages: messages)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class GoVet < Base
7
+ check_definition key: 'go-vet-check',
8
+ hook: :pre_commit,
9
+ description: 'Run go vet on staged Go files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['go'] },
14
+ command: %w[go vet],
15
+ install_hint: 'Ensure Go toolchain is installed and on PATH'
16
+
17
+ def run
18
+ go_files = applicable_files.select { |path| File.file?(path) && File.extname(path) == '.go' }
19
+ return CheckResult.pass if go_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *go_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class Golint < Base
7
+ check_definition key: 'golint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run golint on staged Go files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['golint'] },
14
+ command: %w[golint],
15
+ install_hint: 'Install golint or override command in config'
16
+
17
+ def run
18
+ go_files = applicable_files.select { |path| File.file?(path) && File.extname(path) == '.go' }
19
+ return CheckResult.pass if go_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *go_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class HamlLint < Base
7
+ check_definition key: 'haml-lint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run haml-lint on staged HAML files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['bundle'], 'libraries' => ['haml_lint'] },
14
+ command: %w[bundle exec haml-lint],
15
+ install_hint: 'Add `gem "haml_lint"` to your Gemfile and run bundle install'
16
+
17
+ def run
18
+ haml_files = applicable_files.select { |path| path.end_with?('.haml') && File.file?(path) }
19
+ return CheckResult.pass if haml_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *haml_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class Jslint < Base
7
+ JS_EXTENSIONS = %w[.js .jsx .mjs .cjs].freeze
8
+
9
+ check_definition key: 'jslint-check',
10
+ hook: :pre_commit,
11
+ description: 'Run jslint on staged JavaScript files',
12
+ file_based: true,
13
+ enabled: false,
14
+ quiet: true,
15
+ dependencies: { 'executables' => ['jslint'] },
16
+ command: %w[jslint],
17
+ install_hint: 'Install jslint or override command in config'
18
+
19
+ def run
20
+ js_files = applicable_files.select do |path|
21
+ File.file?(path) && JS_EXTENSIONS.include?(File.extname(path))
22
+ end
23
+ return CheckResult.pass if js_files.empty?
24
+
25
+ output, status = capture(*Array(config['command']), *js_files)
26
+ return CheckResult.pass if status.success?
27
+
28
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
29
+ CheckResult.fail(messages: messages)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class PhpLint < Base
7
+ check_definition key: 'php-lint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run php -l (syntax check) on staged PHP files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['php'] },
14
+ command: %w[php -l],
15
+ install_hint: 'Ensure PHP is installed and on PATH'
16
+
17
+ def run
18
+ php_files = applicable_files.select { |path| path.end_with?('.php') && File.file?(path) }
19
+ return CheckResult.pass if php_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *php_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class Pylint < Base
7
+ check_definition key: 'pylint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run pylint on staged Python files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['pylint'] },
14
+ command: %w[pylint],
15
+ install_hint: 'Install pylint (e.g. pip install pylint) or override command in config'
16
+
17
+ def run
18
+ py_files = applicable_files.select { |path| path.end_with?('.py') && File.file?(path) }
19
+ return CheckResult.pass if py_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *py_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class RailsBestPractices < Base
7
+ check_definition key: 'rails-best-practices',
8
+ hook: :pre_commit,
9
+ description: 'Warn on Rails best practices violations',
10
+ file_based: true,
11
+ enabled: false,
12
+ on_fail: :warn,
13
+ quiet: true,
14
+ dependencies: { 'executables' => ['bundle'], 'libraries' => ['rails_best_practices'] },
15
+ command: %w[bundle exec rails_best_practices],
16
+ install_hint: 'Add `gem "rails_best_practices"` to your Gemfile and run bundle install'
17
+
18
+ def run
19
+ ruby_files = applicable_files.select { |path| File.extname(path) == '.rb' && File.file?(path) }
20
+ return CheckResult.pass if ruby_files.empty?
21
+
22
+ output, status = capture(*Array(config['command']), *ruby_files)
23
+ return CheckResult.pass if status.success?
24
+
25
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
26
+ CheckResult.fail(messages: messages)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PreCommit
6
+ class ScssLint < Base
7
+ check_definition key: 'scss-lint-check',
8
+ hook: :pre_commit,
9
+ description: 'Run scss-lint on staged SCSS files',
10
+ file_based: true,
11
+ enabled: false,
12
+ quiet: true,
13
+ dependencies: { 'executables' => ['bundle'], 'libraries' => ['scss_lint'] },
14
+ command: %w[bundle exec scss-lint],
15
+ install_hint: 'Add `gem "scss_lint"` to your Gemfile and run bundle install'
16
+
17
+ def run
18
+ scss_files = applicable_files.select { |path| path.end_with?('.scss') && File.file?(path) }
19
+ return CheckResult.pass if scss_files.empty?
20
+
21
+ output, status = capture(*Array(config['command']), *scss_files)
22
+ return CheckResult.pass if status.success?
23
+
24
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
25
+ CheckResult.fail(messages: messages)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -14,3 +14,13 @@ require_relative 'pre_commit/json_format_check'
14
14
  require_relative 'pre_commit/migrations_check'
15
15
  require_relative 'pre_commit/whitespace_check'
16
16
  require_relative 'pre_commit/rubocop'
17
+ require_relative 'pre_commit/rails_best_practices'
18
+ require_relative 'pre_commit/erblint'
19
+ require_relative 'pre_commit/eslint'
20
+ require_relative 'pre_commit/golint'
21
+ require_relative 'pre_commit/haml_lint'
22
+ require_relative 'pre_commit/jslint'
23
+ require_relative 'pre_commit/php_lint'
24
+ require_relative 'pre_commit/pylint'
25
+ require_relative 'pre_commit/scss_lint'
26
+ require_relative 'pre_commit/go_vet'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PrePush
6
+ class RunGoTest < Base
7
+ check_definition key: 'run-go-test',
8
+ hook: :pre_push,
9
+ description: 'Run go test suite before push',
10
+ dependencies: { 'executables' => ['go'] },
11
+ command: %w[go test ./...],
12
+ install_hint: 'Ensure Go toolchain is installed and `go test ./...` runs successfully'
13
+
14
+ def run
15
+ output, status = capture(*Array(config['command']))
16
+ return CheckResult.pass if status.success?
17
+
18
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
19
+ CheckResult.fail(messages: messages)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ module PrePush
6
+ class RunPytest < Base
7
+ check_definition key: 'run-pytest',
8
+ hook: :pre_push,
9
+ description: 'Run pytest test suite before push',
10
+ dependencies: { 'executables' => ['pytest'] },
11
+ command: %w[pytest],
12
+ install_hint: 'Install pytest (e.g. pip install pytest) and ensure pytest runs successfully'
13
+
14
+ def run
15
+ output, status = capture(*Array(config['command']))
16
+ return CheckResult.pass if status.success?
17
+
18
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
19
+ CheckResult.fail(messages: messages)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -8,3 +8,5 @@ module GitHooks
8
8
  end
9
9
 
10
10
  require_relative 'pre_push/run_tests'
11
+ require_relative 'pre_push/run_pytest'
12
+ require_relative 'pre_push/run_go_test'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ # Shared logic and options for "run npm install when package.json/package-lock.json changed"
6
+ # (post-checkout and post-merge). Each hook has its own class that passes hook + description.
7
+ module NpmInstallCheck
8
+ DEFINITION_OPTIONS = {
9
+ file_based: true,
10
+ enabled: false,
11
+ include: %w[package.json package-lock.json],
12
+ dependencies: { executables: ['npm'] },
13
+ command: %w[npm install],
14
+ install_hint: 'Ensure npm is available'
15
+ }.freeze
16
+
17
+ def run
18
+ return CheckResult.pass if applicable_files.empty?
19
+
20
+ output, status = capture(*Array(config['command']))
21
+ return CheckResult.pass if status.success?
22
+
23
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
24
+ CheckResult.fail(messages: messages)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHooks
4
+ module Checks
5
+ # Shared logic and options for "run yarn install when package.json/yarn.lock changed"
6
+ # (post-checkout and post-merge). Each hook has its own class that passes hook + description.
7
+ module YarnInstallCheck
8
+ DEFINITION_OPTIONS = {
9
+ file_based: true,
10
+ enabled: false,
11
+ include: %w[package.json yarn.lock],
12
+ dependencies: { executables: ['yarn'] },
13
+ command: %w[yarn install],
14
+ install_hint: 'Ensure yarn is available'
15
+ }.freeze
16
+
17
+ def run
18
+ return CheckResult.pass if applicable_files.empty?
19
+
20
+ output, status = capture(*Array(config['command']))
21
+ return CheckResult.pass if status.success?
22
+
23
+ messages = output.split("\n").map(&:rstrip).reject(&:empty?)
24
+ CheckResult.fail(messages: messages)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -6,5 +6,7 @@ require_relative 'checks/commit_msg'
6
6
  require_relative 'checks/pre_push'
7
7
  require_relative 'checks/shared/bundle_install_check'
8
8
  require_relative 'checks/shared/db_migrate_check'
9
+ require_relative 'checks/shared/npm_install_check'
10
+ require_relative 'checks/shared/yarn_install_check'
9
11
  require_relative 'checks/post_checkout'
10
12
  require_relative 'checks/post_merge'
@@ -96,6 +96,160 @@ PreCommit:
96
96
  file_based: true
97
97
  install_hint: Add `gem "rubocop"` to your Gemfile and run bundle install
98
98
 
99
+ RailsBestPractices:
100
+ enabled: false
101
+ quiet: true
102
+ on_fail: warn
103
+ on_warn: warn
104
+ on_missing_dependency: warn
105
+ include: []
106
+ exclude: []
107
+ dependencies:
108
+ executables: [bundle]
109
+ libraries: [rails_best_practices]
110
+ command: [bundle, exec, rails_best_practices]
111
+ description: Warn on Rails best practices violations
112
+ file_based: true
113
+ install_hint: Add `gem "rails_best_practices"` to your Gemfile and run bundle install
114
+
115
+ ErbLint:
116
+ enabled: false
117
+ quiet: true
118
+ on_fail: fail
119
+ on_warn: warn
120
+ on_missing_dependency: warn
121
+ include: []
122
+ exclude: []
123
+ dependencies:
124
+ executables: [bundle]
125
+ libraries: [erblint]
126
+ command: [bundle, exec, erblint]
127
+ description: Run erblint on staged ERB files
128
+ file_based: true
129
+ install_hint: Add `gem "erblint"` to your Gemfile and run bundle install
130
+
131
+ Eslint:
132
+ enabled: false
133
+ quiet: true
134
+ on_fail: fail
135
+ on_warn: warn
136
+ on_missing_dependency: warn
137
+ include: []
138
+ exclude: []
139
+ dependencies:
140
+ executables: [eslint]
141
+ command: [eslint]
142
+ description: Run eslint on staged JavaScript files
143
+ file_based: true
144
+ install_hint: Install eslint (e.g. npm install -D eslint) or override command in config
145
+
146
+ Golint:
147
+ enabled: false
148
+ quiet: true
149
+ on_fail: fail
150
+ on_warn: warn
151
+ on_missing_dependency: warn
152
+ include: []
153
+ exclude: []
154
+ dependencies:
155
+ executables: [golint]
156
+ command: [golint]
157
+ description: Run golint on staged Go files
158
+ file_based: true
159
+ install_hint: Install golint (e.g. go install golang.org/x/lint/golint@latest) or override command in config
160
+
161
+ HamlLint:
162
+ enabled: false
163
+ quiet: true
164
+ on_fail: fail
165
+ on_warn: warn
166
+ on_missing_dependency: warn
167
+ include: []
168
+ exclude: []
169
+ dependencies:
170
+ executables: [bundle]
171
+ libraries: [haml_lint]
172
+ command: [bundle, exec, haml-lint]
173
+ description: Run haml-lint on staged HAML files
174
+ file_based: true
175
+ install_hint: Add `gem "haml_lint"` to your Gemfile and run bundle install
176
+
177
+ Jslint:
178
+ enabled: false
179
+ quiet: true
180
+ on_fail: fail
181
+ on_warn: warn
182
+ on_missing_dependency: warn
183
+ include: []
184
+ exclude: []
185
+ dependencies:
186
+ executables: [jslint]
187
+ command: [jslint]
188
+ description: Run jslint on staged JavaScript files
189
+ file_based: true
190
+ install_hint: Install jslint (e.g. npm install -D jslint or npm install -g jslint) or override command in config
191
+
192
+ PhpLint:
193
+ enabled: false
194
+ quiet: true
195
+ on_fail: fail
196
+ on_warn: warn
197
+ on_missing_dependency: warn
198
+ include: []
199
+ exclude: []
200
+ dependencies:
201
+ executables: [php]
202
+ command: [php, "-l"]
203
+ description: Run php -l (syntax check) on staged PHP files
204
+ file_based: true
205
+ install_hint: Ensure PHP is installed and on PATH
206
+
207
+ Pylint:
208
+ enabled: false
209
+ quiet: true
210
+ on_fail: fail
211
+ on_warn: warn
212
+ on_missing_dependency: warn
213
+ include: []
214
+ exclude: []
215
+ dependencies:
216
+ executables: [pylint]
217
+ command: [pylint]
218
+ description: Run pylint on staged Python files
219
+ file_based: true
220
+ install_hint: Install pylint (e.g. pip install pylint) or override command in config
221
+
222
+ ScssLint:
223
+ enabled: false
224
+ quiet: true
225
+ on_fail: fail
226
+ on_warn: warn
227
+ on_missing_dependency: warn
228
+ include: []
229
+ exclude: []
230
+ dependencies:
231
+ executables: [bundle]
232
+ libraries: [scss_lint]
233
+ command: [bundle, exec, scss-lint]
234
+ description: Run scss-lint on staged SCSS files
235
+ file_based: true
236
+ install_hint: Add `gem "scss_lint"` to your Gemfile and run bundle install
237
+
238
+ GoVet:
239
+ enabled: false
240
+ quiet: true
241
+ on_fail: fail
242
+ on_warn: warn
243
+ on_missing_dependency: warn
244
+ include: []
245
+ exclude: []
246
+ dependencies:
247
+ executables: [go]
248
+ command: [go, vet]
249
+ description: Run go vet on staged Go files
250
+ file_based: true
251
+ install_hint: Ensure Go toolchain is installed and on PATH
252
+
99
253
  CommitMsg:
100
254
  JiraPrefix:
101
255
  enabled: true
@@ -110,6 +264,19 @@ CommitMsg:
110
264
  description: Prefix commit messages with ticket id from branch
111
265
  file_based: false
112
266
 
267
+ NotEmpty:
268
+ enabled: true
269
+ quiet: false
270
+ on_fail: fail
271
+ on_warn: warn
272
+ on_missing_dependency: warn
273
+ include: []
274
+ exclude: []
275
+ dependencies: {}
276
+ command: []
277
+ description: Reject empty commit messages
278
+ file_based: false
279
+
113
280
  PrePush:
114
281
  RunTests:
115
282
  enabled: false
@@ -127,9 +294,39 @@ PrePush:
127
294
  file_based: false
128
295
  install_hint: Install test dependencies and ensure `bundle exec rspec` runs successfully
129
296
 
297
+ RunPytest:
298
+ enabled: false
299
+ quiet: false
300
+ on_fail: fail
301
+ on_warn: warn
302
+ on_missing_dependency: warn
303
+ include: []
304
+ exclude: []
305
+ dependencies:
306
+ executables: [pytest]
307
+ command: [pytest]
308
+ description: Run pytest test suite before push
309
+ file_based: false
310
+ install_hint: Install pytest (e.g. pip install pytest) and ensure pytest runs successfully
311
+
312
+ RunGoTest:
313
+ enabled: false
314
+ quiet: false
315
+ on_fail: fail
316
+ on_warn: warn
317
+ on_missing_dependency: warn
318
+ include: []
319
+ exclude: []
320
+ dependencies:
321
+ executables: [go]
322
+ command: [go, test, "./..."]
323
+ description: Run go test suite before push
324
+ file_based: false
325
+ install_hint: Ensure Go toolchain is installed and `go test ./...` runs successfully
326
+
130
327
  PostCheckout:
131
328
  BundleInstall:
132
- enabled: true
329
+ enabled: false
133
330
  quiet: false
134
331
  on_fail: fail
135
332
  on_warn: warn
@@ -144,7 +341,7 @@ PostCheckout:
144
341
  install_hint: Ensure bundle is available
145
342
 
146
343
  DbMigrate:
147
- enabled: true
344
+ enabled: false
148
345
  quiet: false
149
346
  on_fail: fail
150
347
  on_warn: warn
@@ -158,9 +355,39 @@ PostCheckout:
158
355
  file_based: true
159
356
  install_hint: Rails app with db:migrate (or override command in config)
160
357
 
358
+ NpmInstall:
359
+ enabled: false
360
+ quiet: false
361
+ on_fail: fail
362
+ on_warn: warn
363
+ on_missing_dependency: warn
364
+ include: [package.json, package-lock.json]
365
+ exclude: []
366
+ dependencies:
367
+ executables: [npm]
368
+ command: [npm, install]
369
+ description: Run npm install when package.json or package-lock.json changed (branch checkout)
370
+ file_based: true
371
+ install_hint: Ensure npm is available
372
+
373
+ YarnInstall:
374
+ enabled: false
375
+ quiet: false
376
+ on_fail: fail
377
+ on_warn: warn
378
+ on_missing_dependency: warn
379
+ include: [package.json, yarn.lock]
380
+ exclude: []
381
+ dependencies:
382
+ executables: [yarn]
383
+ command: [yarn, install]
384
+ description: Run yarn install when package.json or yarn.lock changed (branch checkout)
385
+ file_based: true
386
+ install_hint: Ensure yarn is available
387
+
161
388
  PostMerge:
162
389
  BundleInstall:
163
- enabled: true
390
+ enabled: false
164
391
  quiet: false
165
392
  on_fail: fail
166
393
  on_warn: warn
@@ -175,7 +402,7 @@ PostMerge:
175
402
  install_hint: Ensure bundle is available
176
403
 
177
404
  DbMigrate:
178
- enabled: true
405
+ enabled: false
179
406
  quiet: false
180
407
  on_fail: fail
181
408
  on_warn: warn
@@ -188,3 +415,33 @@ PostMerge:
188
415
  description: Run db:migrate when migrations or schema changed (after merge)
189
416
  file_based: true
190
417
  install_hint: Rails app with db:migrate (or override command in config)
418
+
419
+ NpmInstall:
420
+ enabled: false
421
+ quiet: false
422
+ on_fail: fail
423
+ on_warn: warn
424
+ on_missing_dependency: warn
425
+ include: [package.json, package-lock.json]
426
+ exclude: []
427
+ dependencies:
428
+ executables: [npm]
429
+ command: [npm, install]
430
+ description: Run npm install when package.json or package-lock.json changed (after merge)
431
+ file_based: true
432
+ install_hint: Ensure npm is available
433
+
434
+ YarnInstall:
435
+ enabled: false
436
+ quiet: false
437
+ on_fail: fail
438
+ on_warn: warn
439
+ on_missing_dependency: warn
440
+ include: [package.json, yarn.lock]
441
+ exclude: []
442
+ dependencies:
443
+ executables: [yarn]
444
+ command: [yarn, install]
445
+ description: Run yarn install when package.json or yarn.lock changed (after merge)
446
+ file_based: true
447
+ install_hint: Ensure yarn is available
@@ -10,12 +10,29 @@ module GitHooks
10
10
  Checks::PreCommit::MigrationsCheck,
11
11
  Checks::PreCommit::WhitespaceCheck,
12
12
  Checks::PreCommit::RuboCop,
13
+ Checks::PreCommit::RailsBestPractices,
14
+ Checks::PreCommit::ErbLint,
15
+ Checks::PreCommit::Eslint,
16
+ Checks::PreCommit::Golint,
17
+ Checks::PreCommit::HamlLint,
18
+ Checks::PreCommit::Jslint,
19
+ Checks::PreCommit::PhpLint,
20
+ Checks::PreCommit::Pylint,
21
+ Checks::PreCommit::ScssLint,
22
+ Checks::PreCommit::GoVet,
13
23
  Checks::CommitMsg::JiraPrefix,
24
+ Checks::CommitMsg::NotEmpty,
14
25
  Checks::PrePush::RunTests,
26
+ Checks::PrePush::RunPytest,
27
+ Checks::PrePush::RunGoTest,
15
28
  Checks::PostCheckout::BundleInstall,
16
29
  Checks::PostCheckout::DbMigrate,
30
+ Checks::PostCheckout::NpmInstall,
31
+ Checks::PostCheckout::YarnInstall,
17
32
  Checks::PostMerge::BundleInstall,
18
- Checks::PostMerge::DbMigrate
33
+ Checks::PostMerge::DbMigrate,
34
+ Checks::PostMerge::NpmInstall,
35
+ Checks::PostMerge::YarnInstall
19
36
  ].freeze
20
37
 
21
38
  def self.all
@@ -53,7 +53,7 @@ module GitHooks
53
53
  @modified_files ||= case @hook_name
54
54
  when :pre_commit then @repo.staged_files
55
55
  when :post_checkout
56
- argv[2] == '1' ? @repo.changed_files(argv[0], argv[1]) : []
56
+ @argv[2] == '1' ? @repo.changed_files(@argv[0], @argv[1]) : []
57
57
  when :post_merge
58
58
  @repo.changed_files('ORIG_HEAD', 'HEAD')
59
59
  else []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitHooks
4
- VERSION = '0.7.2'
4
+ VERSION = '0.7.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_git_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Nazarov
@@ -26,24 +26,43 @@ files:
26
26
  - lib/rails_git_hooks/checks/base.rb
27
27
  - lib/rails_git_hooks/checks/commit_msg.rb
28
28
  - lib/rails_git_hooks/checks/commit_msg/jira_prefix.rb
29
+ - lib/rails_git_hooks/checks/commit_msg/not_empty.rb
29
30
  - lib/rails_git_hooks/checks/post_checkout.rb
30
31
  - lib/rails_git_hooks/checks/post_checkout/bundle_install.rb
31
32
  - lib/rails_git_hooks/checks/post_checkout/db_migrate.rb
33
+ - lib/rails_git_hooks/checks/post_checkout/npm_install.rb
34
+ - lib/rails_git_hooks/checks/post_checkout/yarn_install.rb
32
35
  - lib/rails_git_hooks/checks/post_merge.rb
33
36
  - lib/rails_git_hooks/checks/post_merge/bundle_install.rb
34
37
  - lib/rails_git_hooks/checks/post_merge/db_migrate.rb
38
+ - lib/rails_git_hooks/checks/post_merge/npm_install.rb
39
+ - lib/rails_git_hooks/checks/post_merge/yarn_install.rb
35
40
  - lib/rails_git_hooks/checks/pre_commit.rb
36
41
  - lib/rails_git_hooks/checks/pre_commit/debugger_check.rb
37
42
  - lib/rails_git_hooks/checks/pre_commit/default_branch.rb
43
+ - lib/rails_git_hooks/checks/pre_commit/erblint.rb
44
+ - lib/rails_git_hooks/checks/pre_commit/eslint.rb
45
+ - lib/rails_git_hooks/checks/pre_commit/go_vet.rb
46
+ - lib/rails_git_hooks/checks/pre_commit/golint.rb
47
+ - lib/rails_git_hooks/checks/pre_commit/haml_lint.rb
48
+ - lib/rails_git_hooks/checks/pre_commit/jslint.rb
38
49
  - lib/rails_git_hooks/checks/pre_commit/json_format_check.rb
39
50
  - lib/rails_git_hooks/checks/pre_commit/migrations_check.rb
51
+ - lib/rails_git_hooks/checks/pre_commit/php_lint.rb
52
+ - lib/rails_git_hooks/checks/pre_commit/pylint.rb
53
+ - lib/rails_git_hooks/checks/pre_commit/rails_best_practices.rb
40
54
  - lib/rails_git_hooks/checks/pre_commit/rubocop.rb
55
+ - lib/rails_git_hooks/checks/pre_commit/scss_lint.rb
41
56
  - lib/rails_git_hooks/checks/pre_commit/whitespace_check.rb
42
57
  - lib/rails_git_hooks/checks/pre_commit/yaml_format_check.rb
43
58
  - lib/rails_git_hooks/checks/pre_push.rb
59
+ - lib/rails_git_hooks/checks/pre_push/run_go_test.rb
60
+ - lib/rails_git_hooks/checks/pre_push/run_pytest.rb
44
61
  - lib/rails_git_hooks/checks/pre_push/run_tests.rb
45
62
  - lib/rails_git_hooks/checks/shared/bundle_install_check.rb
46
63
  - lib/rails_git_hooks/checks/shared/db_migrate_check.rb
64
+ - lib/rails_git_hooks/checks/shared/npm_install_check.rb
65
+ - lib/rails_git_hooks/checks/shared/yarn_install_check.rb
47
66
  - lib/rails_git_hooks/cli.rb
48
67
  - lib/rails_git_hooks/config/constants.rb
49
68
  - lib/rails_git_hooks/config/defaults.yml