SharpSource 1.9.1
See the version list below for details.
dotnet add package SharpSource --version 1.9.1
NuGet\Install-Package SharpSource -Version 1.9.1
<PackageReference Include="SharpSource" Version="1.9.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add SharpSource --version 1.9.1
#r "nuget: SharpSource, 1.9.1"
// Install SharpSource as a Cake Addin #addin nuget:?package=SharpSource&version=1.9.1 // Install SharpSource as a Cake Tool #tool nuget:?package=SharpSource&version=1.9.1
This repo houses a collection of analyzers that aim to make some language features and framework types easier to work with. It does this by highlighting when you might be using something incorrectly in a way that would result in suboptimal performance, runtime exceptions or general unintended behaviour.
In other words, this repo only contains analyzers for patterns that have a concrete potential to turn into a defect ticket. It is not intended to help with general housekeeping tasks like formatting your code or providing productivity helpers.
Interested in contributing? Take a look at the guidelines!
Code | Name | Description | Level | Provides Code Fix? |
---|---|---|---|---|
SS001 | AsyncMethodWithVoidReturnType | Async methods should return a Task to make them awaitable. Without it, execution continues before the asynchronous Task has finished an exceptions go unhandled. |
Warning | Yes |
SS002 | DateTimeNow | Use DateTime.UtcNow to get a locale-independent value. DateTime.Now uses the system's local timezone which often means unexpected behaviour when working with global teams/deployments. |
Warning | Yes |
SS003 | DivideIntegerByInteger | The operands of a divisive expression are both integers and result in an implicit rounding. | Warning | No |
SS004 | ElementaryMethodsOfTypeInCollectionNotOverridden | Implement Equals() and GetHashcode() methods for a type used in a collection. Collections use these to fetch objects but by default they use reference equality. Depending on where your objects come from, they might be missed in the lookup. |
Warning | No |
SS005 | EqualsAndGetHashcodeNotImplementedTogether | Implement Equals() and GetHashcode() together. Implement both to ensure consistent behaviour around lookups. |
Warning | Yes |
SS006 | ThrowNull | Throwing null will always result in a runtime exception. |
Error | No |
SS007 | FlagsEnumValuesAreNotPowersOfTwo | [Flags] enum members need to be either powers of two, or bitwise OR expressions. This will fire if they are non-negative decimal literals that are not powers of two, and provide a code fix if the value can be achieved through a binary OR using other enum members. |
Error | Yes |
SS008 | GetHashCodeRefersToMutableMember | GetHashCode( ) refers to mutable or static member. If the object is used in a collection and then is mutated, subsequent lookups will result in a different hash and might cause lookups to fail. |
Warning | No |
SS009 | LoopedRandomInstantiation | An instance of type System.Random is created in a loop. Random uses a time-based seed so when used in a fast loop it will end up with multiple identical seeds for subsequent invocations. |
Warning | No |
SS010 | NewGuid | An empty GUID was created in an ambiguous manner. The default Guid constructor creates an instance with an empty value which is rarely what you want. |
Error | Yes |
SS011 | OnPropertyChangedWithoutNameofOperator | Use the nameof() operator in conjunction with OnPropertyChanged() to avoid divergence. |
Warning | Yes |
SS012 | RecursiveOperatorOverload | Recursively using overloaded operator will result in a stack overflow when attempting to use it. | Error | No |
SS013 | RethrowExceptionWithoutLosingStacktrace | An exception is rethrown in a way that it loses the stacktrace. Use an empty throw; statement instead to preserve it. |
Warning | Yes |
SS014 | StringDotFormatWithDifferentAmountOfArguments | A string.Format() call lacks arguments and will cause a runtime exception. |
Error | Yes |
SS015 | StringPlaceholdersInWrongOrder | Orders the arguments of a string.Format() call in ascending order according to index. This reduces the likelihood of the resulting string having data in the wrong place. |
Warning | Yes |
SS017 | StructWithoutElementaryMethodsOverridden | Structs should implement Equals() , GetHashCode() , and ToString() . By default they use reflection which comes with performance penalties. |
Warning | Yes |
SS018 | SwitchDoesNotHandleAllEnumOptions | Add cases for missing enum member. That way you won't miss new behaviour in the consuming API since it will be explicitly handled. | Warning | Yes |
SS019 | SwitchIsMissingDefaultLabel | Switch is missing a default label. Include this to provide fallback behaviour for any missing cases, including when the upstream API adds them later on. |
Warning | Yes |
SS020 | TestMethodWithoutPublicModifier | Verifies whether a test method has the public modifier. Some test frameworks require this to discover unit tests. |
Warning | Yes |
SS021 | TestMethodWithoutTestAttribute | A method might be missing a test attribute. Helps ensure no unit tests are missing from your test runs. | Warning | No |
SS022 | ExceptionThrownFromImplicitOperator | An exception is thrown from an implicit operator |
Warning | No |
SS023 | ExceptionThrownFromPropertyGetter | An exception is thrown from a property getter | Warning | No |
SS024 | ExceptionThrownFromStaticConstructor | An exception is thrown from a static constructor |
Warning | No |
SS025 | ExceptionThrownFromFinallyBlock | An exception is thrown from a finally block |
Warning | No |
SS026 | ExceptionThrownFromEqualityOperator | An exception is thrown from an equality operator | Warning | No |
SS027 | ExceptionThrownFromDispose | An exception is thrown from a Dispose() method |
Warning | No |
SS028 | ExceptionThrownFromFinalizer | An exception is thrown from a finalizer method | Warning | No |
SS029 | ExceptionThrownFromGetHashCode | An exception is thrown from a GetHashCode() method |
Warning | No |
SS030 | ExceptionThrownFromEquals | An exception is thrown from an Equals() method |
Warning | No |
SS032 | ThreadSleepInAsyncMethod | Synchronously sleeping a thread in an async method combines two threading models and can lead to deadlocks. |
Warning | Yes |
SS033 | AsyncOverloadsAvailable | An async overload is available. These overloads typically exist to provide better performing IO calls and should generally be preferred. |
Warning | Yes |
SS034 | AccessingTaskResultWithoutAwait | Use await to get the result of an asynchronous operation. While accessing .Result is fine once the Task has been completed, this removes any ambiguity and helps prevent regressions if the code changes later on. |
Warning | Yes |
SS035 | SynchronousTaskWait | Asynchronously await tasks instead of blocking them to avoid deadlocks. |
Warning | Yes |
SS036 | ExplicitEnumValues | An enum should explicitly specify its values. Otherwise you risk serializing your enums into different numeric values if you add a new member at any place other than the last line in the enum file. | Warning | Yes |
SS037 | HttpClientInstantiatedDirectly | HttpClient was instantiated directly. This can result in socket exhaustion and DNS issues in long-running scenarios. Use IHttpClientFactory instead. |
Warning | No |
SS038 | HttpContextStoredInField | HttpContext was stored in a field. This can result in a previous context being used for subsequent requests. Use IHttpContextAccessor instead. |
Warning | No |
SS039 | EnumWithoutDefaultValue | An enum should specify a default value of 0 as "Unknown" or "None". When an invalid enum value is marshalled or you receive a default value, many systems return it as 0 . This way you don't inadvertedly interpret it as a valid value. |
Warning | No |
SS040 | UnusedResultOnImmutableObject | The result of an operation on a string is unused. At best this has no effect, at worst this means a desired string operation has not been performed. |
Warning | No |
SS041 | UnnecessaryEnumerableMaterialization | An IEnumerable was materialized before a deferred execution call. This generally results in unnecessary work being done. |
Warning | Yes |
SS042 | InstanceFieldWithThreadStatic | [ThreadStatic] can only be used on static fields. If used on an instance field the attribute will not have any effect and the subsequent multithreading behaviour will not be as intended. |
Error | No |
SS043 | MultipleFromBodyParameters | A method specifies multiple [FromBody] parameters but only one is allowed. Specify a wrapper type or use [FromForm] , [FromRoute] , [FromHeader] and [FromQuery] instead. |
Error | No |
SS044 | AttributeMustSpecifyAttributeUsage | An attribute was defined without specifying the [AttributeUsage] . |
Warning | Yes |
SS045 | StaticInitializerAccessedBeforeInitialization | A static field relies on the value of another static field which is defined in the same type. static fields are initialized in order of appearance. |
Error | No |
SS046 | UnboundedStackalloc | An array is stack allocated without checking whether the length is within reasonable bounds. This can result in performance degradations and security risks. | Warning | Yes |
SS047 | LinqTraversalBeforeFilter | An IEnumerable extension method was used to traverse the collection and is subsequently filtered using Where() . If the Where() filter is executed first, the traversal will have to iterate over fewer items which will result in better performance. |
Warning | No |
SS048 | LockingOnDiscouragedObject | A lock was taken using an instance of a discouraged type. System.String , System.Type and this references can all lead to deadlocks and should be replaced with a System.Object instance instead. |
Warning | No |
Configuration
Is a particular rule not to your liking? There are many ways to adjust their severity and even disable them altogether. For an overview of some of the options, check out this document.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.25.2 | 1,776 | 9/15/2024 |
1.25.1 | 101 | 9/15/2024 |
1.25.0 | 132 | 9/15/2024 |
1.24.1 | 151 | 9/13/2024 |
1.24.0 | 8,979 | 2/21/2024 |
1.23.4 | 860 | 1/5/2024 |
1.23.3 | 5,697 | 5/15/2023 |
1.23.2 | 791 | 3/18/2023 |
1.23.1 | 2,019 | 2/28/2023 |
1.23.0 | 311 | 2/26/2023 |
1.22.2 | 287 | 2/25/2023 |
1.22.1 | 311 | 2/21/2023 |
1.22.0 | 277 | 2/21/2023 |
1.21.6 | 681 | 2/10/2023 |
1.21.5 | 407 | 1/31/2023 |
1.21.4 | 338 | 1/29/2023 |
1.21.3 | 332 | 1/25/2023 |
1.21.2 | 314 | 1/23/2023 |
1.21.1 | 318 | 1/22/2023 |
1.21.0 | 330 | 1/21/2023 |
1.20.0 | 347 | 1/20/2023 |
1.19.1 | 366 | 1/14/2023 |
1.19.0 | 330 | 1/12/2023 |
1.18.0 | 10,946 | 1/10/2023 |
1.17.6 | 343 | 1/8/2023 |
1.17.5 | 359 | 1/6/2023 |
1.17.4 | 348 | 1/4/2023 |
1.17.3 | 329 | 1/3/2023 |
1.17.2 | 355 | 1/2/2023 |
1.17.1 | 329 | 1/2/2023 |
1.17.0 | 350 | 1/1/2023 |
1.16.22 | 349 | 1/1/2023 |
1.16.21 | 344 | 1/1/2023 |
1.16.20 | 330 | 1/1/2023 |
1.16.19 | 337 | 1/1/2023 |
1.16.18 | 319 | 12/31/2022 |
1.16.17 | 304 | 12/31/2022 |
1.16.16 | 339 | 12/30/2022 |
1.16.15 | 348 | 12/30/2022 |
1.16.14 | 355 | 12/30/2022 |
1.16.13 | 301 | 12/30/2022 |
1.16.12 | 321 | 12/30/2022 |
1.16.11 | 338 | 12/30/2022 |
1.16.10 | 323 | 12/30/2022 |
1.16.9 | 334 | 12/30/2022 |
1.16.8 | 303 | 12/30/2022 |
1.16.7 | 342 | 12/30/2022 |
1.16.6 | 338 | 12/30/2022 |
1.16.5 | 360 | 12/29/2022 |
1.16.4 | 343 | 12/29/2022 |
1.16.3 | 311 | 12/29/2022 |
1.16.2 | 340 | 12/29/2022 |
1.16.1 | 344 | 12/28/2022 |
1.16.0 | 307 | 12/27/2022 |
1.15.0 | 344 | 12/25/2022 |
1.14.1 | 9,671 | 10/16/2022 |
1.14.0 | 438 | 10/16/2022 |
1.13.1 | 431 | 10/1/2022 |
1.13.0 | 425 | 10/1/2022 |
1.12.0 | 480 | 9/25/2022 |
1.11.2 | 459 | 9/25/2022 |
1.11.1 | 425 | 9/24/2022 |
1.11.0 | 464 | 9/24/2022 |
1.10.1 | 449 | 9/16/2022 |
1.10.0 | 494 | 9/14/2022 |
1.9.4 | 514 | 9/13/2022 |
1.9.3 | 436 | 9/12/2022 |
1.9.2 | 417 | 9/12/2022 |
1.9.1 | 452 | 9/11/2022 |
1.9.0 | 455 | 9/11/2022 |
1.8.0 | 438 | 9/8/2022 |
1.7.2 | 455 | 9/6/2022 |
1.7.1 | 458 | 9/5/2022 |
1.7.0 | 452 | 9/5/2022 |
1.6.0 | 415 | 9/4/2022 |
1.5.0 | 418 | 9/4/2022 |
1.4.2 | 447 | 9/4/2022 |
1.3.1 | 453 | 9/3/2022 |
1.3.0 | 458 | 9/2/2022 |
1.2.4 | 462 | 8/31/2022 |
1.2.3 | 468 | 8/29/2022 |
1.2.2 | 459 | 8/29/2022 |
1.2.1 | 444 | 8/29/2022 |
1.2.0 | 458 | 8/29/2022 |
1.1.1 | 462 | 8/28/2022 |
1.1.0 | 443 | 8/28/2022 |
1.0.0 | 476 | 8/28/2022 |
0.9.0 | 466 | 8/26/2022 |
0.8.0 | 460 | 8/23/2022 |
0.7.0 | 421 | 8/22/2022 |
0.6.0 | 471 | 8/15/2022 |
0.5.0 | 442 | 8/14/2022 |
0.4.0 | 466 | 8/14/2022 |
0.3.0 | 538 | 5/10/2020 |
0.2.0 | 548 | 4/12/2020 |
0.1.0 | 574 | 4/12/2020 |
For a full overview of the changes, visit https://github.com/vannevelj/sharpsource/releases