A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://docs.scala-lang.org/scala3/guides/scaladoc/docstrings.html below:

Docstrings - specific Tags and Features | Scaladoc

This doc page is specific to Scala 3, and may cover new concepts not available in Scala 2. Unless otherwise stated, all the code examples in this page assume you are using Scala 3.

This chapter describes how to correctly write docstrings and how to use all the available features of scaladoc. Since many things are the same as in the old scaladoc, some parts are reused from this article

Scaladoc extends Markdown with additional features, such as linking to API definitions. This can be used from within static documentation and blog posts to provide blend-in content.

Where to put docstrings

Scaladoc comments go before the items they pertain to in a special comment block that starts with a /** and ends with a */, like this:

/** Start the comment here
  * and use the left star followed by a
  * white space on every line.
  *
  * Even on empty paragraph-break lines.
  *
  * Note that the * on each line is aligned
  * with the second * in /** so that the
  * left margin is on the same column on the
  * first line and on subsequent ones.
  *
  * Close the comment with *\/
  *
  * If you use Scaladoc tags (@param, @group, etc.),
  * remember to put them at separate lines with nothing preceding.
  *
  * For example:
  *
  * Calculate the square of the given number
  *
  * @param d the Double to square
  * @return the result of squaring d
  */
 def square(d: Double): Double = d * d

In the example above, this Scaladoc comment is associated with the method square since it is right before it in the source code.

Scaladoc comments can go before fields, methods, classes, traits, objects. For now, scaladoc doesn’t support straightforward solution to document packages. There is a dedicated github issue, where you can check the current status of the problem.

For class primary constructors which in Scala coincide with the definition of the class itself, a @constructor tag is used to target a comment to be put on the primary constructor documentation rather than the class overview.

Scaladoc uses @<tagname> tags to provide specific detail fields in the comments. These include:

Class specific tags Method specific tags Method, Constructor and/or Class tags Usage tags Member grouping tags

These tags are well-suited to larger types or packages, with many members. They allow you to organize the Scaladoc page into distinct sections, with each one shown separately, in the order that you choose.

These tags are not enabled by default! You must pass the -groups flag to Scaladoc in order to turn them on. Typically the sbt for this will look something like:

Compile / doc / scalacOptions ++= Seq(
  "-groups"
)

Each section should have a single-word identifier that is used in all of these tags, shown as group below. By default, that identifier is shown as the title of that documentation section, but you can use @groupname to provide a longer title.

Typically, you should put @groupprio (and optionally @groupname and @groupdesc) in the Scaladoc for the package/trait/class/object itself, describing what all the groups are, and their order. Then put @group in the Scaladoc for each member, saying which group it is in.

Members that do not have a @group tag will be listed as “Ungrouped” in the resulting documentation.

Other tags Macros

If a comment is not provided for an entity at the current inheritance level, but is supplied for the overridden entity at a higher level in the inheritance hierarchy, the comment from the super-class will be used.

Likewise if @param, @tparam, @return and other entity tags are omitted but available from a superclass, those comments will be used.

Explicit

For explicit comment inheritance, use the @inheritdoc tag.

Markup

Scaladoc provides two syntax parsers: markdown (default) or wikidoc. It is still possible to embed HTML tags in Scaladoc (like with Javadoc), but not necessary most of the time as markup may be used instead.

Markdown

Markdown uses commonmark flavour with two custom extensions:

Wikidoc

Wikidoc is syntax used for scala2 scaladoc. It is supported because of many existing source code, however it is not recommended to use it in new projects. Wikisyntax can be toggled on with flag -comment-syntax wiki globally, or with @syntax wiki directive in docstring.

Some of the standard markup available:

`monospace`
''italic text''
'''bold text'''
__underline__
^superscript^
,,subscript,,
[[entity link]], e.g. [[scala.collection.Seq]]
[[https://external.link External Link]], e.g. [[https://scala-lang.org Scala Language Site]]

For more info about wiki links look at this chapter

Other formatting notes

The markup for list blocks looks like:

/** Here is an unordered list:
  *
  *   - First item
  *   - Second item
  *     - Sub-item to the second
  *     - Another sub-item
  *   - Third item
  *
  * Here is an ordered list:
  *
  *   1. First numbered item
  *   1. Second numbered item
  *     i. Sub-item to the second
  *     i. Another sub-item
  *   1. Third item
  */

Concise is nice! Get to the point quickly, people have limited time to spend on your documentation, use it wisely. Omit unnecessary words. Prefer returns X rather than this method returns X, and does X,Y & Z rather than this method does X, Y and Z. DRY - don’t repeat yourself. Resist duplicating the method description in the @return tag and other forms of repetitive commenting.

More details on writing Scaladoc

Further information on the formatting and style recommendations can be found in Scala-lang scaladoc style guide.

Linking to API

Scaladoc allows linking to API documentation with Wiki-style links. Linking to scala.collection.immutable.List is as simple as [[scala.collection.immutable.List]]. For more information on the exact syntax, see doc comment documentation.

Contributors to this page:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4