-
Notifications
You must be signed in to change notification settings - Fork 37
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
[Bug] bad-indent false positive if [Documentation] used in test case that uses Test Template #808
Comments
Hey @sekwahs and thanks for the report. Can you please try to enclose your code inside a triple ``` character, so that the code saves the original formatting? ``` will result in:
|
Updated example.
…On Wed, Mar 29, 2023, 9:08 AM Mateusz Nojek ***@***.***> wrote:
Hey @sekwahs <https://github.com/sekwahs> and thanks for the report.
Unfortunately, I can't reproduce it, because you pasted the code in an
unformatted way, so all the whitespaces were removed, and that is crucial
to understand the issue.
Can you please try to enclose your code inside a triple ``` character, so
that the code saves the original formatting?
```
Like this
```
will result in:
Like this
—
Reply to this email directly, view it on GitHub
<#808 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A23OLD5RXCOIGFUYEQWNHWLW6Q64JANCNFSM6AAAAAAWL745YE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
OK, after reviewing this case, I started thinking if this rule should be applied to templated suites at all. The official documentation is very scarce about using test case settings along with the templated suite. Actually, it does not mention it at all, and I see people doing it (because it's allowed). There are no examples how to do it, so the users come up with different approaches. The code you shared with us looks correct (apart from the other formatting, which violates many Robocop rules, but this is not our concern here) and is properly parsed by Robot Framework. Honestly, I don't know what should be the approach for formatting templated suites. In our test data we have such example (that reports no Robocop issues):
and also yours above, which represents different approach. BTW, your code would not report any issues if written like this:
I need to ask for an advice here @bhirsz and maybe @pekkaklarck. |
Ok, I gave a lot of time to think about it and I must say, that this behavior is not a bug. Robocop purpose is to serve as a tool that checks whether the code aligns with good practices or contains errors. In your code snippet, Robocop complained about the line being under-indented and... it's true. As suggested in my previous comment - if you align it like this:
Robocop will not complain. If you don't want to receive this message, you can either disable it from the command line (
@sekwahs Feel free to share what you feel about it, but this will not be fixed, since it's not a bug. It's just how Robocop works. |
We differ on our interpretation of the word indentation. In my programming experience indentation is the amount of whitespace at the beginning of a line and is typically used to indicate logical syntactic levels within code; spacing between language elements is not considered to be indentation. In this new 3.0.0 implementation of bad-indent the meaning of the word indentation is apparently alignment of words across vertical sections of code regardless of their actual relationship to each other. In the cited example, "argument=abc" has no inherent or implied relationship to the line that starts with "[Documentation]" and thus should require no relative alignment across lines. Perhaps my confusion is based on the name of the rule, bad-indent, which implies it deals solely with indentation. I see now that the documentation for the rule says "Line is misaligned or indent is invalid," so the rule actually looks for more than indentation. In this case I would argue that alignment checking should be covered by a different rule than indentation checking since a) the rule is bad-indent, not bad-alignment, and b) indentation is inherently important in robot and consistency promotes readability, but alignment of unrelated language elements across lines is not inherently important, is not restricted by robot, and whether or how such alignment should be done is a very debatable topic and a choice which should be left to programmers. I could argue at length on why the alignment suggested above between the start of a line within a keyword body should have no connection with the alignment of arguments to the keyword, but that isn't the important issue here; the difference between indentation checking and alignment checking is what is relevant here, along with the ability to separate the two types of checking when enforcing rules. If with release 3.0.0 there are new or old rules that allow checking only indentation without checking alignment based on language elements following the initial indentation, please point me to these so I can attempt to find a solution that provides the functionality desired by my development team. |
I agree with the notion that "bad-indent" should mark problems with the indent, not the alignment. In this case we are actually iterating over statements in the node and we're a not checking if the line is the same. In case of:
We're getting following statements:
And then we're checking for indentation for each statement. I think we should:
We could also wait for Robot Framework style guide decision on indentation etc, they have this dicussion on their roadmap. Unfortunately "bad-indent" rule is one of most unstable rules (we keep changing its implementation) and it could be good to do it once and for good. |
And the last statement is the reason we think it would be best to "park" this issue for now. We don't want to keep changing the rule and it's best to wait until there is official guideline in the Robot Framework (and it's in the progress). There is very high chance that we will follow approach proposed by you in the end but still, we don't want to rush it to avoid changing this rule yet again. In the meantime you can exclude bad-indent and bad-block-indent and create your own custom rule. Below there is version that should work like you want:
The code could be a lot shorter if you just want to check strict indentation, not "most common indent in block" which is also allowed. |
What happened?
Seeing "Line is under-indented (bad-indent)" when a test case for which Test Template is used contains a [Documentation] line.
Example:
What command/code did you try to run?
robocop example.robot
What is the full error message?
example.robot:8:1 [W] 1008 Line is under-indented (bad-indent)
What did you expect to happen instead?
Did not expect this to trigger a warning.
Operating System
Linux
Robocop version
3.0.0
The text was updated successfully, but these errors were encountered: