CodeInspect 0.1.0-beta

CodeInspect library helps you get right noding convention and naming convention

This is a prerelease version of CodeInspect.
Install-Package CodeInspect -Version 0.1.0-beta
dotnet add package CodeInspect --version 0.1.0-beta
<PackageReference Include="CodeInspect" Version="0.1.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeInspect --version 0.1.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RapidCQRS

This is free .NET Standard 2.0 library for Code style inspection. You can use this library with .NET Core >= 2.0 and .NET Framework >= 4.61

Version

Getting Started

These instructions will help you to attach this library to your project

Installing

Instalation with Nuget

Install-Package CodeInspect

Optionally you can add package with attributes like [CodeInspectIgnore]
Install-Package CodeInspect.Attributes

Usage

In Xunit project examples:

Inspect all fields names in the assembly

Fields should have names longer than 2 chars and shorter than 30 chars

Every not specified fields (like public or internal fields) are forbidden in this scenario

Every private and protected fields name must starts with "_"

Every static fields name must start lower case

[Fact]
public void CheckFields_Names_InAssembly()
{
    var inspectResult = Inspect
        .AllFields
        .InAssemblies(typeof(StandardClass).Assembly)
        .AllFields.NameIsNotLongerThan(30).NameIsNotShorterThan(2)
        .And
        .AllNotSpecified.AreForbidden()
        .And
        .PrivateFields.NameStartsWith("_")
        .And
        .ProtectedFields.NameStartsWith("_")
        .And
        .StaticPrivateFields.NameStartsWithLowerCase()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all methods in the namespace

Every method should have name not shorter than 2 chars, not longer than 30 chars, no more args than 6

Every parameter of method should have name starts with lowecase, param name not shorter than 2 chars, param name cannot be longer than 15 chars

Every private method must have return value

[Fact]
public void CheckMethods_NamesAndArgs_InNamespace()
{
    var inspectResult = Inspect
        .AllMethods
        .InNamespaces(typeof(StandardClass).Namespace)
        .AllMethods.NameIsNotShorterThan(2).NameIsNotLongerThan(30).HasLessArgsThan(6).ParamsNameStartsWithLowerCase().ParamsNameIsNotShorterThan(2).ParamsNameNotLongerThan(15)
        .And
        .PrivateMethods.HasReturnType()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all properties in the namespace

Every property name cannot be shorter than 2 chars, name must be shorter than 30 chars, each propertys name must starts capital letter

Every public property must have attribute DataMemberAttribute

Private properties AreForbidden

[Fact]
public void CheckProperties_Attributes_InContract()
{
    var inspectResult = Inspect
        .AllProperties
        .InNamespaces(typeof(TestContract).Namespace)
        .AllProperties.NameIsNotShorterThan(2).NameIsNotLongerThan(30).NameStartsWithCapitalLetter()
        .And
        .PublicProperties.HasAttribute<DataMemberAttribute>()
        .And
        .PrivateProperties.AreForbidden()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all types in the namespace

Types names cannot be shorter than 2 chars and longer than 30 chars. Name must starts with capital letter

Every type must have default constructor, not more methods than 20, not more methods than 10 and inherits class ContractBase

[Fact]
public void CheckTypes_HasDefaultConstructors_InNamespace()
{
    var inspectResult = Inspect
        .AllTypes
        .InNamespaces(typeof(TestContract).Namespace)
        .AllTypes.NameIsNotShorterThan(2).NameIsNotLongerThan(30).NameStartsWithCapitalLetter().HasDefaultConstructor().HasNotMoreMethodsThan(20).HasNotMorePropertiesThan(10).Inherits<ContractBase>()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Authors

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

RapidCQRS

This is free .NET Standard 2.0 library for Code style inspection. You can use this library with .NET Core >= 2.0 and .NET Framework >= 4.61

Version

Getting Started

These instructions will help you to attach this library to your project

Installing

Instalation with Nuget

Install-Package CodeInspect

Optionally you can add package with attributes like [CodeInspectIgnore]
Install-Package CodeInspect.Attributes

Usage

In Xunit project examples:

Inspect all fields names in the assembly

Fields should have names longer than 2 chars and shorter than 30 chars

Every not specified fields (like public or internal fields) are forbidden in this scenario

Every private and protected fields name must starts with "_"

Every static fields name must start lower case

[Fact]
public void CheckFields_Names_InAssembly()
{
    var inspectResult = Inspect
        .AllFields
        .InAssemblies(typeof(StandardClass).Assembly)
        .AllFields.NameIsNotLongerThan(30).NameIsNotShorterThan(2)
        .And
        .AllNotSpecified.AreForbidden()
        .And
        .PrivateFields.NameStartsWith("_")
        .And
        .ProtectedFields.NameStartsWith("_")
        .And
        .StaticPrivateFields.NameStartsWithLowerCase()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all methods in the namespace

Every method should have name not shorter than 2 chars, not longer than 30 chars, no more args than 6

Every parameter of method should have name starts with lowecase, param name not shorter than 2 chars, param name cannot be longer than 15 chars

Every private method must have return value

[Fact]
public void CheckMethods_NamesAndArgs_InNamespace()
{
    var inspectResult = Inspect
        .AllMethods
        .InNamespaces(typeof(StandardClass).Namespace)
        .AllMethods.NameIsNotShorterThan(2).NameIsNotLongerThan(30).HasLessArgsThan(6).ParamsNameStartsWithLowerCase().ParamsNameIsNotShorterThan(2).ParamsNameNotLongerThan(15)
        .And
        .PrivateMethods.HasReturnType()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all properties in the namespace

Every property name cannot be shorter than 2 chars, name must be shorter than 30 chars, each propertys name must starts capital letter

Every public property must have attribute DataMemberAttribute

Private properties AreForbidden

[Fact]
public void CheckProperties_Attributes_InContract()
{
    var inspectResult = Inspect
        .AllProperties
        .InNamespaces(typeof(TestContract).Namespace)
        .AllProperties.NameIsNotShorterThan(2).NameIsNotLongerThan(30).NameStartsWithCapitalLetter()
        .And
        .PublicProperties.HasAttribute<DataMemberAttribute>()
        .And
        .PrivateProperties.AreForbidden()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Inspect all types in the namespace

Types names cannot be shorter than 2 chars and longer than 30 chars. Name must starts with capital letter

Every type must have default constructor, not more methods than 20, not more methods than 10 and inherits class ContractBase

[Fact]
public void CheckTypes_HasDefaultConstructors_InNamespace()
{
    var inspectResult = Inspect
        .AllTypes
        .InNamespaces(typeof(TestContract).Namespace)
        .AllTypes.NameIsNotShorterThan(2).NameIsNotLongerThan(30).NameStartsWithCapitalLetter().HasDefaultConstructor().HasNotMoreMethodsThan(20).HasNotMorePropertiesThan(10).Inherits<ContractBase>()
        .Test();

    Assert.True(inspectResult.IsOk, inspectResult.GetErrorMessage());
}

Authors

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.1.0-beta 140 11/10/2019