Skip to content

Commit

Permalink
Fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jun 1, 2017
1 parent 95eda2d commit 5b33f3f
Show file tree
Hide file tree
Showing 61 changed files with 548 additions and 542 deletions.
15 changes: 12 additions & 3 deletions .rubocop.yml
Expand Up @@ -24,18 +24,21 @@ AllCops:
Rails:
Enabled: true

Layout/ExtraSpacing:
AllowForAlignment: true

Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

Style/ExtraSpacing:
AllowForAlignment: true

Style/FileName:
Exclude:
- 'script/deliver-message'
- 'script/locale/reload-languages'
- 'script/update-spam-blocks'

Style/FormatStringToken:
EnforcedStyle: template

Style/IfInsideElse:
Enabled: false

Expand All @@ -55,6 +58,12 @@ Style/HashSyntax:
Style/StringLiterals:
EnforcedStyle: double_quotes

Style/SymbolArray:
EnforcedStyle: brackets

Rails/ApplicationRecord:
Enabled: false

Rails/HttpPositionalArguments:
Enabled: false

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Expand Up @@ -410,9 +410,9 @@ def fetch_body

def map_layout
append_content_security_policy_directives(
:connect_src => %w(nominatim.openstreetmap.org overpass-api.de router.project-osrm.org valhalla.mapzen.com),
:script_src => %w(graphhopper.com open.mapquestapi.com),
:img_src => %w(developer.mapquest.com)
:connect_src => %w[nominatim.openstreetmap.org overpass-api.de router.project-osrm.org valhalla.mapzen.com],
:script_src => %w[graphhopper.com open.mapquestapi.com],
:img_src => %w[developer.mapquest.com]
)

if STATUS == :database_offline || STATUS == :api_offline
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/diary_entry_controller.rb
Expand Up @@ -128,7 +128,7 @@ def list
return
end
else
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })

if params[:language]
@title = t "diary_entry.list.in_language_title", :language => Language.find(params[:language]).english_name
Expand Down Expand Up @@ -162,7 +162,7 @@ def rss
return
end
else
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w(active confirmed) })
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })

if params[:language]
@entries = @entries.where(:language_code => params[:language])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/oauth_controller.rb
Expand Up @@ -49,7 +49,7 @@ def oauth1_authorize
else
@token.oob? ? @token.client_application.callback_url : @token.callback_url
end
@redirect_url = URI.parse(callback_url) unless callback_url.blank?
@redirect_url = URI.parse(callback_url) if callback_url.present?

if @redirect_url.to_s.blank?
render :action => "authorize_success"
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/site_controller.rb
Expand Up @@ -69,11 +69,11 @@ def edit
require_user
end

if editor == "potlatch" || editor == "potlatch2"
if %w[potlatch potlatch2].include?(editor)
append_content_security_policy_directives(
:object_src => %w(*),
:plugin_types => %w(application/x-shockwave-flash),
:script_src => %w('unsafe-inline')
:object_src => %w[*],
:plugin_types => %w[application/x-shockwave-flash],
:script_src => %w['unsafe-inline']
)
end

Expand Down Expand Up @@ -120,9 +120,9 @@ def preview

def id
append_content_security_policy_directives(
:connect_src => %w(taginfo.openstreetmap.org *.mapillary.com),
:img_src => %w(*),
:script_src => %w(dev.virtualearth.net)
:connect_src => %w[taginfo.openstreetmap.org *.mapillary.com],
:img_src => %w[*],
:script_src => %w[dev.virtualearth.net]
)

render "id", :layout => false
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/trace_controller.rb
Expand Up @@ -21,7 +21,7 @@ class TraceController < ApplicationController
def list
# from display name, pick up user id if one user's traces only
display_name = params[:display_name]
unless display_name.blank?
if display_name.present?
target_user = User.active.where(:display_name => display_name).first
if target_user.nil?
render_unknown_user display_name
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Expand Up @@ -81,7 +81,7 @@ def save
@user.terms_agreed = Time.now.getutc
@user.terms_seen = true

if @user.auth_uid.nil? || @user.auth_uid.empty?
if @user.auth_uid.blank?
@user.auth_provider = nil
@user.auth_uid = nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/browse_helper.rb
Expand Up @@ -99,7 +99,7 @@ def type_and_paginated_count(type, pages)

private

ICON_TAGS = %w(aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway).freeze
ICON_TAGS = %w[aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway].freeze

def icon_tags(object)
object.tags.find_all { |k, _v| ICON_TAGS.include? k }.sort
Expand Down
4 changes: 1 addition & 3 deletions app/models/client_application.rb
Expand Up @@ -75,9 +75,7 @@ def permissions
# this is the set of permissions that the client can ask for. clients
# have to say up-front what permissions they want and when users sign up they
# can agree or not agree to each of them.
PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary,
:allow_write_api, :allow_read_gpx, :allow_write_gpx,
:allow_write_notes].freeze
PERMISSIONS = [:allow_read_prefs, :allow_write_prefs, :allow_write_diary, :allow_write_api, :allow_read_gpx, :allow_write_gpx, :allow_write_notes].freeze

def generate_keys
self.key = OAuth::Helper.generate_key(40)[0, 40]
Expand Down
2 changes: 1 addition & 1 deletion app/models/diary_entry.rb
Expand Up @@ -3,7 +3,7 @@ class DiaryEntry < ActiveRecord::Base
belongs_to :language, :foreign_key => "language_code"

has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w(active confirmed) }).order(:id) }, :class_name => "DiaryComment"
has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w[active confirmed] }).order(:id) }, :class_name => "DiaryComment"
has_many :subscriptions, :class_name => "DiaryEntrySubscription"
has_many :subscribers, :through => :subscriptions, :source => :user

Expand Down
2 changes: 1 addition & 1 deletion app/models/note.rb
Expand Up @@ -7,7 +7,7 @@ class Note < ActiveRecord::Base
:numericality => { :on => :update, :integer_only => true }
validates :latitude, :longitude, :numericality => { :only_integer => true }
validates :closed_at, :presence => true, :if => proc { :status == "closed" }
validates :status, :inclusion => %w(open closed hidden)
validates :status, :inclusion => %w[open closed hidden]

validate :validate_position

Expand Down
2 changes: 1 addition & 1 deletion app/models/note_comment.rb
Expand Up @@ -7,7 +7,7 @@ class NoteComment < ActiveRecord::Base
validates :note, :presence => true, :associated => true
validates :visible, :inclusion => [true, false]
validates :author, :associated => true
validates :event, :inclusion => %w(opened closed reopened commented hidden)
validates :event, :inclusion => %w[opened closed reopened commented hidden]
validates :body, :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/

# Return the comment text
Expand Down
2 changes: 1 addition & 1 deletion app/models/redaction.rb
Expand Up @@ -15,7 +15,7 @@ class Redaction < ActiveRecord::Base
has_many :old_relations

validates :description, :presence => true
validates :description_format, :inclusion => { :in => %w(text html markdown) }
validates :description_format, :inclusion => { :in => %w[text html markdown] }

# this method overrides the AR default to provide the rich
# text object for the description field.
Expand Down
2 changes: 1 addition & 1 deletion app/models/relation.rb
Expand Up @@ -33,7 +33,7 @@ class Relation < ActiveRecord::Base
scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }

TYPES = %w(node way relation).freeze
TYPES = %w[node way relation].freeze

def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
Expand Down
6 changes: 3 additions & 3 deletions app/models/trace.rb
Expand Up @@ -7,14 +7,14 @@ class Trace < ActiveRecord::Base

scope :visible, -> { where(:visible => true) }
scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
scope :visible_to_all, -> { where(:visibility => %w(public identifiable)) }
scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }

validates :user, :presence => true, :associated => true
validates :name, :presence => true, :length => 1..255
validates :description, :presence => { :on => :create }, :length => 1..255
validates :timestamp, :presence => true
validates :visibility, :inclusion => %w(private public trackable identifiable)
validates :visibility, :inclusion => %w[private public trackable identifiable]

def destroy
super
Expand All @@ -29,7 +29,7 @@ def tagstring

def tagstring=(s)
self.tags = if s.include? ","
s.split(/\s*,\s*/).select { |tag| tag !~ /^\s*$/ }.collect do |tag|
s.split(/\s*,\s*/).reject { |tag| tag =~ /^\s*$/ }.collect do |tag|
tt = Tracetag.new
tt.tag = tag
tt
Expand Down
12 changes: 6 additions & 6 deletions app/models/user.rb
Expand Up @@ -9,7 +9,7 @@ class User < ActiveRecord::Base
has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id
has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
has_many :sent_messages, -> { where(:from_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :class_name => "Message", :foreign_key => :from_user_id
has_many :friends, -> { joins(:befriendee).where(:users => { :status => %w(active confirmed) }) }
has_many :friends, -> { joins(:befriendee).where(:users => { :status => %w[active confirmed] }) }
has_many :friend_users, :through => :friends, :source => :befriendee
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
Expand All @@ -28,16 +28,16 @@ class User < ActiveRecord::Base

has_many :roles, :class_name => "UserRole"

scope :visible, -> { where(:status => %w(pending active confirmed)) }
scope :active, -> { where(:status => %w(active confirmed)) }
scope :visible, -> { where(:status => %w[pending active confirmed]) }
scope :active, -> { where(:status => %w[active confirmed]) }
scope :identifiable, -> { where(:data_public => true) }

has_attached_file :image,
:default_url => "/assets/:class/:attachment/:style.png",
:styles => { :large => "100x100>", :small => "50x50>" }

validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
:exclusion => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
:exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
validates :display_name, :if => proc { |u| u.display_name_changed? },
:uniqueness => { :case_sensitive => false }
validates :display_name, :if => proc { |u| u.display_name_changed? },
Expand Down Expand Up @@ -161,13 +161,13 @@ def is_friends_with?(new_friend)
##
# returns true if a user is visible
def visible?
%w(pending active confirmed).include? status
%w[pending active confirmed].include? status
end

##
# returns true if a user is active
def active?
%w(active confirmed).include? status
%w[active confirmed].include? status
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_role.rb
Expand Up @@ -2,7 +2,7 @@ class UserRole < ActiveRecord::Base
belongs_to :user
belongs_to :granter, :class_name => "User"

ALL_ROLES = %w(administrator moderator).freeze
ALL_ROLES = %w[administrator moderator].freeze

validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id }
end
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -34,7 +34,7 @@ class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true unless STATUS == :database_offline

# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += %W[#{config.root}/lib]

# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
Expand Down
42 changes: 21 additions & 21 deletions config/initializers/assets.rb
Expand Up @@ -11,24 +11,24 @@

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w(index.js browse.js welcome.js fixthemap.js)
Rails.application.config.assets.precompile += %w(user.js login.js diary_entry.js edit/*.js)
Rails.application.config.assets.precompile += %w(screen-ltr.css print-ltr.css)
Rails.application.config.assets.precompile += %w(screen-rtl.css print-rtl.css)
Rails.application.config.assets.precompile += %w(leaflet-all.css leaflet.ie.css)
Rails.application.config.assets.precompile += %w(id.js id.css)
Rails.application.config.assets.precompile += %w(embed.js embed.css)
Rails.application.config.assets.precompile += %w(html5shiv.js)
Rails.application.config.assets.precompile += %w(images/marker-*.png img/*-handle.png)
Rails.application.config.assets.precompile += %w(swfobject.js expressInstall.swf)
Rails.application.config.assets.precompile += %w(potlatch2.swf)
Rails.application.config.assets.precompile += %w(potlatch2/assets.zip)
Rails.application.config.assets.precompile += %w(potlatch2/FontLibrary.swf)
Rails.application.config.assets.precompile += %w(potlatch2/locales/*.swf)
Rails.application.config.assets.precompile += %w(help/introduction.*)
Rails.application.config.assets.precompile += %w(iD/img/*.svg iD/img/*.png iD/img/*.gif)
Rails.application.config.assets.precompile += %w(iD/img/pattern/*.png)
Rails.application.config.assets.precompile += %w(iD/locales/*.json)
Rails.application.config.assets.precompile += %w(iD/traffico/stylesheets/traffico.css)
Rails.application.config.assets.precompile += %w(iD/traffico/fonts/traffico_*)
Rails.application.config.assets.precompile += %w(iD/traffico/string-maps/*.json)
Rails.application.config.assets.precompile += %w[index.js browse.js welcome.js fixthemap.js]
Rails.application.config.assets.precompile += %w[user.js login.js diary_entry.js edit/*.js]
Rails.application.config.assets.precompile += %w[screen-ltr.css print-ltr.css]
Rails.application.config.assets.precompile += %w[screen-rtl.css print-rtl.css]
Rails.application.config.assets.precompile += %w[leaflet-all.css leaflet.ie.css]
Rails.application.config.assets.precompile += %w[id.js id.css]
Rails.application.config.assets.precompile += %w[embed.js embed.css]
Rails.application.config.assets.precompile += %w[html5shiv.js]
Rails.application.config.assets.precompile += %w[images/marker-*.png img/*-handle.png]
Rails.application.config.assets.precompile += %w[swfobject.js expressInstall.swf]
Rails.application.config.assets.precompile += %w[potlatch2.swf]
Rails.application.config.assets.precompile += %w[potlatch2/assets.zip]
Rails.application.config.assets.precompile += %w[potlatch2/FontLibrary.swf]
Rails.application.config.assets.precompile += %w[potlatch2/locales/*.swf]
Rails.application.config.assets.precompile += %w[help/introduction.*]
Rails.application.config.assets.precompile += %w[iD/img/*.svg iD/img/*.png iD/img/*.gif]
Rails.application.config.assets.precompile += %w[iD/img/pattern/*.png]
Rails.application.config.assets.precompile += %w[iD/locales/*.json]
Rails.application.config.assets.precompile += %w[iD/traffico/stylesheets/traffico.css]
Rails.application.config.assets.precompile += %w[iD/traffico/fonts/traffico_*]
Rails.application.config.assets.precompile += %w[iD/traffico/string-maps/*.json]
4 changes: 2 additions & 2 deletions config/initializers/sanitize.rb
@@ -1,5 +1,5 @@
Sanitize::Config::OSM = Sanitize::Config::RELAXED.dup

Sanitize::Config::OSM[:elements] -= %w(div style)
Sanitize::Config::OSM[:elements] -= %w[div style]
Sanitize::Config::OSM[:add_attributes] = { "a" => { "rel" => "nofollow" } }
Sanitize::Config::OSM[:remove_contents] = %w(script style)
Sanitize::Config::OSM[:remove_contents] = %w[script style]
24 changes: 12 additions & 12 deletions config/initializers/secure_headers.rb
@@ -1,17 +1,17 @@
if defined?(CSP_REPORT_URL)
policy = {
:default_src => %w('self'),
:child_src => %w('self'),
:connect_src => %w('self'),
:font_src => %w('none'),
:form_action => %w('self'),
:frame_ancestors => %w('self'),
:img_src => %w('self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr),
:media_src => %w('none'),
:object_src => %w('self'),
:plugin_types => %w('none'),
:script_src => %w('self'),
:style_src => %w('self' 'unsafe-inline'),
:default_src => %w['self'],
:child_src => %w['self'],
:connect_src => %w['self'],
:font_src => %w['none'],
:form_action => %w['self'],
:frame_ancestors => %w['self'],
:img_src => %w['self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr],
:media_src => %w['none'],
:object_src => %w['self'],
:plugin_types => %w['none'],
:script_src => %w['self'],
:style_src => %w['self' 'unsafe-inline'],
:report_uri => [CSP_REPORT_URL]
}

Expand Down

0 comments on commit 5b33f3f

Please sign in to comment.