CodeInspect 0.1.0-beta
dotnet add package CodeInspect --version 0.1.0-beta
NuGet\Install-Package CodeInspect -Version 0.1.0-beta
<PackageReference Include="CodeInspect" Version="0.1.0-beta" />
paket add CodeInspect --version 0.1.0-beta
#r "nuget: CodeInspect, 0.1.0-beta"
// Install CodeInspect as a Cake Addin #addin nuget:?package=CodeInspect&version=0.1.0-beta&prerelease // Install CodeInspect as a Cake Tool #tool nuget:?package=CodeInspect&version=0.1.0-beta&prerelease
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
- Przemysław Grzywa - Przemko92
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CodeInspect.Attributes (>= 0.1.0)
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 |
---|---|---|
0.1.0-beta | 356 | 11/10/2019 |