Skip to content

Commit

Permalink
Rubocop (#939)
Browse files Browse the repository at this point in the history
* Add rubocop to travis.

* Lots of auto-corrects.

* Rubocop is clean.
  • Loading branch information
mccalluc authored and afred committed Apr 15, 2016
1 parent 7d099e4 commit b1c0abc
Show file tree
Hide file tree
Showing 68 changed files with 554 additions and 580 deletions.
46 changes: 0 additions & 46 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1 @@
inherit_from: .rubocop_todo.yml

# TODO: What's a better idiom?
Style/MultilineBlockChain:
Enabled: false

# Nice, but a bit esoteric:
Style/SymbolProc:
Enabled: false
Style/WordArray:
MinSize: 6

# %r is more unusual than a backslash, at least for me.
Style/RegexpLiteral:
AllowInnerSlashes: true

Style/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space

Metrics/ParameterLists:
Max: 4

# I like to distinguish code blocks which are commented out from real comments
Style/CommentIndentation:
Enabled: false

# Message Often supplied in exception constructor, so I don't think an additional message is essential.
Style/RaiseArgs:
Enabled: false

AllCops:
Exclude:
- 'bin/**'
- 'db/schema.rb'

## TODO ##

Metrics/AbcSize:
Max: 80
Metrics/MethodLength:
Max: 97
Style/ClassVars:
Enabled: false
Style/Documentation:
Enabled: false
Metrics/LineLength:
Max: 180
113 changes: 71 additions & 42 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,106 +1,135 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-08-17 12:58:08 -0400 using RuboCop version 0.33.0.
# on 2016-04-14 16:25:22 -0400 using RuboCop version 0.39.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Offense count: 1
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'bin/spring'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
# SupportedStyles: keyword, variable, start_of_line
Lint/EndAlignment:
Enabled: false

# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Lint/Eval:
Exclude:
- 'app/controllers/api_controller.rb'

# Offense count: 2
Lint/HandleExceptions:
Exclude:
- 'bin/rails'
- 'bin/rake'

# Offense count: 7
Lint/IneffectiveAccessModifier:
Exclude:
- 'app/models/featured.rb'
- 'scripts/lib/cleaner.rb'

# Offense count: 2
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'config/environment.rb'

# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'config/environment.rb'

# Offense count: 2
# Offense count: 27
Metrics/AbcSize:
Max: 111

# Offense count: 3
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 153
Max: 152

# Offense count: 12
Metrics/CyclomaticComplexity:
Max: 24

# Offense count: 3
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 297
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 220
Max: 225

# Offense count: 1
# Offense count: 32
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 127
Max: 131

# Offense count: 10
Metrics/PerceivedComplexity:
Max: 20

# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/AndOr:
Exclude:
- 'config/environment.rb'

# Offense count: 1
Style/AsciiComments:
Exclude:
- 'spec/lib/markdown_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters:
Enabled: false

# Offense count: 2
# Offense count: 4
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'config/environment.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: Keywords.
Style/CommentAnnotation:
Exclude:
- 'app/models/ability.rb'
# Offense count: 55
Style/Documentation:
Enabled: false

# Offense count: 30
# Offense count: 28
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Exclude:
- 'scripts/download_clean_ingest.rb'
- 'scripts/lib/downloader.rb'
- 'scripts/lib/pb_core_ingester.rb'

# Offense count: 5
Style/MultilineTernaryOperator:
# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'app/controllers/advanced_controller.rb'
- 'spec/support/remote_ip_monkey_patch.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/Not:
# Offense count: 3
Style/MultilineBlockChain:
Exclude:
- 'config/environment.rb'
- 'app/models/exhibit.rb'
- 'app/models/vocab_map.rb'

# Offense count: 2
Style/RescueModifier:
# Offense count: 12
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Enabled: false

# Offense count: 20
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'app/models/exhibit.rb'
- 'spec/models/exhibit_spec.rb'
- 'app/models/featured.rb'
- 'config/routes.rb'
- 'lib/html_scrubber.rb'
- 'scripts/lib/downloader.rb'
- 'spec/features/override_spec.rb'
- 'spec/models/pb_core_spec.rb'
- 'spec/scripts/download_clean_ingest_spec.rb'
- 'spec/scripts/downloader_spec.rb'
- 'spec/support/link_checker.rb'
- 'spec/support/validation_helper.rb'
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ sudo: false
cache: bundler
script:
- bundle exec rails server &
- bundle exec rake ci
- bundle exec rake ci
- bundle exec rubocop -D
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ gem 'rspec', :group => :test
gem 'rspec-rails', :group => :test
gem 'capybara', :group => :test

gem 'rubocop', :group => :development
gem 'pry', :group => :development
gem 'pry-nav', :group => :development

Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
ast (2.2.0)
autoprefixer-rails (5.1.7.1)
execjs
json
Expand Down Expand Up @@ -134,10 +135,13 @@ GEM
mini_portile (~> 0.6.0)
openseadragon (0.2.0)
rails (> 3.2.0)
parser (2.3.0.7)
ast (~> 2.2)
passenger (5.0.6)
rack
rake (>= 0.8.1)
polyglot (0.3.5)
powerpack (0.1.1)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand All @@ -162,6 +166,7 @@ GEM
activesupport (= 4.1.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
Expand Down Expand Up @@ -190,6 +195,13 @@ GEM
rspec-mocks (~> 3.2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
rubocop (0.39.0)
parser (>= 2.3.0.7, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
sass (3.2.19)
sass-rails (4.0.5)
Expand Down Expand Up @@ -242,6 +254,7 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicode-display_width (1.0.3)
wordpress-client (0.2.4)
faraday (>= 0.8)
logger (>= 1.2)
Expand Down Expand Up @@ -278,6 +291,7 @@ DEPENDENCIES
rsolr
rspec
rspec-rails
rubocop
rubyzip
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks

ZIP_URL = 'https://github.com/projectblacklight/blacklight-jetty/archive/v4.9.0.zip'
require 'jettywrapper'
ZIP_URL = 'https://github.com/projectblacklight/blacklight-jetty/archive/v4.9.0.zip'.freeze
require 'jettywrapper'
14 changes: 8 additions & 6 deletions app/controllers/advanced_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ class AdvancedController < ApplicationController
def create
redirect_to "/catalog?q=#{CGI.escape(query)}"
end

def query
[
!params[:all].empty? &&
self.class.prefix(params[:all], '+'),

!params[:title].empty? &&
"+titles:\"#{params[:title]}\"",

!params[:exact].empty? &&
"+\"#{params[:exact]}\"",

!params[:any].empty? &&
self.class.prefix(params[:any], '', ' OR '),

!params[:none].empty? &&
self.class.prefix(params[:none], '-')

].select { |clause| clause }.join(' ')
end
def self.prefix(terms, prefix, joint=' ')

def self.prefix(terms, prefix, joint = ' ')
terms.split(/\s+/).map { |term| "#{prefix}#{term}" }.join(joint)
end
end
8 changes: 4 additions & 4 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
# TODO: There is nothing we have that is worth a CSRF, but CORS is a better way to do this.

def index
@solr = Solr.instance.connect
callback = params.delete('callback') || 'callback'
rows = [params.delete('rows').to_i, 100].min
data = begin
@solr.get('select', params: params.except(:action, :format, :controller).merge({rows: rows}))
@solr.get('select', params: params.except(:action, :format, :controller).merge(rows: rows))
rescue => e
# RSolr dictates that responses be ruby data structures,
# but the eval still scares me.
Expand All @@ -18,11 +18,11 @@ def index
json = JSON.pretty_generate(data)
respond_to do |format|
format.js do
render text: "#{callback}(#{json});",
render text: "#{callback}(#{json});",
status: data['error'] ? 500 : 200
end
format.json do
render text: json,
render text: json,
status: data['error'] ? 500 : 200
end
format.xml do
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/captions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class CaptionsController < ApplicationController
include Blacklight::Catalog

def show
# For debugging:
# render text: <<END
# 1
# 00:00:01,000 --> 00:00:03,000
# CAPTIONS CONTROLLER!!!
# For debugging:
# render text: <<END
# 1
# 00:00:01,000 --> 00:00:03,000
# CAPTIONS CONTROLLER!!!

_response, document = fetch(params['id'])
captions = document['captions']
Expand Down
Loading

0 comments on commit b1c0abc

Please sign in to comment.