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:
Joe4evr
2018-01-14 04:54:47 +01:00
committed by Christopher F
parent 87124d3e39
commit f69ef2a8ca
14 changed files with 1074 additions and 1 deletions

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.