Skip to content

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raycarrick-ed committed Jul 29, 2020
1 parent 3914ab5 commit 4d8bd05
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Layout/LineLength:
# default.
Max: 100

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

# Enforce this in the main code but ignore it in specs since the Rspec core methods
# are defined as potentially ambiguous blocks
Lint/AmbiguousBlockAssociation:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/paginable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Paginable

##
# Regex to validate sort_field param is safe
SORT_COLUMN_FORMAT = /[\w\_]+\.[\w\_]/.freeze
SORT_COLUMN_FORMAT = /[\w_]+\.[\w_]/.freeze

PAGINATION_QUERY_PARAMS = %i[page sort_field sort_direction
search controller action].freeze
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/org_admin/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def download_plans

org = current_user.org
file_name = org.name.gsub(/ /, "_")
.gsub(/[\.;,]/, "")
.gsub(/[.;,]/, "")
header_cols = [
_("Project title").to_s,
_("Template").to_s,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/org_admin/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def update_option_ids(attrs_in, opt_map)
# get attached to the new question
def transfer_associations(attrs, question)
if attrs[:annotations_attributes].present?
attrs[:annotations_attributes].keys.each do |key|
attrs[:annotations_attributes].each_key do |key|
old_annotation = question.annotations.select do |a|
a.org_id.to_s == attrs[:annotations_attributes][key][:org_id] &&
a.type.to_s == attrs[:annotations_attributes][key][:type]
Expand Down
2 changes: 1 addition & 1 deletion app/models/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def value_without_scheme_prefix
identifier_scheme.identifier_prefix.present?

base = identifier_scheme.identifier_prefix
value.gsub(base, "").sub(%r{^\/}, "")
value.gsub(base, "").sub(%r{^/}, "")
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Language < ApplicationRecord

ABBREVIATION_MAXIMUM_LENGTH = 5

ABBREVIATION_FORMAT = /\A[a-z]{2}(\-[A-Z]{2})?\Z/.freeze
ABBREVIATION_FORMAT = /\A[a-z]{2}(-[A-Z]{2})?\Z/.freeze

NAME_MAXIMUM_LENGTH = 20

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ def get_preferences(key)
existing = pref.settings[key.to_s].deep_symbolize_keys

# Check for new preferences
defaults.keys.each do |grp|
defaults[grp].keys.each do |pref, _v|
defaults.each_key do |grp|
defaults[grp].each_key do |pref|
# If the group isn't present in the saved values add all of it's preferences
existing[grp] = defaults[grp] if existing[grp].nil?
# If the preference isn't present in the saved values add the default
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/api/v1/pagination_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def initialize(current_url:, per_page:, total_items:, current_page: 1)
def url_without_pagination
return nil unless @url.present? && @url.is_a?(String)

url = @url.gsub(/per_page\=[\d]+/, "")
.gsub(/page\=[\d]+/, "")
url = @url.gsub(/per_page=\d+/, "")
.gsub(/page=\d+/, "")
.gsub(/(&)+$/, "").gsub(/\?$/, "")

(url.include?("?") ? "#{url}&" : "#{url}?")
Expand Down
2 changes: 1 addition & 1 deletion app/validators/url_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class UrlValidator < ActiveModel::EachValidator

def validate_each(record, attribute, value)
reg = %r{https?://[-a-zA-Z0-9@:%_\+.~#?&/=]{2,256}\.[a-z]{2,4}\b(/[-a-zA-Z0-9@:%_\+.~#?&/=]*)?}
reg = %r{https?://[-a-zA-Z0-9@:%_+.~#?&/=]{2,256}\.[a-z]{2,4}\b(/[-a-zA-Z0-9@:%_+.~#?&/=]*)?}
return unless value =~ reg

record.errors[attribute] << (options[:message] || "is not a valid URL")
Expand Down
2 changes: 1 addition & 1 deletion lib/cleanup/deprecators/get_deprecator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GetDeprecator

# Message printed to STDOUT when a deprecated method is called.
def deprecation_warning(deprecated_method, _message, _backtrace = nil)
new_method = deprecated_method.to_s.gsub(/^get\_/, "")
new_method = deprecated_method.to_s.gsub(/^get_/, "")
message = MESSAGE % { deprecated_method: deprecated_method,
new_method: new_method }
Kernel.warn(message)
Expand Down
2 changes: 1 addition & 1 deletion lib/cleanup/deprecators/set_deprecator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SetDeprecator

# Message printed to STDOUT when a deprecated method is called.
def deprecation_warning(deprecated_method, _message, _backtrace = nil)
new_method = deprecated_method.to_s.gsub(/^set\_/, "").gsub(/\Z/, "=")
new_method = deprecated_method.to_s.gsub(/^set_/, "").gsub(/\Z/, "=")
message = MESSAGE % { deprecated_method: deprecated_method,
new_method: new_method }
Kernel.warn(message)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/templates/templates_editings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
click_link template.sections.first.title
within("#edit_question_#{template.question_ids.first}") do
# rubocop:disable Lint/UselessAssignment, Style/PerlBackrefs
textarea_id = page.body.match(/question\_annotations\_attributes\_annotation\_(\d+)\_text/)
textarea_id = page.body.match(/question_annotations_attributes_annotation_(\d+)_text/)
tinymce_fill_in(:"question_annotations_attributes_annotation_#{$1}_text", with: "Foo bar")
# rubocop:enable Lint/UselessAssignment, Style/PerlBackrefs
click_button "Save"
Expand Down
2 changes: 1 addition & 1 deletion spec/mixins/versionable_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

UUID_REGEX ||= /\A[\w\d]{8}(\-[\w\d]{4}){3}-[\w\d]{12}\Z/i.freeze
UUID_REGEX ||= /\A[\w\d]{8}(-[\w\d]{4}){3}-[\w\d]{12}\Z/i.freeze

shared_examples_for "VersionableModel" do

Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers/has_errors_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec::Matchers.define :have_errors do |_expected|

match do
actual.body.match(/Error\:/)
actual.body.match(/Error:/)
end

failure_message do |_actual|
Expand Down

0 comments on commit 4d8bd05

Please sign in to comment.