SAP / abap-cleaner

ABAP cleaner applies 75+ cleanup rules to ABAP code at a single keystroke
Apache License 2.0
413 stars 46 forks source link

Option: Align Parameters and Components - Issue #338

Open MichiFr opened 1 month ago

MichiFr commented 1 month ago

Hi

I've got this coding below. Note: The type and class-data declaration is given for convenience and for testing purposes only and not part of this ticket.

types:
    BEGIN OF t_byte_conversion
              ,bytes  TYPE decfloat34
              ,unit   TYPE string
              ,label  TYPE string
             ,END OF t_byte_conversion .
  types:
  tt_byte_conversion TYPE STANDARD TABLE OF t_byte_conversion WITH EMPTY KEY .
  class-data V_BYTE_CONVERSION_DEC type ZCL_GENERIC=>TT_BYTE_CONVERSION read-only .

    IF v_byte_conversion_dec[] IS INITIAL.
      v_byte_conversion_dec = VALUE #(
          ( bytes = 1                           unit = 'B'  label = 'Byte' )      ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 3  )  unit = 'kB' label = 'Kilobyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 6  )  unit = 'MB' label = 'Megabyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 9  )  unit = 'GB' label = 'Gigabyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 12 )  unit = 'TB' label = 'Terabyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 15 )  unit = 'PB' label = 'Petabyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 18 )  unit = 'EB' label = 'Exabyte' )   ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 21 )  unit = 'ZB' label = 'Zettabyte' ) ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 24 )  unit = 'YB' label = 'Yottabyte' ) ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 27 )  unit = 'XB' label = 'Xonabyte' )  ##NO_TEXT
          ( bytes = ipow( base = 10 exp = 30 )  unit = ''   label = '' )  "Für Schleifendurchlauf benötigt, immer als letzer Zeile
      ) .
    ENDIF.

Which gets formatted with option "Align parameters and components" to the source below. image

Any reason why the first line does not get any line breaks for its members: unit and label whereas all other do?

IF v_byte_conversion_dec[] IS INITIAL.
      v_byte_conversion_dec = VALUE #( ( bytes = 1                           unit = 'B'  label = 'Byte' )      ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 3  )
                                         unit  = 'kB'
                                         label = 'Kilobyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 6  )
                                         unit  = 'MB'
                                         label = 'Megabyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 9  )
                                         unit  = 'GB'
                                         label = 'Gigabyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 12 )
                                         unit  = 'TB'
                                         label = 'Terabyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 15 )
                                         unit  = 'PB'
                                         label = 'Petabyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 18 )
                                         unit  = 'EB'
                                         label = 'Exabyte' )   ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 21 )
                                         unit  = 'ZB'
                                         label = 'Zettabyte' ) ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 24 )
                                         unit  = 'YB'
                                         label = 'Yottabyte' ) ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 27 )
                                         unit  = 'XB'
                                         label = 'Xonabyte' )  ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 30 )
                                         unit  = ''
                                         label = '' ) ). " Für Schleifendurchlauf benötigt, immer als letzer Zeile
    ENDIF.

I would have expected this formatting for the first line in the original source.

    IF v_byte_conversion_dec[] IS INITIAL.
      v_byte_conversion_dec = VALUE #( ( bytes = 1                           
                                         unit = 'B'  
                                         label = 'Byte' )      ##NO_TEXT
                                       ( bytes = ipow( base = 10
                                                       exp  = 3  )
                                         unit  = 'kB'
                                         label = 'Kilobyte' )  ##NO_TEXT
...
jmgrassau commented 1 month ago

Hi Michael,

interesting example, thanks! This happens because of the following option:

image

With that, one-liners are kept, because they are often nicely readable (IMHO, your original code is almost perfect as it is). If you change the setting to "never", you will get the expected result:

image

The problem here is that the inner parenthesis of ipow( base = ... exp = ... ) is not a table row, so "Align parameters and components" first moves the exp parameter to the second line; then the outer parentheses aren't on a single line anymore – except for the first line – so their parameters get aligned, too.

So, it's not a defect, but the result doesn't look well, either. Hm …

Kind regards, Jörg-Michael

MichiFr commented 1 month ago

Thanks for reading and your explanation!

I've changed the mentioned option and it looks good now !

You can close this ticket if you want!

Michael