-
Notifications
You must be signed in to change notification settings - Fork 39
Unused argument rule #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I don't think it makes sense to enforce removing unused arguments. They might be part of a public API and sometimes need to be there even if they're unused.
With inlined blocks, it is fine to remove unused arguments. But blocks that are cought in a It is certainly useful to identify unused arguments, especially in internal methods. But in public API's they're probably more often explicitly wanted than not. They obviously can't be removed but also shouldn't trigger an error (or require manual disabling) every time. I don't know what would be a good way to do this. Maybe limit to private methods, but private methods can also be part of a defined API (for example the |
And in this case renaming the argument (prepending the
This is a very good argument. What I think now is making each of these types (def, block and proc) be disableable. This is very easy to do within the configuration file. For example, if the user would want to disable the verification of the unused arguments in defs, he will need to do: # .ameba.yml
UnusedArgument:
check_def: false
# check_block: true
# check_proc: true do you think we need to make this default? Enabling it may be good for new projects, where the API is not standardized yet. |
@asterite sorry, but need your help :) Could you please explain why there is def method(a)
yield a # => no &block needed
end
def method(a, &block)
p block # => doesn't compile
block.call(a) # => doesn't compile
&block.call(a) # => doesn't compile
end is there any usecase? |
Yes, renaming should be fine there.
Yes, definitely. False positives would produce lots of annoying noise otherwise.
def method(a, &block : String ->)
block.call(a)
end
method("foo") { |s| puts s } |
4791a2a
to
cc6b272
Compare
TODO:
def foo(a) # <-- `a` is used implicitly
super
end |
A rule that reports unused arguments. For example, this is considered invalid:
and should be written as:
or
Also it detects unused arguments in blocks and procs:
but in this case
&block
arg is still just a dummy argument and can be omitted.