Skip to content

Commit

Permalink
Add DMPRoadmap Rubocop style guide gem (#1797)
Browse files Browse the repository at this point in the history
* Add DMPRoadmap Rubocop style guide gem

* Add bin exe for Rubocop check on changed files
  • Loading branch information
Bodacious committed Aug 13, 2018
1 parent e98abf2 commit b9abee9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,3 @@
inherit_gem:
rubocop-dmp_roadmap:
- config/default.yml
7 changes: 2 additions & 5 deletions Gemfile
Expand Up @@ -181,15 +181,12 @@ group :test do
gem 'chromedriver-helper', ">= 1.2.0"
end

group :ci do
group :ci, :development do
# Security vulnerability scanner for Ruby on Rails. (http://brakemanscanner.org)
gem "brakeman"

# Automatic Ruby code style checking tool. (https://github.com/rubocop-hq/rubocop)
gem "rubocop"

# Code style checking for RSpec files (https://github.com/rubocop-hq/rubocop-rspec)
gem "rubocop-rspec"
gem "rubocop-dmp_roadmap"

# Helper gem to require bundler-audit (http://github.com/stewartmckee/bundle-audit)
gem "bundle-audit"
Expand Down
9 changes: 8 additions & 1 deletion Gemfile.lock
Expand Up @@ -315,6 +315,13 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-dmp_roadmap (1.0.0)
rubocop (>= 0.58.2)
rubocop-rails_config (>= 0.2.2)
rubocop-rspec (>= 1.27.0)
rubocop-rails_config (0.2.2)
railties (>= 3.0)
rubocop (~> 0.56)
rubocop-rspec (1.27.0)
rubocop (>= 0.56.0)
ruby-progressbar (1.9.0)
Expand Down Expand Up @@ -428,7 +435,7 @@ DEPENDENCIES
responders (~> 2.0)
rspec-collection_matchers
rspec-rails
rubocop
rubocop-dmp_roadmap
rubocop-rspec
ruby_dig
selenium-webdriver (>= 3.13.1)
Expand Down
43 changes: 43 additions & 0 deletions bin/rubocop_changed
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Which branch should we compare HEAD with for changed files? (defaults: 'development')
BRANCH='development'
DIRS='app lib'

while getopts 'b:d:' optname
do
case "$optname" in
"b")
BRANCH=$OPTARG
;;
"d")
DIRS=$OPTARG
;;
esac
done

# Get a list of all files that have changed on this branch in app and lib directories.
CHANGED_FILES=$(git diff --name-only $BRANCH -- $DIRS)

# A string with the name of each changed file
EXISTING_FILES=""

# Iterate over each changed file
for FILEPATH in $CHANGED_FILES
do
# Append this filename if the file still exists (in case the file has been deleted)
if [ -f $FILEPATH ]; then
EXISTING_FILES+=" $FILEPATH"
fi
done

# If there are no files that have been changed...
if [ -z "$EXISTING_FILES" ]
then
# Print a message and exit
echo "Rubocop changed: No matching files have changed."
exit 0
else
# Run Rubocop against the files that have chagned
rubocop -p $EXISTING_FILES
fi

0 comments on commit b9abee9

Please sign in to comment.