Skip to content

Commit

Permalink
Correct the (sometimes meaningless) message in the `COMMENT_WHITE_SPA…
Browse files Browse the repository at this point in the history
…CE` check

### What's done:

 * Now, the amount of space characters is correctly reported as either
   "too many" or "too few".
  • Loading branch information
0x6675636b796f75676974687562 committed Jul 21, 2022
1 parent a67811d commit 8425b60
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,14 @@ class CommentsFormatting(configRules: List<RulesConfig>) : DiktatRule(
node.treeParent.addChild(PsiWhiteSpaceImpl(" ".repeat(configuration.maxSpacesBeforeComment)), node)
}
} else if (!node.treePrev.textContains('\n') && node.treePrev.text.length != configuration.maxSpacesBeforeComment) {
// if there are too many spaces before comment
// if there are too many or too few spaces before comment
val manyOrFew = when {
node.treePrev.text.length > configuration.maxSpacesBeforeComment -> "many"
else -> "few"
}
val message = "There should be ${configuration.maxSpacesBeforeComment} space(s) before comment text, but there are too $manyOrFew in ${node.text}"
COMMENT_WHITE_SPACE.warnAndFix(configRules, emitWarn, isFixMode,
"There should be ${configuration.maxSpacesBeforeComment} space(s) before comment text, but there are too many in ${node.text}", node.startOffset, node) {
message, node.startOffset, node) {
(node.treePrev as LeafPsiElement).rawReplaceWithText(" ".repeat(configuration.maxSpacesBeforeComment))
}
}
Expand Down

0 comments on commit 8425b60

Please sign in to comment.