Skip to content

Commit

Permalink
Added documentation for property tag usage in KDocs (#559)
Browse files Browse the repository at this point in the history
### What's done:
* Updated documentation
  • Loading branch information
petertrr authored Nov 27, 2020
1 parent 07829e0 commit 9cd02d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repositories {
jcenter()
}

// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.1.5"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.7.0") as String
Expand Down
35 changes: 32 additions & 3 deletions info/guide/guide-chapter-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,39 @@ Use a single-line form when you store the entire KDoc block in one line (and the

### <a name="r2.1.1"></a> Rule 2.1.1: KDoc is used for each public, protected or internal code element

At a minimum, KDoc should be used for every public, protected, or internal decorated class, interface, enumeration, method, and member field (property). Other code blocks can also have KDocs if needed.
Instead of using comments before properties in class - use `@property` tag in a KDoc of a class.
At a minimum, KDoc should be used for every public, protected, or internal decorated class, interface, enumeration, method, and member field (property).
Other code blocks can also have KDocs if needed.
Instead of using comments or KDocs before properties in the primary constructor of a class - use `@property` tag in a KDoc of a class.
All properties of the primary constructor should be also documented in a KDoc with a `@property` tag.

Incorrect example:
```kotlin
/**
* Class description
*/
class Example(
/**
* property description
*/
val foo: Foo,
// another property description
val bar: Bar
)
```

Correct example:
```kotlin
/**
* Class description
* @property foo property description
* @property bar another property description
*/
class Example(
val foo: Foo,
val bar: Bar
)
```

**Exceptions:**

1. For setters/getters of properties, obvious comments (like `this getter returns field`) are optional. Note, that Kotlin generates simple `get/set` methods under the hood.
Expand Down Expand Up @@ -125,7 +154,7 @@ This comment should contain @since tag. The right style is to write the applicat
*/
```

Other KDoc tags (such as @param type parameters and @see.) can be added as follow:
Other KDoc tags (such as @param type parameters and @see.) can be added as follows:
```kotlin
/**
* Description of functionality
Expand Down

0 comments on commit 9cd02d7

Please sign in to comment.