Gu.Analyzers

April 18, 2023 ยท View on GitHub

This is a collection of warnings and refactorings with no real plan/scope. Made a package of it for the event someone finds something useful in it.

License NuGet Build status Build Status ci Join the chat at https://gitter.im/JohanLarsson/Gu.Analyzers

IdTitle
GU0001Name the argument
GU0002The position of a named argument should match
GU0003Name the parameter to match the assigned member
GU0004Assign all readonly members
GU0005Use correct argument positions
GU0006Use nameof
GU0007Prefer injecting
GU0008Avoid relay properties
GU0009Name the boolean argument
GU0010Assigning same value
GU0011Don't ignore the returned value
GU0012Check if parameter is null
GU0013Throw for correct parameter
GU0014Prefer using parameter
GU0015Don't assign same more than once
GU0016Prefer lambda
GU0017Don't use discarded
GU0018aName mock
GU0018bName mock
GU0019LinqOrDefault when IEnumerable
GU0020Sort properties
GU0021Calculated property allocates reference type
GU0022Use get-only
GU0023Static members that initialize with other static members depend on document order
GU0024Seal type with default member
GU0025Seal type with overridden equality
GU0026Range operator allocates
GU0050Ignore events when serializing
GU0051Cache the XmlSerializer
GU0052Mark exception with [Serializable]
GU0060Enum member value conflict
GU0061Enum member value out of range
GU0070Default-constructed value type with no useful default
GU0071Implicit casting done by the foreach
GU0072All types should be internal
GU0073Member of non-public type should be internal
GU0074Prefer pattern
GU0075Prefer return nullable
GU0076Merge pattern
GU0077Prefer is null
GU0080Parameter count does not match attribute
GU0081TestCase does not match parameters
GU0082TestCase is identical to other
GU0083TestCase Arguments Mismatch Method Parameters
GU0084Assert exception message
GU0090Don't throw NotImplementedException
GU0100Wrong cref type

Using Gu.Analyzers

The preferable way to use the analyzers is to add the nuget package Gu.Analyzers to the project(s).

The severity of individual rules may be configured using rule set files in Visual Studio 2015.

Installation

Gu.Analyzers can be installed using Paket or the NuGet command line or the NuGet Package Manager in Visual Studio 2015.

Install using the command line:

Install-Package Gu.Analyzers

Updating

The ruleset editor does not handle changes IDs well, if things get out of sync you can try:

  1. Close visual studio.
  2. Edit the ProjectName.rulset file and remove the Gu.Analyzers element.
  3. Start visual studio and add back the desired configuration.

Above is not ideal, sorry about this. Not sure this is our bug.

Current status

Early alpha, names and IDs may change.