Skip to content

Commit

Permalink
bugfix/newlinesrule(#748)
Browse files Browse the repository at this point in the history
### What's done:
  * Fixed bugs
  • Loading branch information
aktsay6 committed Feb 9, 2021
1 parent 7e84d83 commit c4d5b74
Show file tree
Hide file tree
Showing 60 changed files with 187 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import java.io.File
*/
@Suppress("ForbiddenComment")
class FileNaming(configRules: List<RulesConfig>) : DiktatRule(
"file-naming",
configRules,
listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) {
"file-naming",
configRules,
listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) {
private lateinit var filePath: String

override fun logic(node: ASTNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.resolve.ImportPath
*/
@Suppress("ForbiddenComment")
class CommentsRule(configRules: List<RulesConfig>) : DiktatRule(
"comments",
configRules,
listOf(COMMENTED_OUT_CODE)) {
"comments",
configRules,
listOf(COMMENTED_OUT_CODE)) {
private lateinit var ktPsiFactory: KtPsiFactory

override fun logic(node: ASTNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
* 3) All properties declared in the primary constructor are documented using `@property` tag in class KDoc
*/
class KdocComments(configRules: List<RulesConfig>) : DiktatRule(
"kdoc-comments",
configRules,
listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY,
KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) {
"kdoc-comments",
configRules,
listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY,
KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) {
/**
* @param node
* @param autoCorrect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ import java.time.temporal.ChronoField
*/
@Suppress("ForbiddenComment")
class KdocFormatting(configRules: List<RulesConfig>) : DiktatRule(
"kdoc-formatting",
configRules,
listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG,
KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS,
KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) {
"kdoc-formatting",
configRules,
listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG,
KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS,
KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) {
private val basicTagsList = listOf(KDocKnownTag.PARAM, KDocKnownTag.RETURN, KDocKnownTag.THROWS)
private val specialTagNames = setOf("implSpec", "implNote", "apiNote")
private var versionRegex: Regex? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
*/
@Suppress("ForbiddenComment")
class KdocMethods(configRules: List<RulesConfig>) : DiktatRule(
"kdoc-methods",
configRules,
listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG,
KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) {
"kdoc-methods",
configRules,
listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG,
KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) {
/**
* @param node
* @param autoCorrect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
* This rule makes each annotation applied to a class, method or constructor is on its own line. Except: if first annotation of constructor, class or method
*/
class AnnotationNewLineRule(configRules: List<RulesConfig>) : DiktatRule(
"annotation-new-line",
configRules,
listOf(ANNOTATION_NEW_LINE)) {
"annotation-new-line",
configRules,
listOf(ANNOTATION_NEW_LINE)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import org.jetbrains.kotlin.psi.KtTryExpression
* - braces around `else`/`catch`/`finally`/`while` (in `do-while` loop)
*/
class BlockStructureBraces(configRules: List<RulesConfig>) : DiktatRule(
"block-structure",
configRules,
listOf(BRACES_BLOCK_STRUCTURE_ERROR)) {
"block-structure",
configRules,
listOf(BRACES_BLOCK_STRUCTURE_ERROR)) {
override fun logic(node: ASTNode) {
val configuration = BlockStructureBracesConfiguration(
configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace
* Rule that checks that all conditionals and loops have braces.
*/
class BracesInConditionalsAndLoopsRule(configRules: List<RulesConfig>) : DiktatRule(
"braces-rule",
configRules,
listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) {
"braces-rule",
configRules,
listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
IF -> checkIfNode(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* Rule that checks order of declarations inside classes, interfaces and objects.
*/
class ClassLikeStructuresOrderRule(configRules: List<RulesConfig>) : DiktatRule(
"class-like-structures",
configRules,
listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) {
"class-like-structures",
configRules,
listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS_BODY) {
checkDeclarationsOrderInClass(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
*
*/
class ConsecutiveSpacesRule(configRules: List<RulesConfig>) : DiktatRule(
"too-many-spaces",
configRules,
listOf(TOO_MANY_CONSECUTIVE_SPACES)) {
"too-many-spaces",
configRules,
listOf(TOO_MANY_CONSECUTIVE_SPACES)) {
override fun logic(node: ASTNode) {
val configuration = TooManySpacesRuleConfiguration(
configRules.getRuleConfig(TOO_MANY_CONSECUTIVE_SPACES)?.configuration ?: emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
* Rule that checks if empty code blocks (`{ }`) are used and checks their formatting.
*/
class EmptyBlock(configRules: List<RulesConfig>) : DiktatRule(
"empty-block-structure",
configRules,
listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) {
"empty-block-structure",
configRules,
listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) {
override fun logic(node: ASTNode) {
val configuration = EmptyBlockStyleConfiguration(
configRules.getRuleConfig(EMPTY_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
* Rule that checks enum classes formatting
*/
class EnumsSeparated(configRules: List<RulesConfig>) : DiktatRule(
"enum-separated",
configRules,
listOf(ENUMS_SEPARATED)) {
"enum-separated",
configRules,
listOf(ENUMS_SEPARATED)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY)) {
if (node.isClassEnum()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ import java.net.URL
*/
@Suppress("ForbiddenComment")
class LineLength(configRules: List<RulesConfig>) : DiktatRule(
"line-length",
configRules,
listOf(LONG_LINE)) {
"line-length",
configRules,
listOf(LONG_LINE)) {
private lateinit var positionByOffset: (Int) -> Pair<Int, Int>

override fun logic(node: ASTNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import java.lang.StringBuilder
* Rule that checks if numerical separators (`_`) are used for long numerical literals
*/
class LongNumericalValuesSeparatedRule(configRules: List<RulesConfig>) : DiktatRule(
"long-numerical-values",
configRules,
listOf(LONG_NUMERICAL_VALUES_SEPARATED)) {
"long-numerical-values",
configRules,
listOf(LONG_NUMERICAL_VALUES_SEPARATED)) {
override fun logic(node: ASTNode) {
val configuration = LongNumericalValuesConfiguration(
configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children
* @property configRules
*/
class MultipleModifiersSequence(configRules: List<RulesConfig>) : DiktatRule(
"multiple-modifiers",
configRules,
listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) {
"multiple-modifiers",
configRules,
listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) {
override fun logic(node: ASTNode) {
if (node.elementType == MODIFIER_LIST) {
checkModifierList(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
* Rule that checks if nullable types are used and suggest to substitute them with non-nullable
*/
class NullableTypeRule(configRules: List<RulesConfig>) : DiktatRule(
"nullable-type",
configRules,
listOf(NULLABLE_PROPERTY_TYPE)) {
"nullable-type",
configRules,
listOf(NULLABLE_PROPERTY_TYPE)) {
override fun logic(node: ASTNode) {
if (node.elementType == PROPERTY) {
checkProperty(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
* Rule that looks for multiple statements on a single line separated with a `;` and splits them in multiple lines.
*/
class SingleLineStatementsRule(configRules: List<RulesConfig>) : DiktatRule(
"statement",
configRules,
listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) {
"statement",
configRules,
listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) {
override fun logic(node: ASTNode) {
checkSemicolon(node)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.psi.KtObjectDeclaration
* Rule that sorts class properties and enum members alphabetically
*/
class SortRule(configRules: List<RulesConfig>) : DiktatRule(
"sort-rule",
configRules,
listOf(WRONG_DECLARATIONS_ORDER)) {
"sort-rule",
configRules,
listOf(WRONG_DECLARATIONS_ORDER)) {
override fun logic(node: ASTNode) {
val configuration = SortRuleConfiguration(
configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
* // FixMe: .toString() method and functions that return strings are not supported
*/
class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
"string-concatenation",
configRules,
listOf(STRING_CONCATENATION)) {
"string-concatenation",
configRules,
listOf(STRING_CONCATENATION)) {
override fun logic(node: ASTNode) {
if (node.elementType == BINARY_EXPRESSION) {
// searching top-level binary expression to detect any operations with "plus" (+)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
* FixMe: The important caveat here: in "$foo" kotlin compiler adds implicit call to foo.toString() in case foo type is not string.
*/
class StringTemplateFormatRule(configRules: List<RulesConfig>) : DiktatRule(
"string-template-format",
configRules,
listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) {
"string-template-format",
configRules,
listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
LONG_STRING_TEMPLATE_ENTRY -> handleLongStringTemplate(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
*/
@Suppress("TOO_LONG_FUNCTION")
class TrailingCommaRule(configRules: List<RulesConfig>) : DiktatRule(
"trailing-comma",
configRules,
listOf(TRAILING_COMMA)) {
"trailing-comma",
configRules,
listOf(TRAILING_COMMA)) {
private val commonConfig by configRules.getCommonConfiguration()
private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap()
private val configuration by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import org.jetbrains.kotlin.psi.KtWhenExpression
*/
@Suppress("ForbiddenComment")
class WhenMustHaveElseRule(configRules: List<RulesConfig>) : DiktatRule(
"no-else-in-when",
configRules,
listOf(WHEN_WITHOUT_ELSE)) {
"no-else-in-when",
configRules,
listOf(WHEN_WITHOUT_ELSE)) {
override fun logic(node: ASTNode) {
if (node.elementType == ElementType.WHEN && isStatement(node)) {
checkEntries(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
* 2. Checks that blank lines are not put in the beginning or at the end of code blocks with curly braces
*/
class BlankLinesRule(configRules: List<RulesConfig>) : DiktatRule(
"blank-lines",
configRules,
listOf(TOO_MANY_BLANK_LINES)) {
"blank-lines",
configRules,
listOf(TOO_MANY_BLANK_LINES)) {
override fun logic(node: ASTNode) {
if (node.elementType == WHITE_SPACE) {
// note that no blank lines counts as one newline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import org.slf4j.LoggerFactory
* Rule that checks number of lines in a file
*/
class FileSize(configRules: List<RulesConfig>) : DiktatRule(
"file-size",
configRules,
listOf(FILE_IS_TOO_LONG)) {
"file-size",
configRules,
listOf(FILE_IS_TOO_LONG)) {
private val configuration by lazy {
FileSizeConfiguration(
this.configRules.getRuleConfig(FILE_IS_TOO_LONG)?.configuration ?: emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
* @see CustomIndentationChecker
*/
class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
"indentation",
configRules,
listOf(WRONG_INDENTATION)) {
"indentation",
configRules,
listOf(WRONG_INDENTATION)) {
private val configuration: IndentationConfig by lazy {
IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
*/
@Suppress("ForbiddenComment")
class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
"newlines",
configRules,
listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) {
"newlines",
configRules,
listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) {
private val configuration by lazy {
NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap())
}
Expand Down Expand Up @@ -346,9 +346,9 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
.filter { it.elementType == filterType }
.toList()
.takeIf { it.size > 1 }
?.let {
?.let { list ->
val freeText = if (filterType == VALUE_ARGUMENT) {
warnText.format(it.first().text)
warnText.format(list.first().text)
} else {
warnText
}
Expand All @@ -371,7 +371,7 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
.toList()
.takeIf { it.isNotEmpty() }
?.let { invalidCommas ->
val warnText = if (node.getParentIdentifier() != null) {
val warnText = if (node.getParentIdentifier() ?: false) {
"$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>"
} else {
"$entryType should be placed on different lines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* Rule that checks order in top level
*/
class TopLevelOrderRule(configRules: List<RulesConfig>) : DiktatRule(
"top-level-order",
configRules,
listOf(TOP_LEVEL_ORDER)) {
"top-level-order",
configRules,
listOf(TOP_LEVEL_ORDER)) {
override fun logic(node: ASTNode) {
if (node.elementType == FILE) {
checkNode(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
*/
@Suppress("ForbiddenComment")
class WhiteSpaceRule(configRules: List<RulesConfig>) : DiktatRule(
"horizontal-whitespace",
configRules,
listOf(WRONG_WHITESPACE)) {
"horizontal-whitespace",
configRules,
listOf(WRONG_WHITESPACE)) {
@Suppress("ComplexMethod")
override fun logic(node: ASTNode) {
when (node.elementType) {
Expand Down
Loading

0 comments on commit c4d5b74

Please sign in to comment.