You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detect parameters of recursive function that are only used for passing it to the function again.
What problems does it solve:
This would help remove the argument and simplify both the recursive function and its call sites.
Example of things the rule would report:
recursive unusedValue list =case list of[]->1
x :: xs -> x + recursive unusedValue xs
In the case above, unusedValue is marked as used by NoUnused.Variables because it is used as an argument of recursive. But we never use the value anywhere else, meaning it serves no purpose.
We can report the same thing even if different values are passed in some cases.
recursive unusedValue list =case list of[]->1
x1 :: x2 :: xs -> x1 + recursive x2 xs
x :: xs -> x + recursive unusedValue xs
In the example above, the value of unusedValue may change, but we never use it anywhere.
Slightly more advanced:
recursive unusedValue list =case list of[]->1
x :: xs -> x + recursive (unusedValue -1) xs
For this one, it is used in an expression, but that expression ultimately ends up only being used as the same argument for recursive, meaning whatever the value may turn out to be, it will not serve any purpose.
To go one step further, we could detect let declarations
recursive unusedValue list =case list of[]->1
x :: xs ->let value = unusedValue -1in x + recursive value xs
And also pipeline usage (note that I've reversed arguments)
recursive list unusedValue =case list of[]->1
x :: xs -> unusedValue |> recursive xs
Example of things the rule would not report:
recursive accumulator list =case list of[]-> accumulator
x :: xs -> recursive (accumulator + x) xs
When (not) to enable this rule:
🤷♂️
I am looking for:
Other similar cases I've missed that could fit in this rule.
Someone to implement it with/for me
The text was updated successfully, but these errors were encountered:
What the rule should do:
Detect parameters of recursive function that are only used for passing it to the function again.
What problems does it solve:
This would help remove the argument and simplify both the recursive function and its call sites.
Example of things the rule would report:
In the case above,
unusedValue
is marked as used byNoUnused.Variables
because it is used as an argument ofrecursive
. But we never use the value anywhere else, meaning it serves no purpose.We can report the same thing even if different values are passed in some cases.
In the example above, the value of
unusedValue
may change, but we never use it anywhere.Slightly more advanced:
For this one, it is used in an expression, but that expression ultimately ends up only being used as the same argument for
recursive
, meaning whatever the value may turn out to be, it will not serve any purpose.To go one step further, we could detect let declarations
And also pipeline usage (note that I've reversed arguments)
Example of things the rule would not report:
When (not) to enable this rule:
🤷♂️
I am looking for:
The text was updated successfully, but these errors were encountered: