CollectionExpressionKiller 1.0.0
See the version list below for details.
dotnet add package CollectionExpressionKiller --version 1.0.0
NuGet\Install-Package CollectionExpressionKiller -Version 1.0.0
<PackageReference Include="CollectionExpressionKiller" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="CollectionExpressionKiller" Version="1.0.0" />
<PackageReference Include="CollectionExpressionKiller"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add CollectionExpressionKiller --version 1.0.0
#r "nuget: CollectionExpressionKiller, 1.0.0"
#:package CollectionExpressionKiller@1.0.0
#addin nuget:?package=CollectionExpressionKiller&version=1.0.0
#tool nuget:?package=CollectionExpressionKiller&version=1.0.0
<div align="center">
Collection Expression Killer for C#
Ensures Explicit Coding Style for Code Review
</div>
Why?
Collection expression is useful for small scripts, demonstrations or other non-critical use cases but it is unclear what is actually created behind the scenes.
The source code should be explicitly expressing itself and eliminating "Something working" from the repository is important especially on code review on GitHub (no IDE assist).
Installation
dotnet add package CollectionExpressionKiller
.editorconfig Recommendation
Disable the suggestions relating to collection expressions.
dotnet_diagnostic.IDE0300.severity = silent # Use collection expression for array
dotnet_diagnostic.IDE0301.severity = silent # Use collection expression for empty
dotnet_diagnostic.IDE0305.severity = silent # Use collection expression for fluent
dotnet_diagnostic.IDE0028.severity = silent # Use collection initializers
Diagnostics
Ability to disallow all expressions or complicated only.
CEK001: Disallow all collection expressions.CEK002: Disallow expressions with 4 or more elements. (e.g.,[1, 2, ..other, 4])CEK003: Disallow expressions whose string representation is longer than 12 characters.
How to Disable Analyzer
Disable for entire .cs file with #pragma:
#pragma warning disable CEK001
#pragma warning disable CEK002
#pragma warning disable CEK003
int[] values = [1, 2, 3, 4, ..otherCollection];
Disable for entire assembly:
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage(
"Usage",
"CEK001:Collection expressions are not allowed",
Justification = "Approved for this assembly")]
[assembly: SuppressMessage(
"Usage",
"CEK002:Collection expressions must have fewer than 4 elements",
Justification = "Approved for this assembly")]
[assembly: SuppressMessage(
"Usage",
"CEK003:Collection expression text length must be 12 or fewer characters",
Justification = "Approved for this assembly")]
Disable for entire project with .editorconfig:
dotnet_diagnostic.CEK001.severity = none
dotnet_diagnostic.CEK002.severity = none
dotnet_diagnostic.CEK003.severity = none
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- 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.