Skip to content

Commit

Permalink
Fix new rubocopy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Aug 18, 2015
1 parent 7ce7700 commit c9d3583
Show file tree
Hide file tree
Showing 30 changed files with 173 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ AllCops:
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

Style/ExtraSpacing:
AllowForAlignment: true

Style/FileName:
Exclude:
- 'script/deliver-message'
Expand Down
120 changes: 94 additions & 26 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-06-08 15:55:30 +0100 using RuboCop version 0.32.0.
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-08-18 20:27:49 +0100 using RuboCop version 0.33.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: 34
Lint/AmbiguousOperator:
Enabled: false
Exclude:
- 'test/controllers/amf_controller_test.rb'
- 'test/controllers/changeset_controller_test.rb'
- 'test/lib/bounding_box_test.rb'
- 'test/lib/country_test.rb'

# Offense count: 115
Lint/AmbiguousRegexpLiteral:
Enabled: false

# Offense count: 30
# Offense count: 29
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Enabled: false
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/geocoder_controller.rb'
- 'app/controllers/notes_controller.rb'
- 'app/controllers/trace_controller.rb'
- 'app/controllers/user_controller.rb'
- 'app/controllers/user_preference_controller.rb'
- 'app/helpers/application_helper.rb'
- 'app/helpers/browse_helper.rb'
- 'app/models/client_application.rb'
- 'app/models/notifier.rb'
- 'lib/nominatim.rb'
- 'lib/osm.rb'
- 'script/deliver-message'

# Offense count: 3
Lint/FormatParameterMismatch:
Exclude:
- 'app/controllers/swf_controller.rb'

# Offense count: 5
Lint/HandleExceptions:
Enabled: false
Exclude:
- 'app/controllers/amf_controller.rb'
- 'app/controllers/user_controller.rb'
- 'config/initializers/session.rb'

# Offense count: 8
Lint/ParenthesesAsGroupedExpression:
Enabled: false
Exclude:
- 'test/controllers/amf_controller_test.rb'
- 'test/lib/bounding_box_test.rb'
- 'test/models/user_preference_test.rb'

# Offense count: 669
# Offense count: 671
Metrics/AbcSize:
Max: 277

Expand All @@ -43,12 +72,12 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 20

# Offense count: 2537
# Offense count: 2535
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 694

# Offense count: 623
# Offense count: 628
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 179
Expand All @@ -70,34 +99,65 @@ Metrics/PerceivedComplexity:
# Offense count: 2
# Configuration parameters: Include.
Rails/HasAndBelongsToMany:
Enabled: false
Exclude:
- 'app/models/changeset.rb'
- 'app/models/user.rb'

# Offense count: 67
# Offense count: 66
# Configuration parameters: EnforcedStyle, SupportedStyles.
Rails/TimeZone:
Enabled: false

# Offense count: 5
Style/AccessorMethodName:
Enabled: false
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/helpers/title_helper.rb'
- 'app/models/old_way.rb'
- 'lib/osm.rb'
- 'lib/potlatch.rb'

# Offense count: 1
Style/AsciiComments:
Enabled: false
Exclude:
- 'test/models/message_test.rb'

# Offense count: 308
# Offense count: 310
Style/Documentation:
Enabled: false

# Offense count: 38
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/diary_entry_controller.rb'
- 'app/controllers/message_controller.rb'
- 'app/controllers/notes_controller.rb'
- 'app/controllers/site_controller.rb'
- 'app/controllers/user_blocks_controller.rb'
- 'app/controllers/user_controller.rb'
- 'app/controllers/user_roles_controller.rb'
- 'app/helpers/application_helper.rb'
- 'app/models/changeset.rb'
- 'app/models/user.rb'
- 'lib/diff_reader.rb'
- 'lib/object_metadata.rb'

# Offense count: 60
# Cop supports --auto-correct.
Style/LineEndConcatenation:
Enabled: false
Exclude:
- 'db/migrate/008_remove_segments.rb'
- 'db/migrate/020_populate_node_tags_and_remove.rb'
- 'db/migrate/023_add_changesets.rb'
- 'lib/bounding_box.rb'
- 'lib/diff_reader.rb'
- 'lib/osm.rb'
- 'test/controllers/changeset_controller_test.rb'
- 'test/controllers/node_controller_test.rb'
- 'test/controllers/relation_controller_test.rb'
- 'test/controllers/way_controller_test.rb'

# Offense count: 69
# Cop supports --auto-correct.
Expand All @@ -107,12 +167,25 @@ Style/NumericLiterals:
# Offense count: 42
# Cop supports --auto-correct.
Style/PerlBackrefs:
Enabled: false
Exclude:
- 'app/controllers/amf_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/helpers/browse_helper.rb'
- 'config/initializers/paperclip.rb'
- 'lib/id.rb'
- 'lib/potlatch.rb'
- 'test/lib/i18n_test.rb'

# Offense count: 8
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
Style/PredicateName:
Enabled: false
Exclude:
- 'app/models/changeset.rb'
- 'app/models/old_node.rb'
- 'app/models/old_relation.rb'
- 'app/models/old_way.rb'
- 'app/models/user.rb'
- 'lib/classic_pagination/pagination.rb'

# Offense count: 97
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand All @@ -121,16 +194,11 @@ Style/RaiseArgs:

# Offense count: 2
Style/RescueModifier:
Enabled: false
Exclude:
- 'app/helpers/browse_helper.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiteralsInInterpolation:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
Style/TrivialAccessors:
Enabled: false
6 changes: 3 additions & 3 deletions app/controllers/amf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def amf_write
result = startchangeset(*args)
end

err = true if result[0] == -3 # If a conflict is detected, don't execute any more writes
err = true if result[0] == -3 # If a conflict is detected, don't execute any more writes
end

result
Expand Down Expand Up @@ -527,7 +527,7 @@ def findrelations(searchterm)
# 3. version.

def putrelation(renumberednodes, renumberedways, usertoken, changeset_id, version, relid, tags, members, visible) #:doc:
amf_handle_error("'putrelation' #{relid}", "relation", relid) do
amf_handle_error("'putrelation' #{relid}", "relation", relid) do
user = getuser(usertoken)

return -1, "You are not logged in, so the relation could not be saved." unless user
Expand Down Expand Up @@ -645,7 +645,7 @@ def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, po
return -2, "Server error - node with id 0 found in way #{originalway}." if id == 0
return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90

id = renumberednodes[id] if renumberednodes[id]
id = renumberednodes[id] if renumberednodes[id]

node = Node.new
node.changeset_id = changeset_id
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,11 @@ def preferred_editor

# extract authorisation credentials from headers, returns user = nil if none
def get_auth_data
if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
authdata = request.env["X-HTTP_AUTHORIZATION"].to_s.split
elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi
elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi
authdata = request.env["REDIRECT_X_HTTP_AUTHORIZATION"].to_s.split
elsif request.env.key? "HTTP_AUTHORIZATION" # regular location
elsif request.env.key? "HTTP_AUTHORIZATION" # regular location
authdata = request.env["HTTP_AUTHORIZATION"].to_s.split
end
# only basic authentication supported
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/changeset_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def comments_feed
# restrict changesets to those enclosed by a bounding box
# we need to return both the changesets and the bounding box
def conditions_bbox(changesets, bbox)
if bbox
if bbox
bbox.check_boundaries
bbox = bbox.to_scaled
return changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/geocoder_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def search_uk_postcode
unless response.match(/Error/)
dataline = response.split(/\n/)[1]
data = dataline.split(/,/) # easting,northing,postcode,lat,long
postcode = data[2].gsub(/'/, "")
postcode = data[2].delete("'")
zoom = POSTCODE_ZOOM - postcode.count("#")
@results.push(:lat => data[3], :lon => data[4], :zoom => zoom,
:name => postcode)
Expand Down Expand Up @@ -174,7 +174,7 @@ def search_osm_nominatim
if type.empty?
prefix_name = ""
else
prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize
prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.tr("_", " ").capitalize
end
if klass == "boundary" && type == "administrative"
rank = (place.attributes["place_rank"].to_i + 1) / 2
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def search
def mine
if params[:display_name]
if @this_user = User.active.find_by_display_name(params[:display_name])
@title = t "note.mine.title", :user => @this_user.display_name
@heading = t "note.mine.heading", :user => @this_user.display_name
@title = t "note.mine.title", :user => @this_user.display_name
@heading = t "note.mine.heading", :user => @this_user.display_name
@description = t "note.mine.subheading", :user => render_to_string(:partial => "user", :object => @this_user)
@page = (params[:page] || 1).to_i
@page_size = 10
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/swf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def trackpoints
bounds_top = 240 * 20

m = ""
m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
absx = 0
absy = 0
xl = yb = 9999999
Expand All @@ -47,7 +47,7 @@ def trackpoints
user = User.authenticate(:token => params[:token])
sql = "SELECT gps_points.latitude*0.0000001 AS lat,gps_points.longitude*0.0000001 AS lon,gpx_files.id AS fileid," + " EXTRACT(EPOCH FROM gps_points.timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gpx_files,gps_points " + "WHERE gpx_files.id=gpx_id " + " AND gpx_files.user_id=#{user.id} " + " AND " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
else
sql = "SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,gpx_id AS fileid," + " EXTRACT(EPOCH FROM timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gps_points " + "WHERE " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
sql = "SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,gpx_id AS fileid," + " EXTRACT(EPOCH FROM timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gps_points " + "WHERE " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
end
gpslist = ActiveRecord::Base.connection.select_all sql

Expand Down Expand Up @@ -104,11 +104,11 @@ def trackpoints
# Line-drawing

def start_shape
s = 0.chr # No fill styles
s += 2.chr # Two line styles
s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF
s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF
s += 34.chr # 2 fill, 2 line index bits
s = 0.chr # No fill styles
s += 2.chr # Two line styles
s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF
s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF
s += 34.chr # 2 fill, 2 line index bits
s
end

Expand All @@ -117,10 +117,10 @@ def end_shape
end

def start_and_move(x, y, col)
d = "001001" # Line style change, moveTo
d = "001001" # Line style change, moveTo
l = [length_sb(x), length_sb(y)].max
d += format("%05b%0*b%0*b", l, l, x, l, y)
d += col # Select line style
d += col # Select line style
d
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/trace_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def picture
def icon
trace = Trace.find(params[:id])

if trace.visible? && trace.inserted?
if trace.visible? && trace.inserted?
if trace.public? || (@user && @user == trace.user)
expires_in 7.days, :private => !trace.public?, :public => trace.public?
send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => "image/gif", :disposition => "inline")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def successful_login(user)
def failed_login(message)
flash[:error] = message

redirect_to :action => "login", :referer => session[:referer]
redirect_to :action => "login", :referer => session[:referer]

session.delete(:remember_me)
session.delete(:referer)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def wikipedia_link(key, value)
if value =~ /^([a-z-]{2,12}):(.+)$/i
# Value is <lang>:<title> so split it up
# Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315
lang = $1
lang = $1
else
# Value is <title> so default to English Wikipedia
lang = "en"
Expand All @@ -140,7 +140,7 @@ def wikipedia_link(key, value)
# Must break it up to correctly build the url
value = $1
section = "#" + $2
encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).gsub("%", ".")
encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).tr("%", ".")
else
section = ""
encoded_section = ""
Expand Down
2 changes: 1 addition & 1 deletion app/models/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def diary_comment_notification(comment)
:title => "Re: #{comment.diary_entry.title}")

mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
:to => comment.diary_entry.user.email,
:to => comment.diary_entry.user.email,
:subject => I18n.t("notifier.diary_comment_notification.subject", :user => comment.user.display_name)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class User < ActiveRecord::Base
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
has_many :changesets, -> { order(:created_at => :desc) }
has_many :changeset_comments, :foreign_key => :author_id
has_many :changeset_comments, :foreign_key => :author_id
has_and_belongs_to_many :changeset_subscriptions, :class_name => "Changeset", :join_table => "changesets_subscribers", :foreign_key => "subscriber_id"
has_many :note_comments, :foreign_key => :author_id
has_many :notes, :through => :note_comments
Expand Down
Loading

0 comments on commit c9d3583

Please sign in to comment.