1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Enable Lint/UselessAssignment cop to avoid unused variable warnings (#34904)

* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings

Since we've addressed the warning "assigned but unused variable"
frequently.

370537de05
3040446cec
5ed618e192
76ebafe594

And also, I've found the unused args in c1b14ad which raises no warnings
by the cop, it shows the value of the cop.
This commit is contained in:
Ryuta Kamizono 2019-01-09 18:09:01 +09:00 committed by GitHub
parent 69ca787bd2
commit ea65d92f19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 25 deletions

View file

@ -191,6 +191,9 @@ Lint/StringConversionInInterpolation:
Lint/UriEscapeUnescape:
Enabled: true
Lint/UselessAssignment:
Enabled: true
Lint/DeprecatedClassMethods:
Enabled: true

View file

@ -888,7 +888,7 @@ class ControllerWithSymbolAsFilter < PostsController
yield
# Do stuff...
wtf += 1
wtf + 1
end
end

View file

@ -14,7 +14,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest
end
def dump_params_keys(hash = params)
hash.keys.sort.inject("") do |s, k|
hash.keys.sort.each_with_object(+"") do |k, s|
value = hash[k]
if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
@ -23,8 +23,8 @@ class WebServiceTest < ActionDispatch::IntegrationTest
value = ""
end
s += ", " unless s.empty?
s += "#{k}#{value}"
s << ", " unless s.empty?
s << "#{k}#{value}"
end
end
end

View file

@ -22,8 +22,8 @@ module ActiveRecord
def create_database(name, options = {})
options = { encoding: "utf8" }.merge!(options.symbolize_keys)
option_string = options.inject("") do |memo, (key, value)|
memo += case key
option_string = options.each_with_object(+"") do |(key, value), memo|
memo << case key
when :owner
" OWNER = \"#{value}\""
when :template

View file

@ -56,7 +56,7 @@ module ActiveRecord
def touch_attributes_with_time(*names, time: nil)
attribute_names = timestamp_attributes_for_update_in_model
attribute_names |= names.map(&:to_s)
attribute_names.index_with(time ||= current_time_from_proper_timezone)
attribute_names.index_with(time || current_time_from_proper_timezone)
end
private

View file

@ -15,8 +15,9 @@ module Arel # :nodoc: all
collector << "ORDER BY "
collector = inject_join o.orders, collector, ", "
end
collector = maybe_visit o.lock, collector
maybe_visit o.lock, collector
end
def visit_Arel_Nodes_SelectCore(o, collector)
collector = inject_join o.projections, collector, ", "
if o.source && !o.source.empty?

View file

@ -20,7 +20,7 @@ module Arel # :nodoc: all
def visit_Arel_Nodes_SelectOptions(o, collector)
collector = maybe_visit o.offset, collector
collector = maybe_visit o.limit, collector
collector = maybe_visit o.lock, collector
maybe_visit o.lock, collector
end
def visit_Arel_Nodes_Limit(o, collector)

View file

@ -208,14 +208,12 @@ module Arel # :nodoc: all
end
visit_Arel_Nodes_SelectOptions(o, collector)
collector
end
def visit_Arel_Nodes_SelectOptions(o, collector)
collector = maybe_visit o.limit, collector
collector = maybe_visit o.offset, collector
collector = maybe_visit o.lock, collector
maybe_visit o.lock, collector
end
def visit_Arel_Nodes_SelectCore(o, collector)

View file

@ -430,7 +430,7 @@ class EachTest < ActiveRecord::TestCase
assert_kind_of ActiveRecord::Relation, relation
assert_kind_of Post, relation.first
relation = [not_a_post] * relation.count
[not_a_post] * relation.count
end
end
end

View file

@ -144,7 +144,7 @@ class CounterCacheTest < ActiveRecord::TestCase
test "update other counters on parent destroy" do
david, joanna = dog_lovers(:david, :joanna)
joanna = joanna # squelch a warning
_ = joanna # squelch a warning
assert_difference "joanna.reload.dogs_count", -1 do
david.destroy

View file

@ -240,7 +240,7 @@ class InheritanceTest < ActiveRecord::TestCase
cabbage = vegetable.becomes!(Cabbage)
assert_equal "Cabbage", cabbage.custom_type
vegetable = cabbage.becomes!(Vegetable)
cabbage.becomes!(Vegetable)
assert_nil cabbage.custom_type
end
@ -654,7 +654,7 @@ class InheritanceAttributeMappingTest < ActiveRecord::TestCase
assert_equal ["omg_inheritance_attribute_mapping_test/company"], ActiveRecord::Base.connection.select_values("SELECT sponsorable_type FROM sponsors")
sponsor = Sponsor.first
sponsor = Sponsor.find(sponsor.id)
assert_equal startup, sponsor.sponsorable
end
end

View file

@ -104,7 +104,7 @@ class AssertionsTest < ActiveSupport::TestCase
def test_expression_is_evaluated_in_the_appropriate_scope
silence_warnings do
local_scope = "foo"
local_scope = local_scope # to suppress unused variable warning
_ = local_scope # to suppress unused variable warning
assert_difference("local_scope; @object.num") { @object.increment }
end
end

View file

@ -63,9 +63,9 @@ module RailsGuides
end
def mobi
mobi = "ruby_on_rails_guides_#{@version || @edge[0, 7]}"
mobi += ".#{@language}" if @language
mobi += ".mobi"
mobi = +"ruby_on_rails_guides_#{@version || @edge[0, 7]}"
mobi << ".#{@language}" if @language
mobi << ".mobi"
end
def initialize_dirs

View file

@ -95,8 +95,8 @@ class CodeStatistics #:nodoc:
end
def print_line(name, statistics)
m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0
loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0
m_over_c = (statistics.methods / statistics.classes) rescue 0
loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue 0
print "| #{name.ljust(20)} "
HEADERS.each_key do |k|

View file

@ -349,9 +349,9 @@ task default: :test
def wrap_in_modules(unwrapped_code)
unwrapped_code = "#{unwrapped_code}".strip.gsub(/\s$\n/, "")
modules.reverse.inject(unwrapped_code) do |content, mod|
str = "module #{mod}\n"
str += content.lines.map { |line| " #{line}" }.join
str += content.present? ? "\nend" : "end"
str = +"module #{mod}\n"
str << content.lines.map { |line| " #{line}" }.join
str << (content.present? ? "\nend" : "end")
end
end