Skip to content

Code Style and Formatting

Ryan Suzuki edited this page Mar 25, 2022 · 2 revisions

Linting & Style Guide

To run Spotless's gradle tasks, navigate to the root directory of the project first: (Note: the syntax may be slightly different depending on your environment)

  1. To run/validate the project: ./gradlew spotlessCheck
  2. To automatically apply all non-error linting: ./gradlew spotlessApply

This project defers to many of the default configurations of Spotless for linting and styling, but also adheres to Google's Android coding standards as well.

KDoc Annotations

kdoc annotations are very similar to javadoc annotations.

  • @param name Documents a value parameter of a function or a type parameter of a class, property or function. Two acceptable syntaxes are: @param name description or @param[name] description

  • @return provides a description of what a method will or can return

  • @constructor primary constructor of a class

  • @receiver the receiver of an extension function

  • @property name Documents the property of a class which has the specified name. This tag can be used for documenting properties declared in the primary constructor, where putting a doc comment directly before the property definition would be awkward.

  • @throws class, @exception class Documents an exception which can be thrown by a method. Since Kotlin does not have checked exceptions, there is also no expectation that all possible exceptions are documented, but you can still use this tag when it provides useful information for users of the class.

  • @sample identifier Embeds the body of the function with the specified qualified name into the documentation for the current element, in order to show an example of how the element could be used.

  • @see identifier will generate a link similar to the {@link} tag, but more in the context of a reference and not inline

  • @author author of the relevant document

  • @since specifies which version the class, field, or method was added to the project

  • @Deprecated gives an explanation of why code was deprecated, when it may have been deprecated, and what the alternatives are

  • @suppress Excludes the element from the generated documentation. Can be used for elements which are not part of the official API of a module but still have to be visible externally.

  • dokka

  • kdoc syntax

To manually generate a new version of the library's documentation, simply navigate to the root directory of the project and run: ./gradlew dokkaHtml

Clone this wiki locally