HOCON supports multiple comment styles, giving flexibility in how do you document your settings.
Comments are sentences in Hocon configuration that allow users to read and understand the configuration better. Comments help to understand the configuration better and provide context to updates or add extra configuration.
Let’s see How to write comments in multiple ways.
- Single Line Comments
Single Line comments always start with
#
or double slashes//
,All the text followed by
#
or//
are comments, and ignored.These comments are in new lines or inline
Hash Comments (#) The simple and easy to document any line in configuration using
#
symbol
# This is a single-line comment
database {
host = "localhost" # Inline comment briefs about database host
port = 5432
}
- Double Slash Comments (//)
// This is a single-line valid comment
database {
host = "localhost" // Inline comment briefs about database host
port = 5432
}
- Multi-Line Comments
There are no multi-line comments supported, But you can prefix #
or //
on a new line.
Commented lines do spans in multiple lines.
# Multi-line comment example
# Another multiple line
database = "mysql"
- Inline Comments
Inline comments are placed at the end of a line. There is a space between value and comment syntax.
database = "mysql" # Inline comment
- Block Comments:
There is no support for block comments syntax.
Comments are helpful for users to improve readability, but programs or parsers ignore the comment's text.
The below example shows all single, multi, and inline comment examples
# Single line comment
// Another way to write a Single line comment
database = "mysql" # Inline comment
# This is a multi-line comment
# that spans multiple lines
appname = "myapp"
# Comment actual key and pairs
# hostname = "localhost"
ssl = "true" # Inline comment
Tools for Working with HOCON Comments
Most of editors and IDE’s help you work more effectively with commented these configurations.
IDE plugins: Most modern IDE’s provides either inbuilt support or plugins that provides synax highlighting for comments
Linter tools: These tools does validation hocon syntx, while preserving comments.
Documentation Generators: Tools that generates documentation from this configuration files