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

Bugfix. Sanitize diktat config(#737) #759

Merged
merged 3 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
# If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines.
maxParametersInOneLine: 2
# 3 by default.
# maxCallsInOneLine: 3
maxCallsInOneLine: 3
# Checks trailing comma
- name: TRAILING_COMMA
enabled: true
Expand Down Expand Up @@ -323,7 +323,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
2 changes: 1 addition & 1 deletion diktat-rules/src/main/kotlin/generated/WarningNames.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public object WarningNames {

public const val WRONG_NEWLINES_AROUND_KDOC: String = "WRONG_NEWLINES_AROUND_KDOC"

public const val FIRST_COMMENT_NO_SPACES: String = "FIRST_COMMENT_NO_SPACES"
public const val FIRST_COMMENT_NO_BLANK_LINE: String = "FIRST_COMMENT_NO_BLANK_LINE"

public const val COMMENT_WHITE_SPACE: String = "COMMENT_WHITE_SPACE"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum class Warnings(
HEADER_NOT_BEFORE_PACKAGE(true, "2.2.1", "header KDoc should be placed before package and imports"),
COMMENTED_OUT_CODE(false, "2.4.2", "you should not comment out code, use VCS to save it in history and delete this block"),
WRONG_NEWLINES_AROUND_KDOC(true, "2.4.1", "there should be a blank line above the kDoc and there should not be no blank lines after kDoc"),
FIRST_COMMENT_NO_SPACES(true, "2.4.1", "there should not be any spaces before first comment"),
FIRST_COMMENT_NO_BLANK_LINE(true, "2.4.1", "there should not be any blank lines before first comment"),
Copy link
Member

Choose a reason for hiding this comment

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

What does it check once again? Is this a first comment in the file? How is this different from blank lines rule?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It checks that first comment starts with new line. BlankLinesRule handles blank lines in blocks before/after braces. Seems like blank lines before first comment have more complicated logic.

Copy link
Member

Choose a reason for hiding this comment

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

ok then

COMMENT_WHITE_SPACE(true, "2.4.1", "there should be a white space between code and comment also between code start token and comment text"),
IF_ELSE_COMMENTS(true, "2.4.1", "invalid comments structure. Comment should be inside the block"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.cqfn.diktat.common.config.rules.RuleConfiguration
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.getRuleConfig
import org.cqfn.diktat.ruleset.constants.Warnings.COMMENT_WHITE_SPACE
import org.cqfn.diktat.ruleset.constants.Warnings.FIRST_COMMENT_NO_SPACES
import org.cqfn.diktat.ruleset.constants.Warnings.FIRST_COMMENT_NO_BLANK_LINE
import org.cqfn.diktat.ruleset.constants.Warnings.IF_ELSE_COMMENTS
import org.cqfn.diktat.ruleset.constants.Warnings.WRONG_NEWLINES_AROUND_KDOC
import org.cqfn.diktat.ruleset.rules.DiktatRule
Expand Down Expand Up @@ -50,7 +50,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
* * Comments in if else should be inside code blocks. Exception: General if comment
*/
class CommentsFormatting(configRules: List<RulesConfig>) : DiktatRule("kdoc-comments-codeblocks-formatting", configRules,
listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_SPACES,
listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_BLANK_LINE,
IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC)) {
/**
* @param node
Expand Down Expand Up @@ -313,7 +313,7 @@ class CommentsFormatting(configRules: List<RulesConfig>) : DiktatRule("kdoc-comm
if (node.treePrev.isWhiteSpace()) {
if (node.treePrev.numNewLines() > 1 ||
node.treePrev.numNewLines() == 0) {
FIRST_COMMENT_NO_SPACES.warnAndFix(configRules, emitWarn, isFixMode, node.text, node.startOffset, node) {
FIRST_COMMENT_NO_BLANK_LINE.warnAndFix(configRules, emitWarn, isFixMode, node.text, node.startOffset, node) {
(node.treePrev as LeafPsiElement).replaceWithText("\n")
}
}
Expand Down
4 changes: 2 additions & 2 deletions diktat-rules/src/main/resources/diktat-analysis-huawei.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
# If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines.
maxParametersInOneLine: 2
# 3 by default.
# maxCallsInOneLine: 3
maxCallsInOneLine: 3
# Checks trailing comma
- name: TRAILING_COMMA
enabled: true
Expand Down Expand Up @@ -323,7 +323,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
4 changes: 2 additions & 2 deletions diktat-rules/src/main/resources/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
# If the number of parameters on one line is more than this threshold, all parameters will be placed on separate lines.
maxParametersInOneLine: 2
# 3 by default.
# maxCallsInOneLine: 3
maxCallsInOneLine: 3
# Checks trailing comma
- name: TRAILING_COMMA
enabled: true
Expand Down Expand Up @@ -319,7 +319,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.cqfn.diktat.ruleset.rules.chapter2.kdoc.CommentsFormatting
import org.cqfn.diktat.util.FixTestBase

import generated.WarningNames.COMMENT_WHITE_SPACE
import generated.WarningNames.FIRST_COMMENT_NO_SPACES
import generated.WarningNames.FIRST_COMMENT_NO_BLANK_LINE
import generated.WarningNames.IF_ELSE_COMMENTS
import generated.WarningNames.WRONG_NEWLINES_AROUND_KDOC
import org.junit.jupiter.api.Tag
Expand All @@ -19,13 +19,13 @@ class CommentsFormattingFixTest : FixTestBase("test/paragraph2/kdoc/", ::Comment
}

@Test
@Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(COMMENT_WHITE_SPACE), Tag(IF_ELSE_COMMENTS), Tag(FIRST_COMMENT_NO_SPACES))
@Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(COMMENT_WHITE_SPACE), Tag(IF_ELSE_COMMENTS), Tag(FIRST_COMMENT_NO_BLANK_LINE))
fun `check lines and spaces in comments`() {
fixAndCompare("KdocCodeBlocksFormattingExpected.kt", "KdocCodeBlocksFormattingTest.kt")
}

@Test
@Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(FIRST_COMMENT_NO_SPACES))
@Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(FIRST_COMMENT_NO_BLANK_LINE))
fun `test example from code style`() {
fixAndCompare("KdocCodeBlockFormattingExampleExpected.kt", "KdocCodeBlockFormattingExampleTest.kt")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class CommentsFormattingTest : LintTestBase(::CommentsFormatting) {
}

@Test
@Tag(WarningNames.FIRST_COMMENT_NO_SPACES)
@Tag(WarningNames.FIRST_COMMENT_NO_BLANK_LINE)
fun `first comment no space in if - else bad`() {
val code =
"""
Expand All @@ -438,7 +438,7 @@ class CommentsFormattingTest : LintTestBase(::CommentsFormatting) {
""".trimMargin()

lintMethod(code,
LintError(8, 18, ruleId, "${Warnings.FIRST_COMMENT_NO_SPACES.warnText()} // Bad Comment ", true))
LintError(8, 18, ruleId, "${Warnings.FIRST_COMMENT_NO_BLANK_LINE.warnText()} // Bad Comment ", true))
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-groovy-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-kotlin-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
2 changes: 1 addition & 1 deletion examples/maven/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
- name: WRONG_NEWLINES_AROUND_KDOC
enabled: true
# Inspection that checks if there is no blank lines before first comment
- name: FIRST_COMMENT_NO_SPACES
- name: FIRST_COMMENT_NO_BLANK_LINE
enabled: true
# Inspection that checks if there are blank lines between code and comment and between code start token and comment's text
- name: COMMENT_WHITE_SPACE
Expand Down
2 changes: 1 addition & 1 deletion info/available-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
| 2 | 2.4.2 | COMMENTED_OUT_CODE | Check: warns if commented code is detected (when un-commented, can be parsed) | no | no | Offset is lost when joined EOL comments are split again|
| 2 | 2.4.1 | COMMENT_WHITE_SPACE | Check: warns if there is no space between // and comment, if there is no space between code and comment <br>Fix: adds a white space | yes | maxSpaces | - |
| 2 | 2.4.1 | WRONG_NEWLINES_AROUND_KDOC | Check: warns if there is no new line above and under comment. Exception first comment<br>Fix: adds a new line | yes | no | - |
| 2 | 2.4.1 | FIRST_COMMENT_NO_SPACES | Check: warns if there is a new line before first comment<br>Fix: deletes a new line | yes | no | - |
| 2 | 2.4.1 | FIRST_COMMENT_NO_BLANK_LINE | Check: warns if there is a new line before first comment<br>Fix: deletes a new line | yes | no | - |
| 2 | 2.4.1 | IF_ELSE_COMMENTS | Check: warns if there is a comment not in the else block<br>Fix: adds the comment to the first line in else block | yes | no | - |
| 2 | 2.2.1 | HEADER_NOT_BEFORE_PACKAGE | Check: warns if header KDoc if file is located not before package directive<br>Fix: moves this KDoc | yes | no | |
| 3 | 3.1.1 | FILE_IS_TOO_LONG | Check: warns if file has too many lines<br>Fix: no | no | maxSize<br> ignoreFolders | - |
Expand Down
2 changes: 1 addition & 1 deletion info/rules-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
| HEADER_NOT_BEFORE_PACKAGE | [2.2.1](guide/diktat-coding-convention.md#r2.2.1) | yes | Comments |
| KDOC_TRIVIAL_KDOC_ON_FUNCTION | [2.3.1](guide/diktat-coding-convention.md#r2.3.1) | no | Comments |
| WRONG_NEWLINES_AROUND_KDOC | [2.4.1](guide/diktat-coding-convention.md#r2.4.1) | yes | Comments |
| FIRST_COMMENT_NO_SPACES | [2.4.1](guide/diktat-coding-convention.md#r2.4.1) | yes | Comments |
| FIRST_COMMENT_NO_BLANK_LINE | [2.4.1](guide/diktat-coding-convention.md#r2.4.1) | yes | Comments |
| COMMENT_WHITE_SPACE | [2.4.1](guide/diktat-coding-convention.md#r2.4.1) | yes | Comments |
| IF_ELSE_COMMENTS | [2.4.1](guide/diktat-coding-convention.md#r2.4.1) | yes | Comments |
| COMMENTED_OUT_CODE | [2.4.2](guide/diktat-coding-convention.md#r2.4.2) | no | Comments |
Expand Down