Skip to content
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

Check 95: Add filter so that some classes can be ignored. #1165

Open
nununo opened this issue Feb 4, 2025 · 4 comments
Open

Check 95: Add filter so that some classes can be ignored. #1165

nununo opened this issue Feb 4, 2025 · 4 comments

Comments

@nununo
Copy link

nununo commented Feb 4, 2025

I want to flag the use of me-> everywhere except in exception classes.

It would be great if a filter could be added so I could set it to ignore zcx_*.

I will try to implement this myself.

@ConjuringCoffee
Copy link
Collaborator

ConjuringCoffee commented Feb 4, 2025

Why though? Is it because CX_ROOT has method parameters that are named exactly like attributes? If so, then that might be more sensible than defining filters on class name level 😉

@nununo
Copy link
Author

nununo commented Feb 4, 2025

Hum, well, I have this exception class which I think was generated by ABAP:

CLASS zcx_coot DEFINITION
  PUBLIC
    INHERITING FROM cx_static_check
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_t100_dyn_msg .
    INTERFACES if_t100_message .

    METHODS constructor
      IMPORTING
        !textid   LIKE if_t100_message=>t100key OPTIONAL
        !previous LIKE previous OPTIONAL .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcx_coot IMPLEMENTATION.
  METHOD constructor ##ADT_SUPPRESS_GENERATION.
    CALL METHOD super->constructor
      EXPORTING
        previous = previous.
    CLEAR me->textid.
    IF textid IS NOT INITIAL.
      if_t100_message~t100key = textid.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

The constructor uses both the parameter textid and the attribute me->textid.

I agree that having method parameters shadow class attributes is a bad idea but this is code generated by SAP. What would you do in this case?

@ConjuringCoffee
Copy link
Collaborator

Personally, I think me-> only makes sense when parameters shadow attributes. Sometimes this can't be avoided.

My suggestion would be to adapt check 95 to not raise an error if there is shadowing. Check 46 already has shadowing detection, so you might be able to extract the logic from there.

@nununo
Copy link
Author

nununo commented Feb 5, 2025

That makes total sense. Perfect. I'll try to implement it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants