Replace no_inline_in_optional_branches with new rule
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:
IMHO no_inline_in_optional_branches should be deleted and replaced with new rule.
Solves #2522.
yes 👍
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.
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?
I'll get to it sometime
I'll get to it sometime
Maybe adding pseudo comment & pragma as the workaround for now would do the trick?