abaplint icon indicating copy to clipboard operation
abaplint copied to clipboard

Replace no_inline_in_optional_branches with new rule

Open jan-jezek opened this issue 2 years ago • 5 comments

With SAP/styleguides#302 the styleguide has been changed to better describe the problem. https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#do-not-use-variables-outside-of-the-statement-block-they-are-declared-in

Now it is described as: image

IMHO no_inline_in_optional_branches should be deleted and replaced with new rule.

Solves #2522.

jan-jezek avatar Dec 27 '23 12:12 jan-jezek

yes 👍

larshp avatar Dec 28 '23 07:12 larshp

I was just going to report an issue, then found #2522 and this one, and would like to add my vote for it. A declaration for a looped table row used only inside the loop body makes sense. One exception I'd consider acceptable is a single read immediately afterwards where the last item is relevant, but that's just my opinion.

loop at itab into data(row).
  do_stuff_with( row ).
endloop.
data(last) = row.

pokrakam avatar Jul 19 '24 14:07 pokrakam

I was just going to report an issue, then found #2522

Same here 😄

I turned the no_inline_in_optional_branches on as I was hoping it will somehow work in pair with prefer_inline but I got more issues instead 😞 .

So this guideline posted in the first comment (link) actually, impacts also prefer_inline. As prefer_inline always says "do the inline if you didn't" and this guideline says "ok, if you need to use the variable in some optional blocks, declare it upfront". At least that's how I understand it. Correct me if I'm wrong. If I'm right, then what about prefer_inline rule?

DGRHicron avatar Aug 01 '24 18:08 DGRHicron

I'll get to it sometime

larshp avatar Aug 02 '24 05:08 larshp

I'll get to it sometime

Maybe adding pseudo comment & pragma as the workaround for now would do the trick?

DGRHicron avatar Aug 02 '24 07:08 DGRHicron