Skip to content

Commit 205ec03

Browse files
committed
Document limitations in comments on the formatter
See #13736.
1 parent a3a3210 commit 205ec03

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/elixir/lib/code.ex

+15-6
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,8 @@ defmodule Code do
932932
933933
## Code comments
934934
935-
The formatter also handles code comments in a way to guarantee a space
936-
is always added between the beginning of the comment (#) and the next
937-
character.
935+
The formatter handles code comments and guarantees a space is always added
936+
between the beginning of the comment (#) and the next character.
938937
939938
The formatter also extracts all trailing comments to their previous line.
940939
For example, the code below
@@ -946,9 +945,19 @@ defmodule Code do
946945
# world
947946
hello
948947
949-
Because code comments are handled apart from the code representation (AST),
950-
there are some situations where code comments are seen as ambiguous by the
951-
code formatter. For example, the comment in the anonymous function below
948+
While the formatter attempts to preserve comments in most situations,
949+
that's not always possible, because code comments are handled apart from
950+
the code representation (AST). While the formatter can preserve code
951+
comments between expressions and function arguments, the formatter
952+
cannot currently preserve them around operators. For example, the following
953+
code will move the code comments to before the operator usage:
954+
955+
foo() ||
956+
# also check for bar
957+
bar()
958+
959+
In some situations, code comments can be seen as ambiguous by the formatter.
960+
For example, the comment in the anonymous function below
952961
953962
fn
954963
arg1 ->

0 commit comments

Comments
 (0)