Skip to content

Commit ada632c

Browse files
committed
[docs] Diagnostics: Add quoting guidelines
1 parent 17032b6 commit ada632c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

docs/Diagnostics.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,23 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
3838

3939
- When applicable, phrase diagnostics as rules rather than reporting that the compiler failed to do something. Example:
4040

41-
- Normal: "cannot call 'super.init' outside of an initializer"
42-
- Better: "'super.init' cannot be called outside of an initializer"
41+
- Normal: `cannot call 'super.init' outside of an initializer`
42+
- Better: `'super.init' cannot be called outside of an initializer`
43+
44+
- Use `'` to quote attributes, symbol names, and any other text that is
45+
referred to as code or a token.
46+
Some idiomatic Swift tokens, such as `protocol`, by themselves are or appear
47+
in Swift terms of art.
48+
Terms of art are written in plain text and must not be quoted.
49+
If you are not certain whether a Swift token has an associated term of art,
50+
consult the [book].
51+
For example:
52+
- `'mutating' is only valid on methods`, but
53+
`cannot call mutating method on immutable value`.
54+
- `'@autoclosure' only applies to function types`.
55+
- `subscript access can throw but is not marked with 'try'`.
56+
- `expected '{' after 'defer'`.
57+
- `type 'S' does not conform to protocol 'Sequence'`.
4358

4459
- When referring to attributes by name, use *either* `attribute 'foo'` or
4560
`'@foo'`, rather than `attribute '@foo'`.
@@ -54,6 +69,8 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
5469

5570
- If possible, it is best to include the name of the type or function that has the error, e.g. "non-actor type 'Nope' cannot ..." is better than "non-actor type cannot ...". It helps developers relate the error message to the specific type the error is about, even if the error would highlight the appropriate line / function in other ways.
5671

72+
[book]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language
73+
5774
### Locations and Highlights ###
5875

5976
- Diagnostics are always emitted at a particular line and column. Try to be specific.

0 commit comments

Comments
 (0)