Fix Style/NumericPredicate rubocop warnings
This commit is contained in:
parent
64146b4f36
commit
de29e9b3f5
14 changed files with 21 additions and 42 deletions
|
@ -185,27 +185,6 @@ Style/IfUnlessModifier:
|
||||||
Style/NumericLiterals:
|
Style/NumericLiterals:
|
||||||
MinDigits: 11
|
MinDigits: 11
|
||||||
|
|
||||||
# Offense count: 21
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
|
||||||
# SupportedStyles: predicate, comparison
|
|
||||||
Style/NumericPredicate:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/**/*'
|
|
||||||
- 'app/controllers/amf_controller.rb'
|
|
||||||
- 'app/controllers/changeset_controller.rb'
|
|
||||||
- 'app/controllers/notes_controller.rb'
|
|
||||||
- 'app/helpers/banner_helper.rb'
|
|
||||||
- 'app/helpers/issues_helper.rb'
|
|
||||||
- 'app/models/relation.rb'
|
|
||||||
- 'app/models/trace.rb'
|
|
||||||
- 'app/models/way.rb'
|
|
||||||
- 'db/migrate/021_move_to_innodb.rb'
|
|
||||||
- 'lib/classic_pagination/pagination.rb'
|
|
||||||
- 'lib/daemons/gpx_import.rb'
|
|
||||||
- 'lib/gpx.rb'
|
|
||||||
- 'test/controllers/amf_controller_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 3080
|
# Offense count: 3080
|
||||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||||
# URISchemes: http, https
|
# URISchemes: http, https
|
||||||
|
|
|
@ -472,7 +472,7 @@ class AmfController < ApplicationController
|
||||||
return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
|
return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
|
||||||
|
|
||||||
query = Trace.visible_to(user)
|
query = Trace.visible_to(user)
|
||||||
query = if searchterm.to_i > 0
|
query = if searchterm.to_i.positive?
|
||||||
query.where(:id => searchterm.to_i)
|
query.where(:id => searchterm.to_i)
|
||||||
else
|
else
|
||||||
query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
|
query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
|
||||||
|
@ -508,7 +508,7 @@ class AmfController < ApplicationController
|
||||||
|
|
||||||
def findrelations(searchterm)
|
def findrelations(searchterm)
|
||||||
rels = []
|
rels = []
|
||||||
if searchterm.to_i > 0
|
if searchterm.to_i.positive?
|
||||||
rel = Relation.where(:id => searchterm.to_i).first
|
rel = Relation.where(:id => searchterm.to_i).first
|
||||||
rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel&.visible
|
rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel&.visible
|
||||||
else
|
else
|
||||||
|
@ -545,7 +545,7 @@ class AmfController < ApplicationController
|
||||||
relation = nil
|
relation = nil
|
||||||
Relation.transaction do
|
Relation.transaction do
|
||||||
# create a new relation, or find the existing one
|
# create a new relation, or find the existing one
|
||||||
relation = Relation.find(relid) if relid > 0
|
relation = Relation.find(relid) if relid.positive?
|
||||||
# We always need a new node, based on the data that has been sent to us
|
# We always need a new node, based on the data that has been sent to us
|
||||||
new_relation = Relation.new
|
new_relation = Relation.new
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ class AmfController < ApplicationController
|
||||||
typedmembers = []
|
typedmembers = []
|
||||||
members.each do |m|
|
members.each do |m|
|
||||||
mid = m[1].to_i
|
mid = m[1].to_i
|
||||||
if mid < 0
|
if mid.negative?
|
||||||
mid = renumberednodes[mid] if m[0] == "Node"
|
mid = renumberednodes[mid] if m[0] == "Node"
|
||||||
mid = renumberedways[mid] if m[0] == "Way"
|
mid = renumberedways[mid] if m[0] == "Way"
|
||||||
end
|
end
|
||||||
|
@ -741,7 +741,7 @@ class AmfController < ApplicationController
|
||||||
node = nil
|
node = nil
|
||||||
new_node = nil
|
new_node = nil
|
||||||
Node.transaction do
|
Node.transaction do
|
||||||
if id > 0
|
if id.positive?
|
||||||
begin
|
begin
|
||||||
node = Node.find(id)
|
node = Node.find(id)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -582,7 +582,7 @@ class ChangesetController < ApplicationController
|
||||||
# Get the maximum number of comments to return
|
# Get the maximum number of comments to return
|
||||||
def comments_limit
|
def comments_limit
|
||||||
if params[:limit]
|
if params[:limit]
|
||||||
if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
|
if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
|
||||||
params[:limit].to_i
|
params[:limit].to_i
|
||||||
else
|
else
|
||||||
raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"
|
raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"
|
||||||
|
|
|
@ -307,7 +307,7 @@ class NotesController < ApplicationController
|
||||||
# Get the maximum number of results to return
|
# Get the maximum number of results to return
|
||||||
def result_limit
|
def result_limit
|
||||||
if params[:limit]
|
if params[:limit]
|
||||||
if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
|
if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
|
||||||
params[:limit].to_i
|
params[:limit].to_i
|
||||||
else
|
else
|
||||||
raise OSM::APIBadUserInput, "Note limit must be between 1 and 10000"
|
raise OSM::APIBadUserInput, "Note limit must be between 1 and 10000"
|
||||||
|
@ -327,9 +327,9 @@ class NotesController < ApplicationController
|
||||||
7
|
7
|
||||||
end
|
end
|
||||||
|
|
||||||
if closed_since < 0
|
if closed_since.negative?
|
||||||
notes.where.not(:status => "hidden")
|
notes.where.not(:status => "hidden")
|
||||||
elsif closed_since > 0
|
elsif closed_since.positive?
|
||||||
notes.where(:status => "open")
|
notes.where(:status => "open")
|
||||||
.or(notes.where(:status => "closed")
|
.or(notes.where(:status => "closed")
|
||||||
.where(notes.arel_table[:closed_at].gt(Time.now - closed_since.days)))
|
.where(notes.arel_table[:closed_at].gt(Time.now - closed_since.days)))
|
||||||
|
|
|
@ -26,7 +26,7 @@ module BannerHelper
|
||||||
|
|
||||||
# rotate all banner queue positions
|
# rotate all banner queue positions
|
||||||
index = cval.to_i
|
index = cval.to_i
|
||||||
cookies[ckey] = index - 1 if index > 0
|
cookies[ckey] = index - 1 if index.positive?
|
||||||
|
|
||||||
# pick banner with mininum queue position
|
# pick banner with mininum queue position
|
||||||
next if index > min_index
|
next if index > min_index
|
||||||
|
|
|
@ -29,7 +29,7 @@ module IssuesHelper
|
||||||
count = Issue.visible_to(current_user).open.limit(100).size
|
count = Issue.visible_to(current_user).open.limit(100).size
|
||||||
if count > 99
|
if count > 99
|
||||||
content_tag(:span, "99+", :class => "count-number")
|
content_tag(:span, "99+", :class => "count-number")
|
||||||
elsif count > 0
|
elsif count.positive?
|
||||||
content_tag(:span, count, :class => "count-number")
|
content_tag(:span, count, :class => "count-number")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -275,7 +275,7 @@ class Relation < ActiveRecord::Base
|
||||||
def fix_placeholders!(id_map, placeholder_id = nil)
|
def fix_placeholders!(id_map, placeholder_id = nil)
|
||||||
members.map! do |type, id, role|
|
members.map! do |type, id, role|
|
||||||
old_id = id.to_i
|
old_id = id.to_i
|
||||||
if old_id < 0
|
if old_id.negative?
|
||||||
new_id = id_map[type.downcase.to_sym][old_id]
|
new_id = id_map[type.downcase.to_sym][old_id]
|
||||||
raise OSM::APIBadUserInput, "Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}." if new_id.nil?
|
raise OSM::APIBadUserInput, "Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}." if new_id.nil?
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ class Trace < ActiveRecord::Base
|
||||||
tp.save!
|
tp.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
if gpx.actual_points > 0
|
if gpx.actual_points.positive?
|
||||||
max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
|
max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
|
||||||
min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
|
min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
|
||||||
max_lon = Tracepoint.where(:gpx_id => id).maximum(:longitude)
|
max_lon = Tracepoint.where(:gpx_id => id).maximum(:longitude)
|
||||||
|
|
|
@ -254,7 +254,7 @@ class Way < ActiveRecord::Base
|
||||||
# to IDs +id_map+.
|
# to IDs +id_map+.
|
||||||
def fix_placeholders!(id_map, placeholder_id = nil)
|
def fix_placeholders!(id_map, placeholder_id = nil)
|
||||||
nds.map! do |node_id|
|
nds.map! do |node_id|
|
||||||
if node_id < 0
|
if node_id.negative?
|
||||||
new_id = id_map[:node][node_id]
|
new_id = id_map[:node][node_id]
|
||||||
raise OSM::APIBadUserInput, "Placeholder node not found for reference #{node_id} in way #{id.nil? ? placeholder_id : id}" if new_id.nil?
|
raise OSM::APIBadUserInput, "Placeholder node not found for reference #{node_id} in way #{id.nil? ? placeholder_id : id}" if new_id.nil?
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class MoveToInnodb < ActiveRecord::Migration[5.0]
|
||||||
# current version to something less so that we can update the version in
|
# current version to something less so that we can update the version in
|
||||||
# batches of 10000
|
# batches of 10000
|
||||||
tbl.classify.constantize.update_all(:version => -1)
|
tbl.classify.constantize.update_all(:version => -1)
|
||||||
tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 }) while tbl.classify.constantize.where(:version => -1).count > 0
|
tbl.classify.constantize.update_all("version=(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)", { :version => -1 }, { :limit => 10000 }) while tbl.classify.constantize.where(:version => -1).count.positive?
|
||||||
# execute "UPDATE current_#{tbl} SET version = " +
|
# execute "UPDATE current_#{tbl} SET version = " +
|
||||||
# "(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
|
# "(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
|
||||||
# The above update causes a MySQL error:
|
# The above update causes a MySQL error:
|
||||||
|
|
|
@ -398,7 +398,7 @@ module ActionController
|
||||||
# Sets the window's padding (the number of pages on either side of the
|
# Sets the window's padding (the number of pages on either side of the
|
||||||
# window page).
|
# window page).
|
||||||
def padding=(padding)
|
def padding=(padding)
|
||||||
@padding = padding < 0 ? 0 : padding
|
@padding = padding.negative? ? 0 : padding
|
||||||
# Find the beginning and end pages of the window
|
# Find the beginning and end pages of the window
|
||||||
@first = if @paginator.has_page_number?(@page.number - @padding)
|
@first = if @paginator.has_page_number?(@page.number - @padding)
|
||||||
@paginator[@page.number - @padding]
|
@paginator[@page.number - @padding]
|
||||||
|
|
|
@ -20,7 +20,7 @@ loop do
|
||||||
begin
|
begin
|
||||||
gpx = trace.import
|
gpx = trace.import
|
||||||
|
|
||||||
if gpx.actual_points > 0
|
if gpx.actual_points.positive?
|
||||||
Notifier.gpx_success(trace, gpx.actual_points).deliver
|
Notifier.gpx_success(trace, gpx.actual_points).deliver
|
||||||
else
|
else
|
||||||
Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
|
Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
|
||||||
|
|
|
@ -79,7 +79,7 @@ module GPX
|
||||||
px = proj.x(p.longitude)
|
px = proj.x(p.longitude)
|
||||||
py = proj.y(p.latitude)
|
py = proj.y(p.latitude)
|
||||||
|
|
||||||
if m > 0
|
if m.positive?
|
||||||
frames.times do |n|
|
frames.times do |n|
|
||||||
gc = if n == mm
|
gc = if n == mm
|
||||||
highlightgc.dup
|
highlightgc.dup
|
||||||
|
|
|
@ -747,7 +747,7 @@ class AmfControllerTest < ActionController::TestCase
|
||||||
assert_equal 5, result.size
|
assert_equal 5, result.size
|
||||||
assert_equal 0, result[0], "expected to get the status ok from the amf"
|
assert_equal 0, result[0], "expected to get the status ok from the amf"
|
||||||
assert_equal 0, result[2], "The old id should be 0"
|
assert_equal 0, result[2], "The old id should be 0"
|
||||||
assert result[3] > 0, "The new id should be greater than 0"
|
assert result[3].positive?, "The new id should be greater than 0"
|
||||||
assert_equal 1, result[4], "The new version should be 1"
|
assert_equal 1, result[4], "The new version should be 1"
|
||||||
|
|
||||||
# Finally check that the node that was saved has saved the data correctly
|
# Finally check that the node that was saved has saved the data correctly
|
||||||
|
@ -784,7 +784,7 @@ class AmfControllerTest < ActionController::TestCase
|
||||||
assert_equal 5, result.size
|
assert_equal 5, result.size
|
||||||
assert_equal 0, result[0], "Expected to get the status ok in the amf"
|
assert_equal 0, result[0], "Expected to get the status ok in the amf"
|
||||||
assert_equal 0, result[2], "The old id should be 0"
|
assert_equal 0, result[2], "The old id should be 0"
|
||||||
assert result[3] > 0, "The new id should be greater than 0"
|
assert result[3].positive?, "The new id should be greater than 0"
|
||||||
assert_equal 1, result[4], "The new version should be 1"
|
assert_equal 1, result[4], "The new version should be 1"
|
||||||
|
|
||||||
# Finally check that the node that was saved has saved the data correctly
|
# Finally check that the node that was saved has saved the data correctly
|
||||||
|
@ -831,7 +831,7 @@ class AmfControllerTest < ActionController::TestCase
|
||||||
assert_equal 5, result.size
|
assert_equal 5, result.size
|
||||||
assert_equal 0, result[0], "Expected to get the status ok in the amf"
|
assert_equal 0, result[0], "Expected to get the status ok in the amf"
|
||||||
assert_equal 0, result[2], "The old id should be 0"
|
assert_equal 0, result[2], "The old id should be 0"
|
||||||
assert result[3] > 0, "The new id should be greater than 0"
|
assert result[3].positive?, "The new id should be greater than 0"
|
||||||
assert_equal 1, result[4], "The new version should be 1"
|
assert_equal 1, result[4], "The new version should be 1"
|
||||||
|
|
||||||
# Finally check that the node that was saved has saved the data correctly
|
# Finally check that the node that was saved has saved the data correctly
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue