Browse Source

Add doc file

pull/906/head
Joe4evr 7 years ago
parent
commit
e0a96cd117
2 changed files with 31 additions and 1 deletions
  1. +1
    -1
      src/Discord.Net.Analyzers/GuildAccessAnalyzer.cs
  2. +30
    -0
      src/Discord.Net.Analyzers/docs/DNET0001.md

+ 1
- 1
src/Discord.Net.Analyzers/GuildAccessAnalyzer.cs View File

@@ -16,7 +16,7 @@ namespace Discord.Analyzers
private const string Title = "Limit command to Guild contexts.";
private const string MessageFormat = "Command method '{0}' is accessing 'Context.Guild' but is not restricted to Guild contexts.";
private const string Description = "Accessing 'Context.Guild' in a command without limiting the command to run only in guilds.";
private const string Category = "Design";
private const string Category = "API Usage";

private static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);



+ 30
- 0
src/Discord.Net.Analyzers/docs/DNET0001.md View File

@@ -0,0 +1,30 @@
# DNET0001

<table>
<tr>
<td>TypeName</td>
<td>GuildAccessAnalyzer</td>
</tr>
<tr>
<td>CheckId</td>
<td>DNET0001</td>
</tr>
<tr>
<td>Category</td>
<td>API Usage</td>
</tr>
</table>

## Cause

A method identified as a command is accessing `Context.Guild` without the requisite precondition.

## Rule description

The value of `Context.Guild` is `null` if a command is invoked in a DM channel. Attempting to access
guild properties in such a case will result in a `NullReferenceException` at runtime.
This exception is entirely avoidable by using the library's provided preconditions.

## How to fix violations

Add the precondition `[RequireContext(ContextType.Guild)]` to the command or module class.

Loading…
Cancel
Save