diff --git a/CHANGELOG.md b/CHANGELOG.md index b35a6dfb0a8..e12eb35f071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [#7735](https://github.com/rubocop-hq/rubocop/issues/7735): `NodePattern` and `AST` classes have been moved to the [`rubocop-ast` gem](https://github.com/rubocop-hq/rubocop-ast). ([@marcandre][]) * [#7950](https://github.com/rubocop-hq/rubocop/pull/7950): Add new `Lint/DeprecatedOpenSSLConstant` cop. ([@bdewater][]) * [#7976](https://github.com/rubocop-hq/rubocop/issues/7976): Add `AllowAliasSyntax` and `AllowedMethods` options for `Layout/EmptyLinesAroundAttributeAccessor`. ([@koic][]) +* [#7984](https://github.com/rubocop-hq/rubocop/pull/7984): New `rake` task "check_commit" will run `rspec` and `rubocop` on files touched by the last commit. ([@marcandre][]) ### Bug fixes diff --git a/manual/contributing.md b/manual/contributing.md index 3c1445fe285..59e1a9b2b88 100644 --- a/manual/contributing.md +++ b/manual/contributing.md @@ -17,6 +17,10 @@ Patches in any form are always welcome! GitHub pull requests are even better! :- Before submitting a patch or a pull request make sure all tests are passing and that your patch is in line with the [contribution guidelines](https://github.com/rubocop-hq/rubocop/blob/master/CONTRIBUTING.md). + +A handy way to test only the files that you have modified in the last commit +(with `rspec` and `rubocop`) is to use `rake check_commit`. + Also see the [Development section](development.md). ## Documentation diff --git a/tasks/check_commit.rake b/tasks/check_commit.rake new file mode 100644 index 00000000000..3c02e5a04b6 --- /dev/null +++ b/tasks/check_commit.rake @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +def commit_paths(commit_range) + commit_range = "#{commit_range}~..HEAD" if commit_range.include?('..') + `git diff-tree --no-commit-id --name-only -r #{commit_range}`.split("\n") +ensure + exit($CHILD_STATUS.exitstatus) if $CHILD_STATUS.exitstatus != 0 +end + +desc 'Check files modified in commit (default: HEAD) with rspec and rubocop' +RuboCop::RakeTask.new(:check_commit, :commit) do |t, args| + commit = args[:commit] || 'HEAD' + paths = commit_paths(commit) + specs = paths.select { |p| p.start_with?('spec') } + + puts "Checking: #{paths.join(' ')}" + RuboCop::SpecRunner.new(specs).run_specs + + t.patterns = paths +end