Skip to content

Commit

Permalink
feature/inline-classes(#698)
Browse files Browse the repository at this point in the history
### What's done:
  * Fixed bugs
  • Loading branch information
aktsay6 committed Jan 19, 2021
1 parent fdf2afb commit 82cd263
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AsyncAndSyncRule(private val configRules: List<RulesConfig>) : Rule("sync-
}

private fun checkRunBlocking(node: ASTNode) {
node.parent({it.isAsync() || it.isSuspend()})?.let {
node.parent({ it.isAsync() || it.isSuspend() })?.let {
RUN_BLOCKING_INSIDE_ASYNC.warn(configRules, emitWarn, isFixMode, node.text, node.startOffset, node)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CheckInverseMethodRule(private val configRules: List<RulesConfig>) : Rule(
.treeParent
.siblings(forward = false)
.takeWhile { it.elementType in intermediateTokens }
.firstOrNull { it.elementType == OPERATION_REFERENCE}
.firstOrNull { it.elementType == OPERATION_REFERENCE }
if (operationRef?.text == "!") {
INVERSE_FUNCTION_PREFERRED.warnAndFix(configRules, emitWarn, isFixMode, "${methodMap[node.text]} instead of !${node.text}", node.startOffset, node) {
val callExpression = CompositeElement(CALL_EXPRESSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ClassLikeStructuresOrderRule(private val configRules: List<RulesConfig>) :
unusedClasses)
.allBlockFlattened()
.map { astNode ->
Pair(astNode, astNode.siblings(false).takeWhile { it.elementType == WHITE_SPACE || it.isPartOfComment()}.toList())
Pair(astNode, astNode.siblings(false).takeWhile { it.elementType == WHITE_SPACE || it.isPartOfComment() }.toList())
}

val classChildren = node.children().filter { it.elementType in childrenTypes }.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ class IdentifierNaming(private val configRules: List<RulesConfig>) : Rule("ident
// FixMe: cover fixes with tests
val correctVariableName = variableName.text.toLowerCamelCase()
variableName
.parent({it.elementType == FILE})
.parent({ it.elementType == FILE })
?.findAllVariablesWithUsages { it.name == variableName.text }
?.flatMap { it.value.toList() }
?.forEach { (it.node.firstChildNode as LeafPsiElement).replaceWithText(correctVariableName)}
?.forEach { (it.node.firstChildNode as LeafPsiElement).replaceWithText(correctVariableName) }
(variableName as LeafPsiElement).replaceWithText(correctVariableName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LambdaLengthRule(private val configRules: List<RulesConfig>) : Rule("lambd
node.treeParent.removeChild(node)
}
}
val isIt = copyNode.findAllNodesWithSpecificType(ElementType.REFERENCE_EXPRESSION).map {re -> re.text}.contains("it")
val isIt = copyNode.findAllNodesWithSpecificType(ElementType.REFERENCE_EXPRESSION).map { re -> re.text }.contains("it")
val parameters = node.findChildByType(ElementType.FUNCTION_LITERAL)?.findChildByType(ElementType.VALUE_PARAMETER_LIST)
if (parameters == null && isIt) {
Warnings.TOO_MANY_LINES_IN_LAMBDA.warn(configRules, emitWarn, isFixMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LambdaParameterOrder(private val configRules: List<RulesConfig>) : Rule("l
private fun checkArguments(node: ASTNode) {
val funArguments = (node.psi as KtFunction).valueParameters
val sortArguments = funArguments.sortedBy { it.typeReference?.node?.hasChildOfType(FUNCTION_TYPE) }
funArguments.filterIndexed {index, ktParameter -> ktParameter != sortArguments[index] }.ifNotEmpty {
funArguments.filterIndexed { index, ktParameter -> ktParameter != sortArguments[index] }.ifNotEmpty {
LAMBDA_IS_NOT_LAST_PARAMETER.warn(configRules, emitWarn, isFixMode, node.findChildByType(IDENTIFIER)!!.text,
first().node.startOffset, node)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OverloadingArgumentsFunction(private val configRules: List<RulesConfig>) :
.map { it.psi as KtFunction }
.filter { it.nameIdentifier!!.text == funPsi.nameIdentifier!!.text && it.valueParameters.containsAll(funPsi.valueParameters) }
.filter { funPsi.node.findChildBefore(IDENTIFIER, TYPE_REFERENCE)?.text == it.node.findChildBefore(IDENTIFIER, TYPE_REFERENCE)?.text }
.filter {funPsi.node.findChildAfter(IDENTIFIER, TYPE_REFERENCE)?.text == it.node.findChildAfter(IDENTIFIER, TYPE_REFERENCE)?.text }
.filter { funPsi.node.findChildAfter(IDENTIFIER, TYPE_REFERENCE)?.text == it.node.findChildAfter(IDENTIFIER, TYPE_REFERENCE)?.text }
.toList()
if (allOverloadFunction.isNotEmpty()) {
WRONG_OVERLOADING_FUNCTION_ARGUMENTS.warn(configRules, emitWarn, isFixMode, funPsi.node.findChildByType(IDENTIFIER)!!.text, funPsi.startOffset, funPsi.node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class NewlinesRule(private val configRules: List<RulesConfig>) : Rule("newlines"
/**
* This method checks that complex expression should be replace with new variable
*/
private fun ASTNode.isInParentheses() = parent({it.elementType == DOT_QUALIFIED_EXPRESSION || it.elementType == SAFE_ACCESS_EXPRESSION})
private fun ASTNode.isInParentheses() = parent({ it.elementType == DOT_QUALIFIED_EXPRESSION || it.elementType == SAFE_ACCESS_EXPRESSION })
?.treeParent
?.elementType
?.let { it in parenthesesTypes }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class WhiteSpaceRule(private val configRules: List<RulesConfig>) : Rule("horizon
// note: the conditions in the following `if`s cannot be collapsed into simple conjunctions
if (isFromLambdaAsArgument) {
val isFirstArgument = node
.parent({ it.elementType == VALUE_ARGUMENT })
.let { it?.prevSibling { prevNode -> prevNode.elementType == COMMA } == null }
.parent({ it.elementType == VALUE_ARGUMENT })
.let { it?.prevSibling { prevNode -> prevNode.elementType == COMMA } == null }

// If it is lambda, then we don't force it to be on newline or same line
if (numWhiteSpace != 0 && isFirstArgument) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class CommentsFormatting(private val configRules: List<RulesConfig>) : Rule("kdo
}
if (node.treeParent.elementType == FILE) {
// This case is for top-level comments that are located in the beginning of the line and therefore don't need any spaces before.
if (!node.treePrev.isWhiteSpaceWithNewline() && node.treePrev.text.count { it == ' '} > 0) {
if (!node.treePrev.isWhiteSpaceWithNewline() && node.treePrev.text.count { it == ' ' } > 0) {
COMMENT_WHITE_SPACE.warnAndFix(configRules, emitWarn, isFixMode,
"There should be 0 space(s) before comment text, but are ${node.treePrev.text.count { it == ' ' }} in ${node.text}",
node.startOffset, node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class KdocComments(private val configRules: List<RulesConfig>) : Rule("kdoc-comm
?.findChildByType(KDOC) ?: return
val propertiesInKdoc = kdocBeforeClass
.kDocTags()
?.filter { it.knownTag == KDocKnownTag.PROPERTY}
?.filter { it.knownTag == KDocKnownTag.PROPERTY }
val propertyNames = (node.psi as KtParameterList)
.parameters
.mapNotNull { it.nameIdentifier?.text }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) {
@Tag(WarningNames.WRONG_WHITESPACE)
fun `check whitespaces around braces in lambda example - good`() {
lintMethod(
"""
"""
|fun foo() {
| list.map { it.text }
|}
Expand All @@ -632,13 +632,13 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) {
@Tag(WarningNames.WRONG_WHITESPACE)
fun `check whitespaces around braces in lambda example - bad`() {
lintMethod(
"""
"""
|fun foo() {
| list.map {it.text}
|}
""".trimMargin(),
LintError(2, 14, ruleId, "${WRONG_WHITESPACE.warnText()} there should be a whitespace after {", true),
LintError(2, 22, ruleId, "${WRONG_WHITESPACE.warnText()} there should be a whitespace before }", true)
LintError(2, 14, ruleId, "${WRONG_WHITESPACE.warnText()} there should be a whitespace after {", true),
LintError(2, 22, ruleId, "${WRONG_WHITESPACE.warnText()} there should be a whitespace before }", true)
)
}
}

0 comments on commit 82cd263

Please sign in to comment.