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

Added documentation for property tag usage in KDocs #559

Merged
merged 4 commits into from
Nov 27, 2020
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
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
petertrr marked this conversation as resolved.
Show resolved Hide resolved
*/
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