Skip to content

thoenissen/Reihitsu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

443 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reihitsu

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

Quick Start

Analyzer

dotnet add package Reihitsu.Analyzer

CLI

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

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

License

Stars

4 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors