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
Hi Jörg-Michael, I would like to request another feature. I realize that some of my previous issues didn't get an answer yet, but I would like to try nonetheless. 😉
The rule "Delete unused variables" currently only handles local variables. Although I don't use it for variable deletion, I highly value the functionality to add TODO comments for unused local variables. I would like to see this functionality extended to method parameters. For global classes, this should be well within the limitations of the ABAP Cleaner because the method definition and the method implementation is in the same include.
Example:
CLASSycl_example_2 DEFINITION PUBLIC INHERITING FROMycl_example_3 FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS example
IMPORTING
iv_i TYPE i.
ENDCLASS.
CLASSycl_example_2 IMPLEMENTATION.
METHODexample.
RETURN.
ENDMETHOD.
ENDCLASS.
Possible result:
PUBLIC SECTION.
METHODS example
IMPORTING" TODO: variable is never used (ABAP cleaner)
iv_i TYPE i.
I don't know if it is problematic to add regular comments within the method definition though. Another possibility would be to add the TODO comment at the start of the method. This would show the TODO comment in the SAP GUI as well, but it would require more details in the comment (and probably more logic to keep the comment updated).
METHODexample.
" TODO: variable IV_I is never used (ABAP cleaner)RETURN.
ENDMETHOD.
I do like the idea, and in principle (after some experimenting) it would almost work out of the box as part of the "Delete unused variables" rule (only if the method signature is in sight, of course).
We could nicely differentiate expectations, e.g. add a comment if
an IMPORTING parameter is never used,
a CHANGING parameter is never used or assigned,
an EXPORTING or RETURNING parameter is never assigned or cleared.
Maybe it would make sense to (optionally) restrict this to private methods only, because with a public or protected method, parameters may not necessarily be needed in every implementation, but possibly only in a child class or in a different class that implements the same interface. On the other hand, you could then add ##NEEDED to the signature to suppress the TODO comment – this also satisfies the Extended Check (SLIN) for unused parameters.
Some care would then indeed be required to avoid duplicate TODOs, remove obsolete TODOs etc.
The selection for the options always looks like this …
… the idea being that interface methods may be implemented in many different classes and possibly provide IMPORTING or CHANGING parameters that are required in some, but not all implementations (so not using them may be fine). By contrast, EXPORTING parameters should always at least be CLEARed (unless they are VALUE parameters). RETURNING parameters are initialized by default, and sometimes a method simply keeps them initial in every case (while a child class may return something different), so again, it would be fine to not assign them.
Examples:
Obsolete TODO comments are automatically removed (e.g. if parameters are now used or assigned, were renamed, removed, etc.).
Activity
jmgrassau commentedon Jan 2, 2024
Hi ConjuringCoffee,
I do like the idea, and in principle (after some experimenting) it would almost work out of the box as part of the "Delete unused variables" rule (only if the method signature is in sight, of course).
We could nicely differentiate expectations, e.g. add a comment if
Maybe it would make sense to (optionally) restrict this to private methods only, because with a public or protected method, parameters may not necessarily be needed in every implementation, but possibly only in a child class or in a different class that implements the same interface. On the other hand, you could then add ##NEEDED to the signature to suppress the TODO comment – this also satisfies the Extended Check (SLIN) for unused parameters.
Some care would then indeed be required to avoid duplicate TODOs, remove obsolete TODOs etc.
Kind regards,
Jörg-Michael
jmgrassau commentedon Jan 4, 2024
Hi ConjuringCoffee,
here's what my attempts look like so far:
The selection for the options always looks like this …
… the idea being that interface methods may be implemented in many different classes and possibly provide IMPORTING or CHANGING parameters that are required in some, but not all implementations (so not using them may be fine). By contrast, EXPORTING parameters should always at least be CLEARed (unless they are VALUE parameters). RETURNING parameters are initialized by default, and sometimes a method simply keeps them initial in every case (while a child class may return something different), so again, it would be fine to not assign them.
Examples:
Obsolete TODO comments are automatically removed (e.g. if parameters are now used or assigned, were renamed, removed, etc.).
Kind regards,
Jörg-Michael
ConjuringCoffee commentedon Jan 5, 2024
That sounds really good! 👍
add new rule "Report unused parameters" (SAP#224)
add new rule "Report unused parameters" (#224)
jmgrassau commentedon Jan 5, 2024
Hi ConjuringCoffee,
thanks again for this idea! The new cleanup rule is now available in version 1.13.0, which was just released!
Kind regards,
Jörg-Michael
ConjuringCoffee commentedon Jan 8, 2024
Awesome, thank you. I think this will really help us improve our code 😄