Creedengo-C#

May 21, 2025 · View on GitHub

Creedengo on NuGet Creedengo on NuGet

Creedengo-C#

creedengo is a collective project aiming to reduce environmental footprint of software at the code level. The goal of the project is to provide a list of static code analyzers to highlight code structures that may have a negative ecological impact: energy and resources over-consumption, "fatware", shortening terminals' lifespan, etc.

creedengo is based on evolving catalogs of good practices, for various technologies. This set of Roslyn analyzers implements these catalogs as rules for scanning your C# projects.

License: GPL v3 Contributor Covenant

🚀 Getting Started

There are several ways you can use the creedengo C# analyzers in your .Net projects:

  1. As a NuGet package
  2. As a .NET tool
  3. As an analyzer for SonarQube.

🧩 NuGet package

The package is available on nuget.org at this address : https://www.nuget.org/packages/Creedengo, and can be added to your projects/solutions like any NuGet package. Once referenced and restored, the creedengo analyzers are automatically integrated in your IDE/compilation process, and will list any applicable info/alert.

Pre-requisite : .Net Standard 2.0, which can be used in a wide range of projects. See Microsoft documentation for details about the supported Frameworks.

🧩 .Net tool

The .Net tool is available on nuget.org at this address : https://www.nuget.org/packages/Creedengo.Tool, and can be fetched on your machine using the following command :

dotnet tool install --global Creedengo.Tool

See .Net tools documentation for additional information.

Once installed, you can launch an analyzis on an existing codebase like this :

creedengo-cli analyze path/to/mySolution.sln path/to/myReport.html.

The file to analyze can be a .sln, a .slnx or a .csproj. The report format depends on it's required extension, the following are currently supported : .html, .json and .csv.

Pre-requisite : .Net 8 SDK.

🧩 Analyzer for SonarQube

Creedengo C# can use SonarScanner for .Net to integrate with SonarQube, and uses a custom import addition to enrich what is reported to Sonar (severity, description, url page, category, and so on). See our dedicated repository for more information.

🌿 Creedengo Rules

IdDescriptionSeverityCode fix
GCI69Don’t call loop invariant functions in loop conditions⚠️
GCI72Don’t execute SQL queries in loops⚠️
GCI75Don’t concatenate strings in loops⚠️
GCI81Specify struct layouts⚠️✔️
GCI82Variable can be made constantℹ️✔️
GCI83Replace Enum ToString() with nameof⚠️✔️
GCI84Avoid async void methods⚠️✔️
GCI85Make type sealedℹ️✔️
GCI86GC.Collect should not be called⚠️
GCI87Use collection indexer⚠️✔️
GCI88Dispose resource asynchronously⚠️✔️
GCI91Use Where before OrderBy⚠️✔️
GCI92Use Length to test empty strings⚠️✔️
GCI93Return Task directlyℹ️✔️
GCI95Use is operator instead of as operatorℹ️✔️

🌿 Customized Roslyn Rules

Creedengo C# customizes the severity of the following native Roslyn rules.

IdDescriptionOld SeverityNew Severity
CA1001Types that own disposable fields should be disposable💤⚠️
CA1802Use Literals Where Appropriate💤⚠️
CA1805Do not initialize unnecessarily💤⚠️
CA1813Avoid unsealed attributes💤⚠️
CA1816Call GC.SuppressFinalize correctlyℹ️⚠️
CA1821Remove empty finalizersℹ️⚠️
CA1822Mark members as staticℹ️⚠️
CA1824Mark assemblies with NeutralResourcesLanguageAttributeℹ️⚠️
CA1825Avoid zero-length array allocationsℹ️⚠️
CA1826Use property instead of Linq Enumerable methodℹ️⚠️
CA1827Do not use Count()/LongCount() when Any() can be usedℹ️⚠️
CA1828Do not use CountAsync/LongCountAsync when AnyAsync can be usedℹ️⚠️
CA1829Use Length/Count property instead of Enumerable.Count methodℹ️⚠️
CA1830Prefer strongly-typed Append and Insert method overloads on StringBuilderℹ️⚠️
CA1832Use AsSpan or AsMemory instead of Range-based indexers for getting ReadOnlySpan or ReadOnlyMemory portion of an arrayℹ️⚠️
CA1833Use AsSpan or AsMemory instead of Range-based indexers for getting Span or Memory portion of an arrayℹ️⚠️
CA1834Use StringBuilder.Append(char) for single character stringsℹ️⚠️
CA1835Prefer the memory-based overloads of ReadAsync/WriteAsync methods in stream-based classesℹ️⚠️
CA1836Prefer IsEmpty over Count when availableℹ️⚠️
CA1837Use Environment.ProcessId instead of Process.GetCurrentProcess().Idℹ️⚠️
CA1838Avoid StringBuilder parameters for P/Invokes💤⚠️
CA1839Use Environment.ProcessPath instead of Process.GetCurrentProcess().MainModule.FileNameℹ️⚠️
CA1840Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadIdℹ️⚠️
CA1841Prefer Dictionary Contains methodsℹ️⚠️
CA1842Do not use 'WhenAll' with a single taskℹ️⚠️
CA1843Do not use 'WaitAll' with a single taskℹ️⚠️
CA1844Provide memory-based overrides of async methods when subclassing 'Stream'ℹ️⚠️
CA1845Use span-based 'string.Concat'ℹ️⚠️
CA1846Prefer AsSpan over Substringℹ️⚠️
CA1847Use String.Contains(char) instead of String.Contains(string) with single charactersℹ️⚠️
CA1850Prefer static HashData method over ComputeHashℹ️⚠️
CA1853Unnecessary call to 'Dictionary.ContainsKey(key)'ℹ️⚠️
CA1854Prefer the IDictionary.TryGetValue(TKey, out TValue) methodℹ️⚠️
CA1855Use Span.Clear() instead of Span.Fill()ℹ️⚠️
CA1858Use StartsWith instead of IndexOfℹ️⚠️
CA1859Prefer concrete types when possible for improved performanceℹ️⚠️
CA1860Avoid using 'Enumerable.Any()' extension methodℹ️⚠️
CA1863Use 'CompositeFormat'💤⚠️
CA1864Prefer the 'IDictionary.TryAdd(TKey, TValue)' methodℹ️⚠️
CA1865-7Use 'string.Method(char)' instead of 'string.Method(string)' for string with single charℹ️⚠️
CA1868Unnecessary call to 'Contains' for setsℹ️⚠️
CA1869Cache and reuse 'JsonSerializerOptions' instancesℹ️⚠️
CA1870Use a cached 'SearchValues' instanceℹ️⚠️
CA1871Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'ℹ️⚠️
CA1872Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'ℹ️⚠️
CA2009Do not call ToImmutableCollection on an ImmutableCollection valueℹ️⚠️
CA2215Dispose methods should call base class dispose💤⚠️
CA2218Override GetHashCode on overriding Equalsℹ️⚠️
CA2251Use String.Equals over String.Compare💤⚠️
CA2264Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'ℹ️⚠️

🤝 Contribution

See contribution on the central repository.

🤓 Main contributors

See main contributors on the central repository.