@@ -4,12 +4,10 @@ import com.saveourtool.diktat.common.config.rules.RuleConfiguration
4
4
import com.saveourtool.diktat.common.config.rules.RulesConfig
5
5
import com.saveourtool.diktat.common.config.rules.getRuleConfig
6
6
import com.saveourtool.diktat.ruleset.constants.Warnings.COMPLEX_EXPRESSION
7
- import com.saveourtool.diktat.ruleset.constants.Warnings.REDUNDANT_SEMICOLON
8
7
import com.saveourtool.diktat.ruleset.constants.Warnings.WRONG_NEWLINES
9
8
import com.saveourtool.diktat.ruleset.rules.DiktatRule
10
9
import com.saveourtool.diktat.ruleset.utils.appendNewlineMergingWhiteSpace
11
10
import com.saveourtool.diktat.ruleset.utils.emptyBlockList
12
- import com.saveourtool.diktat.ruleset.utils.extractLineOfText
13
11
import com.saveourtool.diktat.ruleset.utils.findAllDescendantsWithSpecificType
14
12
import com.saveourtool.diktat.ruleset.utils.findAllNodesWithCondition
15
13
import com.saveourtool.diktat.ruleset.utils.findParentNodeWithSpecificType
@@ -19,7 +17,6 @@ import com.saveourtool.diktat.ruleset.utils.getIdentifierName
19
17
import com.saveourtool.diktat.ruleset.utils.getRootNode
20
18
import com.saveourtool.diktat.ruleset.utils.hasParent
21
19
import com.saveourtool.diktat.ruleset.utils.isBeginByNewline
22
- import com.saveourtool.diktat.ruleset.utils.isEol
23
20
import com.saveourtool.diktat.ruleset.utils.isFollowedByNewline
24
21
import com.saveourtool.diktat.ruleset.utils.isGradleScript
25
22
import com.saveourtool.diktat.ruleset.utils.isSingleLineIfElse
@@ -37,7 +34,6 @@ import org.jetbrains.kotlin.KtNodeTypes.CALL_EXPRESSION
37
34
import org.jetbrains.kotlin.KtNodeTypes.CLASS
38
35
import org.jetbrains.kotlin.KtNodeTypes.CONDITION
39
36
import org.jetbrains.kotlin.KtNodeTypes.DOT_QUALIFIED_EXPRESSION
40
- import org.jetbrains.kotlin.KtNodeTypes.ENUM_ENTRY
41
37
import org.jetbrains.kotlin.KtNodeTypes.FUN
42
38
import org.jetbrains.kotlin.KtNodeTypes.FUNCTION_LITERAL
43
39
import org.jetbrains.kotlin.KtNodeTypes.FUNCTION_TYPE
@@ -90,7 +86,6 @@ import org.jetbrains.kotlin.lexer.KtTokens.PLUSEQ
90
86
import org.jetbrains.kotlin.lexer.KtTokens.RETURN_KEYWORD
91
87
import org.jetbrains.kotlin.lexer.KtTokens.RPAR
92
88
import org.jetbrains.kotlin.lexer.KtTokens.SAFE_ACCESS
93
- import org.jetbrains.kotlin.lexer.KtTokens.SEMICOLON
94
89
import org.jetbrains.kotlin.lexer.KtTokens.WHITE_SPACE
95
90
import org.jetbrains.kotlin.psi.KtBinaryExpression
96
91
import org.jetbrains.kotlin.psi.KtNamedFunction
@@ -106,31 +101,29 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
106
101
private typealias ListOfList = MutableList <MutableList <ASTNode >>
107
102
108
103
/* *
109
- * Rule that checks line break styles.
110
- * 1. Prohibits usage of semicolons at the end of line
111
- * 2. Checks that some operators are followed by newline, while others are prepended by it
112
- * 3. Statements that follow `!!` behave in the same way
113
- * 4. Forces functional style of chained dot call expressions with exception
114
- * 5. Checks that newline is placed after assignment operator, not before
115
- * 6. Ensures that function or constructor name isn't separated from `(` by space or newline
116
- * 7. Ensures that in multiline lambda newline follows arrow or, in case of lambda without explicit parameters, opening brace
117
- * 8. Checks that functions with single `return` are simplified to functions with expression body
118
- * 9. parameter or argument lists and supertype lists that have more than 2 elements should be separated by newlines
119
- * 10. Complex expression inside condition replaced with new variable
104
+ * Rule that checks line break styles:
105
+ * 1. Checks that some operators are followed by newline, while others are prepended by it
106
+ * 2. Statements that follow `!!` behave in the same way
107
+ * 3. Forces functional style of chained dot call expressions with exception
108
+ * 4. Checks that newline is placed after assignment operator, not before
109
+ * 5. Ensures that function or constructor name isn't separated from `(` by space or newline
110
+ * 6. Ensures that in multiline lambda newline follows arrow or, in case of lambda without explicit parameters, opening brace
111
+ * 7. Checks that functions with single `return` are simplified to functions with expression body
112
+ * 8. Parameter or argument lists and supertype lists that have more than 2 elements should be separated by newlines
113
+ * 9. Complex expression inside condition replaced with new variable
120
114
*/
121
115
@Suppress(" ForbiddenComment" )
122
116
class NewlinesRule (configRules : List <RulesConfig >) : DiktatRule(
123
117
NAME_ID ,
124
118
configRules,
125
- listOf(COMPLEX_EXPRESSION , REDUNDANT_SEMICOLON , WRONG_NEWLINES )
119
+ listOf(COMPLEX_EXPRESSION , WRONG_NEWLINES )
126
120
) {
127
121
private val configuration by lazy {
128
122
NewlinesRuleConfiguration (configRules.getRuleConfig(WRONG_NEWLINES )?.configuration ? : emptyMap())
129
123
}
130
124
131
125
override fun logic (node : ASTNode ) {
132
126
when (node.elementType) {
133
- SEMICOLON -> handleSemicolon(node)
134
127
OPERATION_REFERENCE , EQ -> handleOperatorWithLineBreakAfter(node)
135
128
// this logic regulates indentation with elements - so that the symbol and the subsequent expression are on the same line
136
129
in lineBreakBeforeOperators -> handleOperatorWithLineBreakBefore(node)
@@ -206,18 +199,6 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
206
199
private fun isDotQuaOrSafeAccessOrPostfixExpression (node : ASTNode ) =
207
200
node.elementType == DOT_QUALIFIED_EXPRESSION || node.elementType == SAFE_ACCESS_EXPRESSION || node.elementType == POSTFIX_EXPRESSION
208
201
209
- /* *
210
- * Check that EOL semicolon is used only in enums
211
- */
212
- private fun handleSemicolon (node : ASTNode ) {
213
- if (node.isEol() && node.treeParent.elementType != ENUM_ENTRY ) {
214
- // semicolon at the end of line which is not part of enum members declarations
215
- REDUNDANT_SEMICOLON .warnAndFix(configRules, emitWarn, isFixMode, node.extractLineOfText(), node.startOffset, node) {
216
- node.treeParent.removeChild(node)
217
- }
218
- }
219
- }
220
-
221
202
private fun handleOperatorWithLineBreakAfter (node : ASTNode ) {
222
203
// [node] should be either EQ or OPERATION_REFERENCE which has single child
223
204
if (node.elementType != EQ && node.firstChildNode.elementType !in lineBreakAfterOperators && ! node.isInfixCall()) {
0 commit comments