diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..43d23b3 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,3 @@ +inherit_gem: + rubocop-dmp_roadmap: + - config/default.yml diff --git a/Gemfile b/Gemfile index ba35ddb..109bd9c 100644 --- a/Gemfile +++ b/Gemfile @@ -181,15 +181,12 @@ 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" diff --git a/Gemfile.lock b/Gemfile.lock index b8221e9..827f65f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -315,6 +315,13 @@ 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) @@ -428,7 +435,7 @@ responders (~> 2.0) rspec-collection_matchers rspec-rails - rubocop + rubocop-dmp_roadmap rubocop-rspec ruby_dig selenium-webdriver (>= 3.13.1) diff --git a/bin/rubocop_changed b/bin/rubocop_changed new file mode 100755 index 0000000..08c8e49 --- /dev/null +++ b/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