Skip to content

Commit

Permalink
[Fixes #7827] Add pre-commit hook
Browse files Browse the repository at this point in the history
Add an entry point (hook) for using RuboCop with the pre-commit
framework. The entry point allows users to add a minimal pre-commit
config to their project and then it will run RuboCop on commit.

For details on the pre-commit project, see: https://pre-commit.com/.
Here is the framework's introduction:

> Git hook scripts are useful for identifying simple issues before
> submission to code review. We run our hooks on every commit to
> automatically point out issues in code such as missing semicolons,
> trailing whitespace, and debug statements. By pointing these issues
> out before code review, this allows a code reviewer to focus on the
> architecture of a change while not wasting time with trivial style
> nitpicks.
>
> As we created more libraries and projects we recognized that sharing
> our pre-commit hooks across projects is painful. We copied and pasted
> unwieldy bash scripts from project to project and had to manually
> change the hooks to work for different project structures.
>
> We believe that you should always use the best industry standard >
> linters. Some of the best linters are written in languages that you do
> not use in your project or have installed on your machine. For example
> scss-lint is a linter for SCSS written in Ruby. If you’re writing a
> project in node you should be able to use scss-lint as a pre-commit
> hook without adding a Gemfile to your project or understanding how to
> get scss-lint installed.
>
> We built pre-commit to solve our hook issues. It is a multi-language
> package manager for pre-commit hooks. You specify a list of hooks you
> want and pre-commit manages the installation and execution of any hook
> written in any language before every commit. pre-commit is
> specifically designed to not require root access. If one of your
> developers doesn’t have node installed but modifies a JavaScript file,
> pre-commit automatically handles downloading and building node to run
> eslint without root.

Fixes #7827
Closes #8969

Co-Authored-By: Adithya Balaji <adithyabsk@gmail.com>
  • Loading branch information
2 people authored and bbatsov committed Jan 17, 2021
1 parent 257880c commit ff19e9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: rubocop
name: rubocop
entry: rubocop
language: ruby
types: ['ruby']
args: ['--auto-correct', '--force-exclusion']
1 change: 1 addition & 0 deletions changelog/new_add_precommit_hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#7827](https://github.com/rubocop-hq/rubocop/pull/7827): Add pre-commit hook. ([@jdufresne][], [@adithyabsk][])
16 changes: 15 additions & 1 deletion docs/modules/ROOT/pages/integration_with_other_tools.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ capabilities of this extension.
Here's one great opportunity to contribute to RuboCop - implement
RuboCop integration for your favorite editor.

== Git pre-commit hook integration
== Git pre-commit hook integration with overcommit

https://github.com/brigade/overcommit[overcommit] is a fully configurable and
extendable Git commit hook manager. To use RuboCop with overcommit, add the
Expand All @@ -76,6 +76,20 @@ PreCommit:
enabled: true
----

== Git pre-commit hook integration with pre-commit

https://pre-commit.com/[pre-commit] is a framework for managing and maintaining
multi-language pre-commit hooks. To use RuboCop with pre-commit, add the
following to your `.pre-commit-config.yaml` file:

[source,yaml]
----
- repo: https://github.com/rubocop-hq/rubocop
rev: v1.8.1
hooks:
- id: rubocop
----

== Guard integration

If you're fond of https://github.com/guard/guard[Guard] you might
Expand Down

0 comments on commit ff19e9a

Please sign in to comment.