Skip to content

Commit

Permalink
add hook to detect ruby code smells with reek
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanjiman committed May 10, 2018
1 parent aacb388 commit 7aebd6a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .pre-commit-hooks.yaml
Expand Up @@ -36,6 +36,13 @@
entry: pre_commit_hooks/git-dirty.sh
language: script

- id: reek
name: Find ruby code smells
description: Use reek to find ruby code smells
entry: run-reek
language: ruby
types: ['ruby']

- id: shellcheck
name: Test shell scripts with shellcheck
description: Shell scripts conform to shellcheck
Expand Down
2 changes: 2 additions & 0 deletions .reek
@@ -0,0 +1,2 @@
---
# https://github.com/troessner/reek#configuration-options
37 changes: 37 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,7 @@ Git hooks to integrate with [pre-commit](http://pre-commit.com).
* [`forbid-binary`](#forbid-binary)
* [`git-check`](#git-check)
* [`git-dirty`](#git-dirty)
* [`reek`](#reek)
* [`shellcheck`](#shellcheck)
* [`shfmt`](#shfmt)
- [Contributing](#contributing)
Expand All @@ -31,6 +32,7 @@ Add to `.pre-commit-config.yaml` in your git repo:
- id: forbid-space-in-indent
- id: git-check # Configure in .gitattributes
- id: git-dirty # Configure in .gitignore
- id: reek
- id: shellcheck
- id: shfmt

Expand Down Expand Up @@ -154,6 +156,41 @@ The recommended place to persist the configuration is the `.gitignore` file,
described [**here**](https://git-scm.com/docs/gitignore).


### `reek`

#### What it does

Detect code smells in Ruby code.

#### More info

[Reek](https://github.com/troessner/reek)
is a tool that examines Ruby classes, modules and methods and reports any
[Code Smells](docs/Code-Smells.md) it finds.

For an excellent introduction to
[Code Smells](docs/Code-Smells.md) and Reek check out
[this blog post](https://blog.codeship.com/how-to-find-ruby-code-smells-with-reek/)
or [that one](https://troessner.svbtle.com/the-latest-and-greatest-additions-to-reek).
There is also [this talk](https://www.youtube.com/watch?v=pazYe7WRWRU) from
[RubyConfBY](http://rubyconference.by/)
(there is also a [slide deck](http://talks.chastell.net/rubyconf-by-lt-2016/)
if you prefer that).

**Note:** You should not follow the suggestions blindly.

This hook uses the `identify` library of pre-commit to identify ruby scripts.
If the file is a ruby script, then run reek against the file.

#### Custom configuration (overrides)

The recommended place to persist the configuration is the `.reek` file,
described [**here**](https://github.com/troessner/reek#configuration-options).

You can also create [in-line comments](https://github.com/troessner/reek#source-code-comments)
in the source code for individual overrides.


### `shellcheck`

#### What it does
Expand Down
7 changes: 6 additions & 1 deletion __fake_gem.gemspec
Expand Up @@ -4,7 +4,12 @@ Gem::Specification.new do |s|
s.authors = ['Paul Morgan']
s.summary = 'pre-commit hooks for ruby projects'
s.description = 'pre-commit hooks for ruby projects'
s.add_dependency 'bigdecimal' # needed by reek
s.add_dependency 'fasterer', '0.4.1'
s.add_dependency 'reek', '4.8.1'
s.bindir = 'pre_commit_hooks'
s.executables = ['run-fasterer']
s.executables = [
'run-fasterer',
'run-reek',
]
end
1 change: 1 addition & 0 deletions ci/test
Expand Up @@ -23,6 +23,7 @@ try_precommit() {
info 'Try local hooks that require prereqs'
checks='
fasterer
reek
'
for check in ${checks}; do
run pre-commit try-repo ./ "${check}" --all-files --verbose
Expand Down
10 changes: 10 additions & 0 deletions pre_commit_hooks/run-reek
@@ -0,0 +1,10 @@
require 'English'

# This wrapper is needed because "reek" always prints output,
# but pre-commit looks better if there is no output on success.
output = `reek 2>&1`
status = $CHILD_STATUS.exitstatus
puts output if status != 0
exit status

# vim: ft=ruby

0 comments on commit 7aebd6a

Please sign in to comment.