]> git.openstreetmap.org Git - rails.git/commitdiff
Fix some rubocop warnings
authorTom Hughes <tom@compton.nu>
Thu, 15 Sep 2016 21:41:07 +0000 (22:41 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 15 Sep 2016 21:41:07 +0000 (22:41 +0100)
.rubocop_todo.yml
app/controllers/amf_controller.rb
app/helpers/browse_helper.rb
app/models/node.rb
app/models/way.rb
config/initializers/paperclip.rb
lib/id.rb
lib/migrate.rb
lib/potlatch.rb
test/controllers/changeset_controller_test.rb
test/lib/i18n_test.rb

index 3a3008e9eaefa24f7ee2ccacafde158cddf33bb6..8d81a7c56f99cc52b57159cc272288ac5c2a9fdb 100644 (file)
@@ -164,17 +164,6 @@ Style/LineEndConcatenation:
 Style/NumericLiterals:
   MinDigits: 11
 
-# Offense count: 38
-# Cop supports --auto-correct.
-Style/PerlBackrefs:
-  Exclude:
-    - 'app/controllers/amf_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, NameWhitelist.
 # NamePrefix: is_, has_, have_
@@ -202,15 +191,3 @@ Style/RaiseArgs:
 Style/RescueModifier:
   Exclude:
     - 'app/helpers/browse_helper.rb'
-
-# Offense count: 8
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles.
-# SupportedStyles: single_quotes, double_quotes
-Style/StringLiteralsInInterpolation:
-  Exclude:
-    - 'app/controllers/amf_controller.rb'
-    - 'app/models/node.rb'
-    - 'app/models/way.rb'
-    - 'lib/migrate.rb'
-    - 'test/controllers/changeset_controller_test.rb'
index ac6da0566aab5e88fdcee41f1c58b68370ee7027..632974f4fa28042412b832cf2754d9500982f0d9 100644 (file)
@@ -868,7 +868,7 @@ class AmfController < ApplicationController
 
   def getuser(token) #:doc:
     if token =~ /^(.+)\:(.+)$/
-      User.authenticate(:username => $1, :password => $2)
+      User.authenticate(:username => Regexp.last_match(1), :password => Regexp.last_match(2))
     else
       User.authenticate(:token => token)
     end
@@ -914,7 +914,7 @@ class AmfController < ApplicationController
     INNER JOIN current_ways  ON current_ways.id =current_way_nodes.id
        WHERE current_nodes.visible=TRUE
        AND current_ways.visible=TRUE
-       AND #{OSM.sql_for_area(bbox, "current_nodes.")}
+       AND #{OSM.sql_for_area(bbox, 'current_nodes.')}
     EOF
     ActiveRecord::Base.connection.select_all(sql).collect { |a| [a["wayid"].to_i, a["version"].to_i] }
   end
@@ -927,7 +927,7 @@ class AmfController < ApplicationController
        LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id
        WHERE current_nodes.visible=TRUE
        AND cwn.id IS NULL
-       AND #{OSM.sql_for_area(bbox, "current_nodes.")}
+       AND #{OSM.sql_for_area(bbox, 'current_nodes.')}
     EOF
     ActiveRecord::Base.connection.select_all(sql).each do |row|
       poitags = {}
@@ -947,7 +947,7 @@ class AmfController < ApplicationController
       FROM current_relations cr
       INNER JOIN current_relation_members crm ON crm.id=cr.id
       INNER JOIN current_nodes cn ON crm.member_id=cn.id AND crm.member_type='Node'
-       WHERE #{OSM.sql_for_area(bbox, "cn.")}
+       WHERE #{OSM.sql_for_area(bbox, 'cn.')}
       EOF
     unless way_ids.empty?
       sql += <<-EOF
index 76a6d5eb109d7e1f01accf651703db42bd64fa26..ef7b3f554b8ffbb8dafb4eeb25799c6613a2ced1 100644 (file)
@@ -133,14 +133,14 @@ module BrowseHelper
       lang = 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
-               $1
+               Regexp.last_match(1)
              else
                # Value is <title> so default to English Wikipedia
                "en"
              end
     elsif key =~ /^wikipedia:(\S+)$/
       # Language is in the key, so assume value is the title
-      lang = $1
+      lang = Regexp.last_match(1)
     else
       # Not a wikipedia key!
       return nil
@@ -149,9 +149,9 @@ module BrowseHelper
     if value =~ /^([^#]*)#(.*)/
       # Contains a reference to a section of the wikipedia article
       # Must break it up to correctly build the url
-      value = $1
-      section = "#" + $2
-      encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).tr("%", ".")
+      value = Regexp.last_match(1)
+      section = "#" + Regexp.last_match(2)
+      encoded_section = "#" + URI.encode(Regexp.last_match(2).gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).tr("%", ".")
     else
       section = ""
       encoded_section = ""
index a5becbf4d0b2e4ff260416fe2c6e7092124c68d0..578735688be4253bb90bef0967c9f7244aee5de4 100644 (file)
@@ -120,10 +120,10 @@ class Node < ActiveRecord::Base
       lock!
       check_consistency(self, new_node, user)
       ways = Way.joins(:way_nodes).where(:visible => true, :current_way_nodes => { :node_id => id }).order(:id)
-      raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by ways #{ways.collect(&:id).join(",")}.") unless ways.empty?
+      raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by ways #{ways.collect(&:id).join(',')}.") unless ways.empty?
 
       rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Node", :member_id => id }).order(:id)
-      raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
+      raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by relations #{rels.collect(&:id).join(',')}.") unless rels.empty?
 
       self.changeset_id = new_node.changeset_id
       self.tags = {}
index b31ffc1d16a7b38d4064e811194f05361fb13b96..ecbdd2f9ccd054ab4120fe7f627afb0c93f14e5c 100644 (file)
@@ -222,7 +222,7 @@ class Way < ActiveRecord::Base
       lock!
       check_consistency(self, new_way, user)
       rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Way", :member_id => id }).order(:id)
-      raise OSM::APIPreconditionFailedError.new("Way #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
+      raise OSM::APIPreconditionFailedError.new("Way #{id} is still used by relations #{rels.collect(&:id).join(',')}.") unless rels.empty?
 
       self.changeset_id = new_way.changeset_id
       self.changeset = new_way.changeset
index e27c46ea70a406fd08425cec7be982de97021e88..4db3166ae9a4419003f541bc53772ddc557e9dc6 100644 (file)
@@ -6,7 +6,7 @@ module Paperclip
       url = super(style_name, options)
 
       if url =~ %r{^/assets/(.*)$}
-        asset_path($1)
+        asset_path(Regexp.last_match(1))
       else
         url
       end
index 858bc53c34aa8f7b09a32831c7a7db9e813d1c83..4e6cf3b7c8475e403da4322677f9dbb40c27f189 100644 (file)
--- a/lib/id.rb
+++ b/lib/id.rb
@@ -1,3 +1,3 @@
 module ID
-  LOCALES = Locale.list(Rails.root.join("vendor/assets/iD/iD/locales").entries.map { |p| p.basename.to_s[/(.*).json/] && $1 }.compact)
+  LOCALES = Locale.list(Rails.root.join("vendor/assets/iD/iD/locales").entries.map { |p| p.basename.to_s[/(.*).json/] && Regexp.last_match(1) }.compact)
 end
index 9008b0a9f2ba8f8fdfa9435ef350c390fd141707..21c1b2cf2ab7e8c03f8d2585af3f4ce1432f19e7 100644 (file)
@@ -29,7 +29,7 @@ module ActiveRecord
         end
 
         def alter_primary_key(table_name, new_columns)
-          execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + "_pkey")}"
+          execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
           execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
         end
 
index f7661e39dbf177fe678cf0b56e208a8daeddd9ef..4b56414a4f5f0442c6eba18fe92330a72c22a567 100644 (file)
@@ -182,17 +182,17 @@ module Potlatch
         file.each_line do |line|
           t = line.chomp
           if t =~ %r{(\w+)/(\w+)}
-            presettype = $1
-            presetcategory = $2
+            presettype = Regexp.last_match(1)
+            presetcategory = Regexp.last_match(2)
             presetmenus[presettype].push(presetcategory)
             presetnames[presettype][presetcategory] = ["(no preset)"]
           elsif t =~ /^([\w\s]+):\s?(.+)$/
-            pre = $1
-            kv = $2
+            pre = Regexp.last_match(1)
+            kv = Regexp.last_match(2)
             presetnames[presettype][presetcategory].push(pre)
             presets[pre] = {}
             kv.split(",").each do |a|
-              presets[pre][$1] = $2 if a =~ /^(.+)=(.*)$/
+              presets[pre][Regexp.last_match(1)] = Regexp.last_match(2) if a =~ /^(.+)=(.*)$/
             end
           end
         end
@@ -206,10 +206,10 @@ module Potlatch
         file.each_line do |line|
           next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
 
-          tag = $1
-          colours[tag] = $2.hex if $2 != "-"
-          casing[tag] = $3.hex if $3 != "-"
-          areas[tag] = $4.hex if $4 != "-"
+          tag = Regexp.last_match(1)
+          colours[tag] = Regexp.last_match(2).hex if Regexp.last_match(2) != "-"
+          casing[tag] = Regexp.last_match(3).hex if Regexp.last_match(3) != "-"
+          areas[tag] = Regexp.last_match(4).hex if Regexp.last_match(4) != "-"
         end
       end
 
@@ -221,10 +221,10 @@ module Potlatch
         file.each_line do |line|
           next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
 
-          tag = $1
-          relcolours[tag] = $2.hex if $2 != "-"
-          relalphas[tag] = $3.to_i if $3 != "-"
-          relwidths[tag] = $4.to_i if $4 != "-"
+          tag = Regexp.last_match(1)
+          relcolours[tag] = Regexp.last_match(2).hex if Regexp.last_match(2) != "-"
+          relalphas[tag] = Regexp.last_match(3).to_i if Regexp.last_match(3) != "-"
+          relwidths[tag] = Regexp.last_match(4).to_i if Regexp.last_match(4) != "-"
         end
       end
 
@@ -246,9 +246,9 @@ module Potlatch
         file.each_line do |line|
           next unless line.chomp =~ %r{^([\w:]+)/(\w+)\s+(.+)$}
 
-          tag = $1
-          type = $2
-          values = $3
+          tag = Regexp.last_match(1)
+          type = Regexp.last_match(2)
+          values = Regexp.last_match(3)
           autotags[type][tag] = if values == "-"
                                   []
                                 else
index ecccb1f5f3b1feadbc74e00c055489ccdef32c87..e1960d4e8882492f9c3869bc43ed1549f67e590a 100644 (file)
@@ -675,7 +675,7 @@ EOF
 <osmChange>
  <create>
   <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
-   <tag k='foo' v='#{"x" * 256}'/>
+   <tag k='foo' v='#{'x' * 256}'/>
   </node>
  </create>
 </osmChange>
index 09965e950cb5ba38548012026989d0abef5c6c67..c18c2f3468537ad2d539adb78fe51cb1a05ff5bc 100644 (file)
@@ -15,12 +15,12 @@ class I18nTest < ActiveSupport::TestCase
 
           default_value.each do |_subkey, subvalue|
             subvalue.scan(/%\{(\w+)\}/) do
-              variables.push($1)
+              variables.push(Regexp.last_match(1))
             end
           end
         else
           default_value.scan(/%\{(\w+)\}/) do
-            variables.push($1)
+            variables.push(Regexp.last_match(1))
           end
         end
 
@@ -37,14 +37,14 @@ class I18nTest < ActiveSupport::TestCase
             next if subvalue.nil?
 
             subvalue.scan(/%\{(\w+)\}/) do
-              assert variables.include?($1), "#{key}.#{subkey} uses unknown interpolation variable #{$1}"
+              assert variables.include?(Regexp.last_match(1)), "#{key}.#{subkey} uses unknown interpolation variable #{Regexp.last_match(1)}"
             end
           end
         else
           assert value.is_a?(String), "#{key} is not a string"
 
           value.scan(/%\{(\w+)\}/) do
-            assert variables.include?($1), "#{key} uses unknown interpolation variable #{$1}"
+            assert variables.include?(Regexp.last_match(1)), "#{key} uses unknown interpolation variable #{Regexp.last_match(1)}"
           end
         end
       end