Permalink
Browse files

Don't warn about unused arguments if they're passed implicitly via su…

…per.

Signed-off-by: Kevin Clark <kevin.clark@gmail.com>
  • Loading branch information...
Brian Donovan authored and kevinclark committed Mar 16, 2009
1 parent ef77b8a commit 069b939deb8761899ae6e68f0a95b8ff535a72ce
Showing with 28 additions and 1 deletion.
  1. +7 −0 lib/dust/argument_duster.rb
  2. +12 −0 spec/argument_duster_spec.rb
  3. +1 −1 spec/duster_spec.rb
  4. +8 −0 spec/fixtures/local_variable_badness.rb
@@ -1,7 +1,9 @@
module Dust
class ArgumentDuster < LocalVariableCounter
def dust!
+ @silence_warnings = false
super
+ return if @silence_warnings
@lvars.each do |name, details|
next if details[:calls] > 0
@@ -10,5 +12,10 @@ def dust!
warn Warnings::UnusedArgument.new(name)
end
end
+
+ def process_zsuper(exp)
+ @silence_warnings = true
+ s(:zsuper)
+ end
end
end
@@ -23,6 +23,18 @@
duster.warnings.should == []
end
+ it "should not create warnings when calling super with no explicit arguments" do
+ duster = Dust::ArgumentDuster.new(LocalVariableBadness, :super_with_implicit_args)
+ duster.dust!
+ duster.warnings.should == []
+ end
+
+ it "should create warnings when calling super with explicit arguments but without referencing the passed arguments" do
+ duster = Dust::ArgumentDuster.new(LocalVariableBadness, :super_with_explicit_args)
+ duster.dust!
+ duster.warnings.should == [Dust::Warnings::UnusedArgument.new(:arg)]
+ end
+
it "should not create warnings for args used with splats" do
duster = Dust::ArgumentDuster.new(LocalVariableBadness, :args_used_with_splats)
duster.dust!
View
@@ -17,4 +17,4 @@
@duster.scan_for warnings, :with => branches
end
-end
+end
@@ -93,6 +93,14 @@ def block_arg_curried(&block)
respond(&block)
end
+ def super_with_implicit_args(arg)
+ super
+ end
+
+ def super_with_explicit_args(arg)
+ super()
+ end
+
def rescue_to_variable
begin
rescue => e

0 comments on commit 069b939

Please sign in to comment.