Skip to content
thoenissenPublic

About

.NET code style analyzer

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

Reihitsu

麗筆 (reihitsu, [ɾeːçitsɯ]) — beautiful brushwork

A collection of C# development tools built on the Roslyn compiler platform, including a code analyzer with code fixes and a standalone formatting CLI tool.

Packages

Package Description
Reihitsu.Analyzer Roslyn-based analyzer package enforcing coding rules for clarity, design, naming, formatting, documentation, ordering, and performance. NuGet
Reihitsu.Cli Command-line formatting tool for C# source files. NuGet

Try the formatter in your browser at thoenissen.github.io/Reihitsu — no install required, and it always runs the formatter from the latest commit on main.

Quick Start

Analyzer

dotnet add package Reihitsu.Analyzer

CLI

dotnet tool install -g Reihitsu.Cli
reihitsu-format src/

Specifications

The intended behavior of the analyzer, formatter, CLI, and Playground is specified under sdd/, following the repository's Spec Driven Development rules.

Showcase

The following is a code snippet that complies with the rules of the analyzer and formatter.

/// <summary>
/// Builds report instances from a list of customer orders
/// </summary>
internal sealed class ReportBuilder
{
    #region Fields

    /// <summary>
    /// The orders that can are used to build the report
    /// </summary>
    private readonly IReadOnlyList<Order> _orders;

    #endregion // Fields

    #region Constructor

    /// <summary>
    /// Initializes a new instance of the <see cref="ReportBuilder"/> class
    /// </summary>
    /// <param name="orders">The orders that can be used to build reports</param>
    public ReportBuilder(IReadOnlyList<Order> orders)
    {
        _orders = orders ?? throw new ArgumentNullException(nameof(orders));
    }

    #endregion // Constructor

    #region Methods

    /// <summary>
    /// Builds a report for a specific customer
    /// </summary>
    /// <param name="customerId">The customer identifier to filter for</param>
    /// <param name="createdOn">The date assigned to the generated report</param>
    /// <param name="includeInactive">A value indicating whether inactive orders should be included</param>
    /// <returns>The generated report</returns>
    public Report Build(string customerId, DateOnly createdOn, bool includeInactive)
    {
        var items = _orders.Where(order => order.CustomerId == customerId)
                           .Where(order => includeInactive || order.IsActive)
                           .Select(order => new ReportItem
                                            {
                                                Id = order.Id,
                                                Lines = order.Lines
                                                             .Select(line => new ReportLine
                                                                             {
                                                                                 Name = line.Name,
                                                                                 Total = line.UnitPrice
                                                                                         * line.Quantity
                                                                             })
                                                             .ToArray()
                                            })
                           .OrderBy(item => item.Id)
                           .ToArray();

        return new Report(customerId,
                          createdOn,
                          items,
                          new ReportOptions
                          {
                              IncludeTotals = true,
                              UseShortDates = false,
                              Labels = [
                                           "stable",
                                           "demo"
                                       ]
                          });
    }

    #endregion // Methods
}

License

This project is licensed under the terms of the LICENSE file.

SonarCloud

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%)

About

.NET code style analyzer

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages