Support a custom severity in the banned syntax entries of MA0240
Merged
ME
2mo ago+383+383+012345678901234567890123456789-22-22-01234567890123456789
What
The entries of a BannedSyntaxes.txt file (MA0240) now accept an optional severity:
query
query;message
query;severity;message
query;severity;
The severities are the names of the dotnet_diagnostic.<id>.severity option, and they are case-insensitive:
| Severity | Effect |
|---|---|
error | Reported as an error |
warning | Reported as a warning. This is the default |
suggestion / info | Reported as a suggestion |
silent / hidden | Reported as a hidden diagnostic |
none | The entry reports nothing. Its query is still validated by MA0241 |
Why
An entry could only report a warning, so a file could not ban some syntax as an error while reporting the rest as a warning or as a suggestion. none also makes it possible to turn off an entry that comes from a BannedSyntaxes.txt shared by several projects, without editing the shared file.
Notes for the reviewer
- A
DiagnosticDescriptorcarries a single severity, so there is now one descriptor per severity sharing theMA0240id, all listed inSupportedDiagnostics. The warning one is first, so it stays the default severity of the rule and the markup-based tests (MarkupOptions.UseFirstDescriptor) keep resolving to it. - Setting
dotnet_diagnostic.MA0240.severityin an.editorconfigfile still overrides the severity of all the entries, as this option is about the whole rule. This is documented. - A message can contain a
;, so a line only has a severity when the field between the two separators is a single word made of letters.GotoStatement; Do not use goto; use a loopis therefore still a plain message. A single word that is not a known severity, such asGotoStatement;Avoid;it is not readable, is reported by MA0241 ('Avoid' is not a valid severity), so a typo does not silently change the message. - An entry whose severity is
noneis still parsed and validated, so an invalid query in it is reported by MA0241.
Tests
16 new tests. The full test project passes (4887/4887) on Roslyn 5.9, and the MA0240 tests pass (90/90) on Roslyn 4.8, 4.14, 5.0 and 5.6. dotnet run --project src/DocumentationGenerator reports no further changes.