Skip to content
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

Wrong newlines in functional style #346

Merged
merged 14 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class NewlinesRule(private val configRules: List<RulesConfig>) : Rule("newlines"
}
}

@Suppress("ComplexMethod")
private fun handleOperatorWithLineBreakBefore(node: ASTNode) {
if (node.isDotFromPackageOrImport()) {
return
Expand Down Expand Up @@ -305,6 +306,22 @@ class NewlinesRule(private val configRules: List<RulesConfig>) : Rule("newlines"
getAllLeafsWithSpecificType(SAFE_ACCESS, it)
}
}
// fixme: we can't distinguish fully qualified names from chain of calls for now
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// fixme: we can't distinguish fully qualified names from chain of calls for now
// fixme: we can't distinguish fully qualified names (like java.lang) from chain of property accesses (like list.size) for now

Just to be sure we don't forget what this was about

?.filter {
aktsay6 marked this conversation as resolved.
Show resolved Hide resolved
if (it.elementType == DOT) {
val dotExprs = it.treeParent.text.split(".")

// should skip node's that are val params. For example: b.some(z.a()) -> skip z.a()
aktsay6 marked this conversation as resolved.
Show resolved Hide resolved
if (it.treeParent.treeParent != null && it.treeParent.treeParent.elementType == VALUE_PARAMETER_LIST)
return@filter false

val firstCallee = 1
return@filter if (dotExprs[firstCallee].contains('(') || dotExprs[firstCallee].contains('{')) {
true
} else dotExprs.last().contains('(') || dotExprs.last().contains('{')
}
true
}
?.filter { it.getParentExpressions().count() > 1 }
?.count()
?.let { it > 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,17 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
LintError(2, 5, ruleId, singleReturnWarn, true)
)
}

@Test
@Tag(WarningNames.WRONG_NEWLINES)
fun `should not trigger`() {
lintMethod(
"""
|fun foo(): String {
| val isParallelMode: Boolean
| get() = java.lang.Boolean.getBoolean(properties.getProperty("parallel.mode"))
|}
""".trimMargin()
)
}
}