EcoLint 1.0.0

dotnet add package EcoLint --version 1.0.0
                    
NuGet\Install-Package EcoLint -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EcoLint" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EcoLint" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EcoLint" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EcoLint --version 1.0.0
                    
#r "nuget: EcoLint, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EcoLint@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EcoLint&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EcoLint&version=1.0.0
                    
Install as a Cake Tool

<div align="center"> <img src="ecoicon.png" alt="EcoLint Logo" width="200" /> <h1>EcoLint</h1> <p><em>Professional Static Code Analysis for Green Computing in .NET</em></p> </div>

The 'Eco-Computing' Manifesto

Software inefficiency is an invisible environmental crisis. Every redundant CPU cycle, every unnecessary memory allocation, and every blocked thread consumes electrical power. At planetary scale, these inefficiencies compound into significant, measurable carbon emissions. EcoLint is engineered to detect these architectural "Carbon Leaks" in .NET applications, shifting sustainable development from an afterthought to an automated, measurable standard.

We use specific physics-based heuristics to calculate and mitigate carbon waste:

  • Algorithmic Carbon Impact ($C_{algo}$): Nested loops and sub-optimal time complexities ($O(N^2)$) exponentially increase TDP (Thermal Design Power) load over execution time.
  • Garbage Collection Energy ($E_{GC}$): Redundant memory allocations trigger Full Gen 2 GC pauses. Each collection cycle forces the CPU into a high-power state to traverse object graphs.
  • Socket and Thread Leakage ($S_{leak}$): Synchronous blocking (.Wait(), .Result) and direct HttpClient instantiation lead to thread starvation and TIME_WAIT socket exhaustion, wasting server capacity and requiring more horizontal scaling.

Comprehensive Rules Catalog

Rule ID Name Technical Anti-Pattern Carbon Impact Mitigation
ECO001 Nested Loop Complexity Nested for/foreach/while loops. Increases $C_{algo}$ exponentially. Causes prolonged CPU TDP load. Optimize to $O(N)$ using HashSet or Dictionary.
ECO002 Loop String Concatenation Using + or += inside loops for strings. Causes high $E_{GC}$ via repeated allocations. Switch to StringBuilder to nullify GC energy draw.
ECO003 Synchronous Task Blocking .Result or .Wait() on asynchronous tasks. Increases $S_{leak}$. Wastes thread pool and grid energy. Refactor to use proper await syntax.
ECO004 Unnecessary LINQ Count .Count() > 0 for collection check. Wastes CPU cycles by enumerating entire collections. Use .Any() to halt execution immediately.
ECO005 HttpClient Leak Direct new HttpClient() instantiation. High $S_{leak}$ due to socket exhaustion (TIME_WAIT). Use IHttpClientFactory or a singleton.
ECO006 Missing Span Optimization foreach over standard collections in high frequency. High memory allocation resulting in $E_{GC}$ spikes. Use Span<T> or ReadOnlySpan<T> to zero out allocations.
ECO007 Large Struct by Value Passing structs without in or ref modifier. Redundant memory copying energy across execution scopes. Use the in modifier for large read-only structs.
ECO008 Missing CancellationToken Long-running async loops missing cancellation check. "Ghost" cloud computations continuing after cancellation. Monitor CancellationToken in async loops.
ECO009 Class Destructor Usage Custom finalizer (~Class()) implementation. Delays object promotion to Gen 1/2, forcing longer grid residency power. Avoid finalizers entirely; implement IDisposable.
ECO010 LOH Exhaustion Risk Direct heavy array allocation (new byte[10000]). Potential Large Object Heap (LOH) shock and destructive Full GC. Utilize ArrayPool<T>.Shared to rent/return buffers.

Code Examples: Anti-Pattern vs. Eco-Friendly

ECO001: Nested Loop Complexity

Anti-Pattern:

// O(N^2) complexity causes prolonged CPU load
foreach (var user in users) {
    foreach (var order in orders) {
        if (user.Id == order.UserId) { /* ... */ }
    }
}

Eco-Friendly:

// O(N) complexity using a Dictionary
var userDict = users.ToDictionary(u => u.Id);
foreach (var order in orders) {
    if (userDict.TryGetValue(order.UserId, out var user)) { /* ... */ }
}

ECO002: Loop String Concatenation

Anti-Pattern:

string result = "";
for(int i = 0; i < 100; i++) {
    result += "data"; // Allocates new string each time
}

Eco-Friendly:

var sb = new StringBuilder();
for(int i = 0; i < 100; i++) {
    sb.Append("data");
}
var result = sb.ToString();

ECO003: Synchronous Task Blocking

Anti-Pattern:

// Blocks thread, risks thread pool starvation
var data = FetchDataAsync().Result; 

Eco-Friendly:

var data = await FetchDataAsync();

ECO004: Unnecessary LINQ Count

Anti-Pattern:

// Iterates entire sequence to find count
if (users.Count() > 0) { /* ... */ } 

Eco-Friendly:

// Returns true as soon as one element is found
if (users.Any()) { /* ... */ }

ECO005: HttpClient Leak

Anti-Pattern:

// Leaves sockets in TIME_WAIT state
using (var client = new HttpClient()) {
    var response = await client.GetAsync(url);
}

Eco-Friendly:

// Reuses sockets
var client = _httpClientFactory.CreateClient();
var response = await client.GetAsync(url);

ECO006: Missing Span Optimization

Anti-Pattern:

foreach (var item in dataArray) { /* ... */ }

Eco-Friendly:

// Avoids heap tracking
ReadOnlySpan<int> span = dataArray.AsSpan();
foreach (var item in span) { /* ... */ }

ECO007: Large Struct by Value

Anti-Pattern:

// Copies full struct memory on invocation
public void Process(LargeStruct data) { /* ... */ }

Eco-Friendly:

// Passes by read-only reference
public void Process(in LargeStruct data) { /* ... */ }

ECO008: Missing CancellationToken

Anti-Pattern:

// Continues running even if parent is cancelled
while (true) {
    await Task.Delay(1000);
}

Eco-Friendly:

while (!cancellationToken.IsCancellationRequested) {
    await Task.Delay(1000, cancellationToken);
}

ECO009: Class Destructor Usage

Anti-Pattern:

~MyClass() {
    // Delays GC cleanup
}

Eco-Friendly:

public class MyClass : IDisposable {
    public void Dispose() {
        // Deterministic cleanup
        GC.SuppressFinalize(this);
    }
}

ECO010: LOH Exhaustion Risk

Anti-Pattern:

// Stresses LOH and causes Full Gen 2 GC
var buffer = new byte[10000]; 

Eco-Friendly:

var buffer = ArrayPool<byte>.Shared.Rent(10000);
try {
    // Process data
} finally {
    ArrayPool<byte>.Shared.Return(buffer);
}

Installation & Usage Guide

System Requirements

  • .NET SDK: 6.0 or higher.

CLI Commands

EcoLint acts as a fast command-line static analyzer.

# Build the tool
dotnet build

# Run EcoLint against a target project
dotnet run -- "path/to/target/project"

Interpreting Outputs

EcoLint produces two standard report formats:

  • JSON Report: Ideal for automated CI/CD pipelines. It cleanly lists file paths, rule IDs, and line numbers of any carbon leaks.
  • HTML Report: Provides an interactive, graphical sustainability dashboard. Developers can use this to visually locate architectural flaws and implement eco-friendly mitigations.

CI/CD Integration

Use EcoLint as a Quality Gate in your automated pipelines to prevent carbon-heavy logic from reaching production. Here is an example configuration for GitHub Actions:

name: Green Computing Quality Gate

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  ecolint-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '8.0.x'
        
    - name: Run EcoLint Analysis
      run: |
        dotnet run --project path/to/EcoLint/EcoLint.csproj -- "path/to/your/target/project"
        
    # Example: Fail the build if HTML report shows Critical Carbon Leaks

Technical Architecture: Under the Hood

  • LintEngine.cs: The core analyzer. It orchestrates static analysis by dynamically loading all IEcoRule implementations, parsing target .cs files, and checking for carbon leaks using efficient regex-based structural evaluation without full Roslyn compilation overhead.
  • HtmlReportGenerator.cs: Translates the raw lists of LintIssue items into a dynamic, stylized HTML report. It helps bridge the gap between abstract code anti-patterns and actionable sustainability metrics.

EcoLint: Built for the future. Code responsibly.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.

Version Downloads Last Updated
1.0.0 123 6/6/2026
1.0.0-beta 103 6/3/2026

v1.0.0: Added ECO007-ECO010 rules. New Web Dashboard for visual reporting. General bug fixes and performance optimizations.