Skip to content

Commit

Permalink
Fixed KdocComments (#1754)
Browse files Browse the repository at this point in the history
### What's done:
- Changed warning `KDOC_NO_CONSTRUCTOR_PROPERTY` to `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` in some cases when property or parameter has comment before.
- Added check is warning `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` fixable for case when property or parameter has any tags in KDoc-comment before. If it has = non-fixed.
- Added configuration for `@param` tags creation: `isParamTagsForParameters` and `isParamTagsForPrivateProperties`.
- Added fixed warnings `KDOC_NO_CONSTRUCTOR_PROPERTY` and `KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT` for cases when configuration options are on, and then `private` properties and parameters must have `@param` tags in class-KDoc. Additionally added logic for replacing incorrect tag with correct one regardless of whether configuration is enabled or not.
- Added non-fixed warning `KDOC_EXTRA_PROPERTY` for redundant `@param` tags in class-KDoc.
- Reworked fix tests. Added tests for cases when `@property` or `@param` tag exist in class-KDoc.
- Added new warning tests.

It's part of #1737
  • Loading branch information
DrAlexD authored Oct 16, 2023
1 parent e0fb721 commit 71c81d4
Show file tree
Hide file tree
Showing 32 changed files with 2,346 additions and 434 deletions.
3 changes: 3 additions & 0 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@
# Checks that property in constructor doesn't contain comment
- name: KDOC_NO_CONSTRUCTOR_PROPERTY
enabled: true
configuration:
isParamTagsForParameters: false # create param tags for parameters without val or var
isParamTagsForPrivateProperties: false # create param tags for private properties
# Checks that property in KDoc present in class
- name: KDOC_EXTRA_PROPERTY
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ private typealias RunAction = (DiktatProcessor, DiktatProcessorListener) -> Unit
/**
* A runner for diktat on bunch of files using baseline and reporter
*
* @param diktatBaselineGenerator
* @property diktatProcessor
* @property diktatBaseline
* @property diktatBaselineGenerator
* @property diktatReporter
*/
data class DiktatRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import com.saveourtool.diktat.api.DiktatBaselineFactory
import com.saveourtool.diktat.api.DiktatProcessorListener
import com.saveourtool.diktat.api.DiktatReporter
import com.saveourtool.diktat.api.DiktatReporterFactory
import com.saveourtool.diktat.api.DiktatRuleConfig
import com.saveourtool.diktat.api.DiktatRuleConfigReader
import com.saveourtool.diktat.api.DiktatRuleSet
import com.saveourtool.diktat.api.DiktatRuleSetFactory
import java.io.OutputStream
import java.nio.file.Path

/**
* A factory to create [DiktatRunner]
*
* @param diktatRuleConfigReader a reader for [DiktatRuleConfig]
* @param diktatRuleSetFactory a factory for [DiktatRuleSet]
* @param diktatProcessorFactory a factory for [DiktatProcessor]
* @param diktatBaselineFactory a factory for [DiktatBaseline]
* @property diktatReporterFactory a factory for [DiktatReporter]
*/
class DiktatRunnerFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import kotlinx.cli.default
import kotlinx.cli.vararg

/**
* @param groupByFileInPlain
* @param colorNameInPlain
* @param logLevel
* @property config path to `diktat-analysis.yml`
* @property mode mode of `diktat`
* @property reporterProviderId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import kotlinx.serialization.Serializable
/**
* This class is used to serialize/deserialize json representation
* that is used to store command line arguments
* @property shortName short argument representation like -h
* @property longName long argument representation like --help
* @property hasArgs indicates if option should have explicit argument
*
* @param shortName short argument representation like -h
* @param helpDescr
* @param longName long argument representation like --help
* @param hasArgs indicates if option should have explicit argument
* @param isRequired
*/
@Serializable
data class CliArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration

/**
* [SymbolProcessor] to generate a class with contacts for names from provided enum
*
* @param codeGenerator
*/
class EnumNamesSymbolProcessor(
private val codeGenerator: CodeGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import java.io.File

/**
* An extension to configure diktat in build.gradle(.kts) file
*
* @param patternSet
*/
open class DiktatExtension(
private val patternSet: PatternSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import java.nio.file.Path

/**
* A base task to run `diktat`
*
* @param inputs
* @property extension
*/
@Suppress("WRONG_NEWLINES", "Deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import java.nio.file.Path

/**
* [DiktatReporter] using __KtLint__
*
* @param ktLintReporter
* @param sourceRootDir
*/
class DiktatReporterImpl(
private val ktLintReporter: ReporterV2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
/**
* This class represent individual inspections of diktat code style.
* A [Warnings] entry contains rule name, warning message and is used in code check.
*
* @param warn description of the inspection
* @property canBeAutoCorrected whether this inspection can automatically fix the code. Should be public to be able to use it in docs generator.
* @property ruleId number of the inspection according to [diktat code style](https://github.com/saveourtool/diktat/blob/master/info/guide/diktat-coding-convention.md)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ private typealias DiktatRuleApi = com.saveourtool.diktat.api.DiktatRule
/**
* This is a wrapper around _KtLint_ `com.pinterest.ktlint.core.Rule`.
*
* @param inspections warnings that are used in the rule's code
* @property id id of the rule
* @property configRules all rules from configuration
* @property inspections warnings that are used in the rule's code
*/
@Suppress("TooGenericExceptionCaught")
abstract class DiktatRule(
Expand Down
Loading

0 comments on commit 71c81d4

Please sign in to comment.