Skip to content

Commit

Permalink
Fix some rubocop todos
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Aug 2, 2020
1 parent f881a8c commit 2d39722
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Style/Documentation:
Enabled: false

Style/FormatStringToken:
EnforcedStyle: template
Exclude:
- 'config/routes.rb'

Style/IfInsideElse:
Enabled: false
Expand Down
27 changes: 3 additions & 24 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-07-31 18:09:40 UTC using RuboCop version 0.86.0.
# on 2020-08-02 18:37:55 UTC using RuboCop version 0.86.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
Expand All @@ -13,7 +13,7 @@ require:
- rubocop-performance
- rubocop-rails

# Offense count: 565
# Offense count: 568
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down Expand Up @@ -123,14 +123,12 @@ Rails/HasAndBelongsToMany:
- 'app/models/changeset.rb'
- 'app/models/user.rb'

# Offense count: 11
# Offense count: 4
# Configuration parameters: Include.
# Include: app/helpers/**/*.rb
Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/helpers/title_helper.rb'
- 'app/helpers/trace_helper.rb'

# Offense count: 5
# Configuration parameters: Include.
Expand Down Expand Up @@ -163,25 +161,6 @@ Rails/OutputSafety:
Rails/TimeZone:
Enabled: false

# Offense count: 1
# Configuration parameters: AllowedChars.
Style/AsciiComments:
Exclude:
- 'test/models/message_test.rb'

# Offense count: 32
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
Exclude:
- 'app/models/concerns/geo_record.rb'
- 'app/views/api/map/_bounds.xml.builder'
- 'lib/bounding_box.rb'
- 'test/controllers/api/map_controller_test.rb'
- 'test/controllers/api/relations_controller_test.rb'
- 'test/controllers/api/ways_controller_test.rb'
- 'test/lib/bounding_box_test.rb'

# Offense count: 572
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class ApplicationController < ActionController::Base
around_action :better_errors_allow_inline, :if => proc { Rails.env.development? }

attr_accessor :current_user
attr_accessor :oauth_token

helper_method :current_user
helper_method :oauth_token
helper_method :preferred_langauges

private
Expand Down Expand Up @@ -58,7 +60,7 @@ def require_user
end

def require_oauth
@oauth = current_user.access_token(Settings.oauth_key) if current_user && Settings.key?(:oauth_key)
@oauth_token = current_user.access_token(Settings.oauth_key) if current_user && Settings.key?(:oauth_key)
end

##
Expand Down
10 changes: 5 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def application_data

data[:location] = session[:location] if session[:location]

if @oauth
data[:token] = @oauth.token
data[:token_secret] = @oauth.secret
data[:consumer_key] = @oauth.client_application.key
data[:consumer_secret] = @oauth.client_application.secret
if oauth_token
data[:token] = oauth_token.token
data[:token_secret] = oauth_token.secret
data[:consumer_key] = oauth_token.client_application.key
data[:consumer_secret] = oauth_token.client_application.secret
end

data
Expand Down
6 changes: 1 addition & 5 deletions app/helpers/trace_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module TraceHelper
def link_to_tag(tag)
if @action == "mine"
link_to(tag, :tag => tag, :page => nil)
else
link_to(tag, :tag => tag, :display_name => @display_name, :page => nil)
end
link_to(tag, :tag => tag, :page => nil)
end
end
4 changes: 2 additions & 2 deletions app/models/concerns/geo_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def initialize(obj)
end

def to_s
format("%.7f", self)
format("%<coord>.7f", :coord => self)
end

def as_json(_)
format("%.7f", self).to_f
format("%<coord>.7f", :coord => self).to_f
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/views/api/map/_bounds.xml.builder
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
attrs = {
"minlat" => format("%.7f", bounds.min_lat),
"minlon" => format("%.7f", bounds.min_lon),
"maxlat" => format("%.7f", bounds.max_lat),
"maxlon" => format("%.7f", bounds.max_lon)
"minlat" => format("%<lat>.7f", :lat => bounds.min_lat),
"minlon" => format("%<lon>.7f", :lon => bounds.min_lon),
"maxlat" => format("%<lat>.7f", :lat => bounds.max_lat),
"maxlon" => format("%<lon>.7f", :lon => bounds.max_lon)
}

xml.bounds(attrs)
8 changes: 4 additions & 4 deletions lib/bounding_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def slippy_height(zoom)
# there are two forms used for bounds with and without an underscore,
# cater for both forms eg minlon and min_lon
def add_bounds_to(hash, underscore = "")
hash["min#{underscore}lat"] = format("%.7f", min_lat)
hash["min#{underscore}lon"] = format("%.7f", min_lon)
hash["max#{underscore}lat"] = format("%.7f", max_lat)
hash["max#{underscore}lon"] = format("%.7f", max_lon)
hash["min#{underscore}lat"] = format("%<lat>.7f", :lat => min_lat)
hash["min#{underscore}lon"] = format("%<lon>.7f", :lon => min_lon)
hash["max#{underscore}lat"] = format("%<lat>.7f", :lat => max_lat)
hash["max#{underscore}lon"] = format("%<lon>.7f", :lon => max_lon)
hash
end

Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api/map_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def test_map
end
assert_response :success, "Expected scucess with the map call"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{format('%.7f', minlon)}'][minlat='#{format('%.7f', minlat)}'][maxlon='#{format('%.7f', maxlon)}'][maxlat='#{format('%.7f', maxlat)}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{format('%.7f', node.lat)}'][lon='#{format('%.7f', node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
assert_select "bounds[minlon='#{format('%<lon>.7f', :lon => minlon)}'][minlat='#{format('%<lat>.7f', :lat => minlat)}'][maxlon='#{format('%<lon>.7f', :lon => maxlon)}'][maxlat='#{format('%<lat>.7f', :lat => maxlat)}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{format('%<lat>.7f', :lat => node.lat)}'][lon='#{format('%<lon>.7f', :lon => node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_map_inclusive
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{format('%.7f', node.lat)}'][lon='#{format('%.7f', node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
assert_select "node[id='#{node.id}'][lat='#{format('%<lat>.7f', :lat => node.lat)}'][lon='#{format('%<lon>.7f', :lon => node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/api/relations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,10 @@ def check_changeset_modify(bbox)
assert_response :success, "can't re-read changeset for modify test"
assert_select "osm>changeset", 1, "Changeset element doesn't exist in #{@response.body}"
assert_select "osm>changeset[id='#{changeset_id}']", 1, "Changeset id=#{changeset_id} doesn't exist in #{@response.body}"
assert_select "osm>changeset[min_lon='#{format('%.7f', bbox.min_lon)}']", 1, "Changeset min_lon wrong in #{@response.body}"
assert_select "osm>changeset[min_lat='#{format('%.7f', bbox.min_lat)}']", 1, "Changeset min_lat wrong in #{@response.body}"
assert_select "osm>changeset[max_lon='#{format('%.7f', bbox.max_lon)}']", 1, "Changeset max_lon wrong in #{@response.body}"
assert_select "osm>changeset[max_lat='#{format('%.7f', bbox.max_lat)}']", 1, "Changeset max_lat wrong in #{@response.body}"
assert_select "osm>changeset[min_lon='#{format('%<lon>.7f', :lon => bbox.min_lon)}']", 1, "Changeset min_lon wrong in #{@response.body}"
assert_select "osm>changeset[min_lat='#{format('%<lat>.7f', :lat => bbox.min_lat)}']", 1, "Changeset min_lat wrong in #{@response.body}"
assert_select "osm>changeset[max_lon='#{format('%<lon>.7f', :lon => bbox.max_lon)}']", 1, "Changeset max_lon wrong in #{@response.body}"
assert_select "osm>changeset[max_lat='#{format('%<lat>.7f', :lat => bbox.max_lat)}']", 1, "Changeset max_lat wrong in #{@response.body}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/ways_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_full
# reference and as the node element.
way.nodes.each do |n|
assert_select "osm way nd[ref='#{n.id}']", 1
assert_select "osm node[id='#{n.id}'][version='1'][lat='#{format('%.7f', n.lat)}'][lon='#{format('%.7f', n.lon)}']", 1
assert_select "osm node[id='#{n.id}'][version='1'][lat='#{format('%<lat>.7f', :lat => n.lat)}'][lon='#{format('%<lon>.7f', :lon => n.lon)}']", 1
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/integration/compressed_requests_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_no_compression
post "/api/0.6/changeset/#{changeset.id}/upload",
:params => diff,
:headers => {
"HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_CONTENT_TYPE" => "application/xml"
}
assert_response :success,
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_gzip_compression
post "/api/0.6/changeset/#{changeset.id}/upload",
:params => gzip_content(diff),
:headers => {
"HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_CONTENT_ENCODING" => "gzip",
"HTTP_CONTENT_TYPE" => "application/xml"
}
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_deflate_compression
post "/api/0.6/changeset/#{changeset.id}/upload",
:params => deflate_content(diff),
:headers => {
"HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_CONTENT_ENCODING" => "deflate",
"HTTP_CONTENT_TYPE" => "application/xml"
}
Expand All @@ -158,7 +158,7 @@ def test_invalid_compression
post "/api/0.6/changeset/#{changeset.id}/upload",
:params => "",
:headers => {
"HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user.display_name}:test")),
"HTTP_CONTENT_ENCODING" => "unknown",
"HTTP_CONTENT_TYPE" => "application/xml"
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/user_blocks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class UserBlocksTest < ActionDispatch::IntegrationTest
def auth_header(user, pass)
{ "HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
{ "HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user}:#{pass}")) }
end

def test_api_blocked
Expand Down
2 changes: 1 addition & 1 deletion test/integration/user_terms_seen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ def test_terms_cant_be_circumvented
private

def auth_header(user, pass)
{ "HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
{ "HTTP_AUTHORIZATION" => format("Basic %<auth>s", :auth => Base64.encode64("#{user}:#{pass}")) }
end
end
16 changes: 8 additions & 8 deletions test/lib/bounding_box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,19 @@ def test_slippy_height
def test_add_bounds_to_no_underscore
bounds = @bbox_from_string.add_bounds_to({})
assert_equal 4, bounds.size
assert_equal format("%.7f", @min_lon), bounds["minlon"]
assert_equal format("%.7f", @min_lat), bounds["minlat"]
assert_equal format("%.7f", @max_lon), bounds["maxlon"]
assert_equal format("%.7f", @max_lat), bounds["maxlat"]
assert_equal format("%<lon>.7f", :lon => @min_lon), bounds["minlon"]
assert_equal format("%<lat>.7f", :lat => @min_lat), bounds["minlat"]
assert_equal format("%<lon>.7f", :lon => @max_lon), bounds["maxlon"]
assert_equal format("%<lat>.7f", :lat => @max_lat), bounds["maxlat"]
end

def test_add_bounds_to_with_underscore
bounds = @bbox_from_string.add_bounds_to({}, "_")
assert_equal 4, bounds.size
assert_equal format("%.7f", @min_lon), bounds["min_lon"]
assert_equal format("%.7f", @min_lat), bounds["min_lat"]
assert_equal format("%.7f", @max_lon), bounds["max_lon"]
assert_equal format("%.7f", @max_lat), bounds["max_lat"]
assert_equal format("%<lon>.7f", :lon => @min_lon), bounds["min_lon"]
assert_equal format("%<lat>.7f", :lat => @min_lat), bounds["min_lat"]
assert_equal format("%<lon>.7f", :lon => @max_lon), bounds["max_lon"]
assert_equal format("%<lat>.7f", :lat => @max_lat), bounds["max_lat"]
end

def test_to_scaled
Expand Down
2 changes: 1 addition & 1 deletion test/models/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def make_message(char, count)
def assert_message_ok(char, count)
message = make_message(char, count)
assert message.save!
response = message.class.find(message.id) # stand by for some über-generalisation...
response = message.class.find(message.id) # stand by for some uber-generalisation...
assert_equal char * count, response.title, "message with #{count} #{char} chars (i.e. #{char.length * count} bytes) fails"
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def assert_nodes_are_equal(a, b)
##
# return request header for HTTP Basic Authorization
def basic_authorization_header(user, pass)
{ "Authorization" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
{ "Authorization" => format("Basic %<auth>s", :auth => Base64.encode64("#{user}:#{pass}")) }
end

##
Expand Down

0 comments on commit 2d39722

Please sign in to comment.