SAP / abap-cleaner

ABAP cleaner applies 95+ cleanup rules to ABAP code at a single keystroke
Apache License 2.0
457 stars 48 forks source link

Delete unused variables #333

Closed JoachimEck closed 5 months ago

JoachimEck commented 5 months ago

Hey again,

sorry but today it is a strange day 😄

When I use the ABAP Cleaner, it doesn't delete the unused variables in some cases. I have set up an example. image image It moves the used variables, so it seems to recognize that the others are not used. If I remove the "ASSIGN" commands, it deletes everything. Here is the entire profile again: profile.zip

Sorry for so much work today. But I love your tool!

Thanks.

Best regards, Joachim

jmgrassau commented 5 months ago

Hi Joachim,

thanks for opening this! Unfortunately, this is "no defect", because as soon as ABAP cleaner finds a dynamic ASSIGN ('...') (or macro usage or test injection), it skips the "Delete unused variables" rule altogether for the current method. While things are obvious in your example, it would generally be too difficult (and in many cases, impossible) to determine which variables are used dynamically and which aren't.

But please keep going! Maybe you just have some pieces of rare syntax in today's code, which ABAP cleaner has never been confronted with!

Kind regards, Jörg-Michael

P.S.: Other rules that may be skipped in such cases are "Use FINAL for immutable variables", "Remove needless CLEAR", and "Report unused parameters".

JoachimEck commented 5 months ago

Hi Jörg-Michael,

thank you very much for your explanation. Now I can understand that.

Best regards, Joachim