You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also added some code in IndentationRule class that resolves the issue, but I'm sure there is a better and more idiomatic way to implement it.
Despite, here is my modification of IndentationRule.visitMethodCallExpression():
@Override
void visitMethodCallExpression(MethodCallExpression call) {
// If the method name starts on a different line, then assume it is a chained method call,
// and any blocks that are arguments should be indented.
if (isChainedMethodCallOnDifferentLine(call) && call.arguments instanceof ArgumentListExpression) {
call.arguments.expressions.each { expr ->
if (expr instanceof ClosureExpression && expr.code instanceof BlockStatement) {
blockIndentLevel[expr.code] = blockIndentLevel[expr.code] + 1
}
}
}
if (call.arguments instanceof ArgumentListExpression && !call.arguments.expressions.isEmpty() && !(call.arguments.expressions.last() instanceof ClosureExpression)) {
call.arguments.expressions.each { expr ->
if (expr instanceof ClosureExpression && expr.code instanceof BlockStatement && (expr.lineNumber != expr.lastColumnNumber)) {
blockIndentLevel[expr.code] = blockIndentLevel[expr.code] + 1
}
}
}
super.visitMethodCallExpression(call)
}
Tnx
The text was updated successfully, but these errors were encountered:
Ugh, the Indentation rule has been quite the pain in the butt. It started out relatively simple, just trying to go after the low-hanging fruit -- the easy stuff supported by the Groovy AST. But one special case after another has added a bunch of complexity and brittleness.
Thanks for providing the example code that caused the false positive, as well as the possible code fix. That fix did address that one particular example, but not several other related ones that I tried. I ended up adding some more flexibility to the rule so that method call parameters that are Closures with blocks can have those statements within a range of indent levels. We'll see how that holds up to the brutal realities of widespread use.
In Spock interaction tests, I stumbled on some indentation warnings. Here is the code fragment with marked relevant lines:
After some debugging and reading CodeNarc code, I believe I managed to recreate the issue by adding the following test in
IndentationRuleTest
:I also added some code in
IndentationRule
class that resolves the issue, but I'm sure there is a better and more idiomatic way to implement it.Despite, here is my modification of
IndentationRule.visitMethodCallExpression()
:Tnx
The text was updated successfully, but these errors were encountered: