Add API Analyzer Assembly (#906)
* Start on API analyzers * Finish GuildAccessAnalyzer * Update build script (will this do?) * Correct slashes * Extrapolate DerivesFromModuleBase() to an extension method * Quick refactoring * Add doc file
This commit is contained in:
30
src/Discord.Net.Analyzers/docs/DNET0001.md
Normal file
30
src/Discord.Net.Analyzers/docs/DNET0001.md
Normal 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.
|
||||
Reference in New Issue
Block a user