DocC—like many other systems—makes the distinction between "warnings" and "errors" that warnings allow the build continue whereas errors fail the build without doing the remainder of the work and without outputting a "product". In practice, this has led to DocC avoiding error-severity diagnostics, even for issues where content is dropped from the output.
Different people have different opinions about which categories of issues should be considered errors and which shouldn't but the only control that they have for this today is the --warnings-as-errors flag. This raises the severity of all warnings to errors, so unless the developer has fixes all other warnings, they can't use this flag to fend against specific categories of issues.
With SE-0446 (Precise Control Flags over Compiler Warnings), Swift 6.1 gained two new -Werror <group> and -Wwarning <group> flags to control allow for precise control of the severity of individual groups of warnings/diagnostics. I propose that we do the same for DocC.
Proposed solution
Add two new --Werror and --Wwarning flags to DocC to control the severity of groups of diagnostics or individual diagnostics. For example, you can raise the severity of 2 diagnostics using:
--Werror UnresolvedLink --Werror MultipleTopicsSections
Similarly, you can raise all warnings to error-severity except a select few using:
--warnings-as-errors --Wwarning UnresolvedLink --Wwarning MultipleTopicsSections
Add a new --print-diagnostic-groups / --no-print-diagnostic-groups flag that controls whether or not DocC includes the diagnostic group identifier after the message in the console output. In the default diagnostic output format (aimed at humans) this behavior would be enabled by default a means for developers to discover which identifiers relate to which warnings. For example:
warning: 'someMethod()' is ambiguous at '/ModuleName/SomeStruct' [UnresolvedLink]
--> Sources/ModuleName/SomeFile.swift:2:28-2:40
1 |
2 + /// An ambiguous link to ``someMethod()``
| ├─suggestion: Insert '->Int' for 'func someMethod() -> Int'
| ╰─suggestion: Insert '->String' for 'func someMethod() -> String'
3 | public struct SomeStruct {
In the diagnostic format intended for tools (configured via the --ide-console-output flag), diagnostic group identifier wouldn't be enabled by default so as to not impact any parsing logic of existing tools.
Note: the recommended ways for tools to consume diagnostic information is via the JSON file that DocC outputs to the specified
--diagnostics-file <file-path>location.
Organize conceptually related diagnostics into broader groups that developers might want to control the severity of as a group. For example, DocC today uses different diagnostic IDs for issues about missing required directive parameters, extra unknown directive parameters, and incorrect values for directive parameters. It makes more sense to control the severity of these warnings as a single hypothetical "DirectiveParameterValidation" group (although that group ID spelling isn't finalized).
A draft PR that starts to implement this is available at swift-docc PR #1347.
Tools and scripts who make calls to DocC can check for the support for these flags by checking for the "precise-diagnostic-severity-control" feature in DocC's features.json file in the toolchain.
Future directions
In addition to these command line flags we could allow developers to configure specific diagnostic severities in their documentation catalog's (.docc directory) optional Info.plist file. For example, we could add two hypothetical <WarningsAsErrors> and <ErrorsAsWarnings> keys, each with their own list of string values representing individual diagnostic group identifiers.
Alternatives considered
The proposes spellings of the new flags are based on their Swift spellings with a two dash prefix instead of a single dash prefix. The idea is that developers would already be familiar with these spellings.
Alternatively, we could use a single dash prefix to be consistent with Swift (but inconsistent with DocC's other flags: -Werror and -Wwarning
Alternatively, we could use full spelled out singular-noun-phrases (warning instead of warnings) to control the severity of individual diagnostics: --warning-as-error to raise the severity and either --error-as-warning or --no-warning-as-error to lower the severity.