From b1d6229b5347a8a99f1af6f36c3c5b949fb91128 Mon Sep 17 00:00:00 2001 From: GaelFraiteur Date: Tue, 24 Sep 2024 12:05:34 +0200 Subject: [PATCH] Fixing some issues. Applying Metalama code style. --- .../CodeQualityTalk.Analyzers.csproj | 4 +- .../FactoryNameAnalyzer.cs | 63 ++++++++++--------- .../ArchitectureTests.cs | 22 ++++--- .../CodeQualityTalk.ArchUnitTests.csproj | 8 +-- .../Abstractions/DocumentCreationContext.cs | 2 + .../Abstractions/DocumentHelper.cs | 6 +- .../Abstractions/IDocument.cs | 3 + .../Abstractions/IDocumentFactory.cs | 8 ++- .../Architecture/AdvancedFabric.cs | 22 ++++--- .../Architecture/Fabric.cs | 10 +-- .../CodeQualityTalk.Metalama.csproj | 4 +- CodeQualityTalk.Metalama/CreditNote.cs | 13 ++-- CodeQualityTalk.Metalama/Documents/Invoice.cs | 13 ++-- .../Factories/CreditNoteCreator.cs | 5 +- .../Factories/InvoiceFactory.cs | 5 +- .../CodeQualityTalk.Verifier.csproj | 8 +-- CodeQualityTalk.Verifier/Program.cs | 55 +++++++++------- .../Abstractions/DocumentCreationContext.cs | 2 + .../Abstractions/DocumentHelper.cs | 6 +- CodeQualityTalk/Abstractions/IDocument.cs | 3 + .../Abstractions/IDocumentFactory.cs | 6 +- CodeQualityTalk/CreditNote.cs | 13 ++-- CodeQualityTalk/Documents/Invoice.cs | 15 +++-- .../Factories/CreditNoteCreator.cs | 5 +- CodeQualityTalk/Factories/InvoiceFactory.cs | 5 +- Directory.Packages.Props | 18 ++++++ qodana.yaml | 29 +++++++++ 27 files changed, 224 insertions(+), 129 deletions(-) create mode 100644 Directory.Packages.Props create mode 100644 qodana.yaml diff --git a/CodeQualityTalk.Analyzers/CodeQualityTalk.Analyzers.csproj b/CodeQualityTalk.Analyzers/CodeQualityTalk.Analyzers.csproj index de6084b..3040e92 100644 --- a/CodeQualityTalk.Analyzers/CodeQualityTalk.Analyzers.csproj +++ b/CodeQualityTalk.Analyzers/CodeQualityTalk.Analyzers.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/CodeQualityTalk.Analyzers/FactoryNameAnalyzer.cs b/CodeQualityTalk.Analyzers/FactoryNameAnalyzer.cs index 2715864..192a2ea 100644 --- a/CodeQualityTalk.Analyzers/FactoryNameAnalyzer.cs +++ b/CodeQualityTalk.Analyzers/FactoryNameAnalyzer.cs @@ -1,5 +1,6 @@ -using System.Collections.Immutable; -using System.Diagnostics; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -9,71 +10,73 @@ namespace CodeQualityTalk.Analyzers { - [DiagnosticAnalyzer( LanguageNames.CSharp )] public class FactoryNameAnalyzer : DiagnosticAnalyzer { - private static readonly DiagnosticDescriptor _diagnosticDescriptor = new DiagnosticDescriptor( + private static readonly DiagnosticDescriptor _diagnosticDescriptor = new( "MY001", "Types implementing IDocumentFactory must be named *Factory", "(Analyzer) The type {0} must have the Factory suffix because it implements IDocumentFactory", - "Naming", DiagnosticSeverity.Warning, true); + "Naming", + DiagnosticSeverity.Warning, + true ); - public override void Initialize(AnalysisContext context) + public override void Initialize( AnalysisContext context ) { context.EnableConcurrentExecution(); - context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - context.RegisterSemanticModelAction(AnalyzeSemanticModel); + context.ConfigureGeneratedCodeAnalysis( GeneratedCodeAnalysisFlags.None ); + context.RegisterSemanticModelAction( this.AnalyzeSemanticModel ); } - private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) + private void AnalyzeSemanticModel( SemanticModelAnalysisContext context ) { - new Walker(context).Visit(context.FilterTree.GetRoot()); + new Walker( context ).Visit( context.FilterTree.GetRoot() ); } public override ImmutableArray SupportedDiagnostics { get; } = [_diagnosticDescriptor]; - class Walker : CSharpSyntaxWalker + private class Walker : CSharpSyntaxWalker { private readonly SemanticModelAnalysisContext _context; - public Walker(SemanticModelAnalysisContext context) + public Walker( SemanticModelAnalysisContext context ) { - _context = context; + this._context = context; } - - public override void VisitClassDeclaration(ClassDeclarationSyntax node) + public override void VisitClassDeclaration( ClassDeclarationSyntax node ) { - this.InspectType(node); - base.VisitClassDeclaration(node); + this.InspectType( node ); + base.VisitClassDeclaration( node ); } - public override void VisitRecordDeclaration(RecordDeclarationSyntax node) + public override void VisitRecordDeclaration( RecordDeclarationSyntax node ) { - this.InspectType(node); - base.VisitRecordDeclaration(node); + this.InspectType( node ); + base.VisitRecordDeclaration( node ); } - public override void VisitStructDeclaration(StructDeclarationSyntax node) + public override void VisitStructDeclaration( StructDeclarationSyntax node ) { - this.InspectType(node); - base.VisitStructDeclaration(node); + this.InspectType( node ); + base.VisitStructDeclaration( node ); } - private void InspectType(TypeDeclarationSyntax type) + private void InspectType( TypeDeclarationSyntax type ) { - var typeSymbol = this._context.SemanticModel.GetDeclaredSymbol(type); + var typeSymbol = this._context.SemanticModel.GetDeclaredSymbol( type ); if ( typeSymbol != null && - !type.Identifier.Text.EndsWith("Factory") && - typeSymbol.AllInterfaces.Any(i => i.Name == "IDocumentFactory")) + !type.Identifier.Text.EndsWith( "Factory" ) && + typeSymbol.AllInterfaces.Any( i => i.Name == "IDocumentFactory" ) ) { - _context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, type.Identifier.GetLocation(), - type.Identifier.Text)); + this._context.ReportDiagnostic( + Diagnostic.Create( + _diagnosticDescriptor, + type.Identifier.GetLocation(), + type.Identifier.Text ) ); } - } } } diff --git a/CodeQualityTalk.ArchUnitTests/ArchitectureTests.cs b/CodeQualityTalk.ArchUnitTests/ArchitectureTests.cs index 2e4754e..b45555f 100644 --- a/CodeQualityTalk.ArchUnitTests/ArchitectureTests.cs +++ b/CodeQualityTalk.ArchUnitTests/ArchitectureTests.cs @@ -1,3 +1,5 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using ArchUnitNET.Domain; using ArchUnitNET.Loader; using ArchUnitNET.xUnit; @@ -10,17 +12,17 @@ namespace CodeQualityTalk.Tests; public class ArchitectureTests { private readonly Architecture _testedProjects = - new ArchLoader().LoadAssembly(typeof(IDocumentFactory).Assembly).Build(); + new ArchLoader().LoadAssembly( typeof(IDocumentFactory).Assembly ).Build(); [Fact] public void TypesDerivedFromIFactory_ShouldBe_NamedFactory() { Types() .That() - .ImplementInterface(typeof(IDocumentFactory)) + .ImplementInterface( typeof(IDocumentFactory) ) .Should() - .HaveName("^.*Factory$", true) - .Check(_testedProjects); + .HaveName( "^.*Factory$", true ) + .Check( this._testedProjects ); } [Fact] @@ -28,10 +30,10 @@ public void TypesDerivedFromIDocument_ShouldBe_InDocumentsNamespace() { Types() .That() - .ImplementInterface(typeof(IDocument)) + .ImplementInterface( typeof(IDocument) ) .Should() - .HaveFullName(@"^CodeQualityTalk\.Documents\..*", true) - .Check(_testedProjects); + .HaveFullName( @"^CodeQualityTalk\.Documents\..*", true ) + .Check( this._testedProjects ); } [Fact] @@ -39,9 +41,9 @@ public void Abstractions_CannotUse_DocumentsNamespace() { Types() .That() - .ResideInNamespace("CodeQualityTalk.Abstractions") + .ResideInNamespace( "CodeQualityTalk.Abstractions" ) .Should() - .NotDependOnAny(Types().That().DoNotResideInNamespace("CodeQualityTalk.Abstractions")) - .Check(_testedProjects); + .NotDependOnAny( Types().That().DoNotResideInNamespace( "CodeQualityTalk.Abstractions" ) ) + .Check( this._testedProjects ); } } \ No newline at end of file diff --git a/CodeQualityTalk.ArchUnitTests/CodeQualityTalk.ArchUnitTests.csproj b/CodeQualityTalk.ArchUnitTests/CodeQualityTalk.ArchUnitTests.csproj index d892566..15a1a96 100644 --- a/CodeQualityTalk.ArchUnitTests/CodeQualityTalk.ArchUnitTests.csproj +++ b/CodeQualityTalk.ArchUnitTests/CodeQualityTalk.ArchUnitTests.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/CodeQualityTalk.Metalama/Abstractions/DocumentCreationContext.cs b/CodeQualityTalk.Metalama/Abstractions/DocumentCreationContext.cs index 5cb42d7..917c12d 100644 --- a/CodeQualityTalk.Metalama/Abstractions/DocumentCreationContext.cs +++ b/CodeQualityTalk.Metalama/Abstractions/DocumentCreationContext.cs @@ -1,3 +1,5 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + namespace CodeQualityTalk.Abstractions; public record DocumentCreationContext( string OwnerId ); \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Abstractions/DocumentHelper.cs b/CodeQualityTalk.Metalama/Abstractions/DocumentHelper.cs index 3a1c122..903d160 100644 --- a/CodeQualityTalk.Metalama/Abstractions/DocumentHelper.cs +++ b/CodeQualityTalk.Metalama/Abstractions/DocumentHelper.cs @@ -1,8 +1,10 @@ -using CodeQualityTalk.Documents; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using CodeQualityTalk.Documents; namespace CodeQualityTalk.Abstractions; public static class DocumentHelper { - public static bool IsInvoice(IDocument document) => document is Invoice; + public static bool IsInvoice( IDocument document ) => document is Invoice; } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Abstractions/IDocument.cs b/CodeQualityTalk.Metalama/Abstractions/IDocument.cs index 255c1a4..e67b966 100644 --- a/CodeQualityTalk.Metalama/Abstractions/IDocument.cs +++ b/CodeQualityTalk.Metalama/Abstractions/IDocument.cs @@ -1,7 +1,10 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + namespace CodeQualityTalk.Abstractions; public interface IDocument { string OwnerId { get; } + string Name { get; } } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Abstractions/IDocumentFactory.cs b/CodeQualityTalk.Metalama/Abstractions/IDocumentFactory.cs index d5932c6..09a4dc8 100644 --- a/CodeQualityTalk.Metalama/Abstractions/IDocumentFactory.cs +++ b/CodeQualityTalk.Metalama/Abstractions/IDocumentFactory.cs @@ -1,9 +1,11 @@ -using Metalama.Extensions.Architecture.Aspects; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using Metalama.Extensions.Architecture.Aspects; namespace CodeQualityTalk.Abstractions; -[DerivedTypesMustRespectNamingConvention("*Factory")] +[DerivedTypesMustRespectNamingConvention( "*Factory" )] public interface IDocumentFactory { - IDocument CreateDocument(string name, DocumentCreationContext context); + IDocument CreateDocument( string name, DocumentCreationContext context ); } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Architecture/AdvancedFabric.cs b/CodeQualityTalk.Metalama/Architecture/AdvancedFabric.cs index 2b74b4a..0aa10d7 100644 --- a/CodeQualityTalk.Metalama/Architecture/AdvancedFabric.cs +++ b/CodeQualityTalk.Metalama/Architecture/AdvancedFabric.cs @@ -1,4 +1,6 @@ -using CodeQualityTalk.Abstractions; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using CodeQualityTalk.Abstractions; using Metalama.Framework.Aspects; using Metalama.Framework.Code; using Metalama.Framework.Diagnostics; @@ -11,21 +13,23 @@ public class AdvancedFabric : ProjectFabric { private const string _documentNamespace = "CodeQualityTalk.Documents"; - private static DiagnosticDefinition<(INamedType Type, string Namespace)> _warning = new("MY001", Severity.Warning, - "(Metalama) The '{0}' type must be in the '{1}' namespace."); + private static readonly DiagnosticDefinition<(INamedType Type, string Namespace)> _warning = new( + "MY001", + Severity.Warning, + "(Metalama) The '{0}' type must be in the '{1}' namespace." ); - public override void AmendProject(IProjectAmender amender) + public override void AmendProject( IProjectAmender amender ) { // Validate namespace. - amender.SelectReflectionType(typeof(IDocument)) - .ValidateInboundReferences(ValidateNamespace, ReferenceGranularity.Type, ReferenceKinds.BaseType); + amender.SelectReflectionType( typeof(IDocument) ) + .ValidateInboundReferences( ValidateNamespace, ReferenceGranularity.Type, ReferenceKinds.BaseType ); } - private static void ValidateNamespace(ReferenceValidationContext context) + private static void ValidateNamespace( ReferenceValidationContext context ) { - if (context.Origin.Namespace.FullName != _documentNamespace) + if ( context.Origin.Namespace.FullName != _documentNamespace ) { - context.Diagnostics.Report(_warning.WithArguments((context.Origin.Type, _documentNamespace))); + context.Diagnostics.Report( _warning.WithArguments( (context.Origin.Type, _documentNamespace) ) ); } } } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Architecture/Fabric.cs b/CodeQualityTalk.Metalama/Architecture/Fabric.cs index 9625244..c1a2ba6 100644 --- a/CodeQualityTalk.Metalama/Architecture/Fabric.cs +++ b/CodeQualityTalk.Metalama/Architecture/Fabric.cs @@ -1,4 +1,6 @@ -using Metalama.Extensions.Architecture; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using Metalama.Extensions.Architecture; using Metalama.Extensions.Architecture.Predicates; using Metalama.Framework.Fabrics; @@ -6,11 +8,11 @@ namespace CodeQualityTalk.Architecture; public class Fabric : ProjectFabric { - public override void AmendProject(IProjectAmender amender) + public override void AmendProject( IProjectAmender amender ) { // Validate dependencies. amender - .Select(c=>c.GlobalNamespace.GetDescendant("CodeQualityTalk.Documents")!) - .CannotBeUsedFrom( x => x.Namespace("CodeQualityTalk.Abstractions")); + .Select( c => c.GlobalNamespace.GetDescendant( "CodeQualityTalk.Documents" )! ) + .CannotBeUsedFrom( x => x.Namespace( "CodeQualityTalk.Abstractions" ) ); } } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/CodeQualityTalk.Metalama.csproj b/CodeQualityTalk.Metalama/CodeQualityTalk.Metalama.csproj index 1c9700d..de53fa0 100644 --- a/CodeQualityTalk.Metalama/CodeQualityTalk.Metalama.csproj +++ b/CodeQualityTalk.Metalama/CodeQualityTalk.Metalama.csproj @@ -8,11 +8,9 @@ CodeQualityTalk - - - + diff --git a/CodeQualityTalk.Metalama/CreditNote.cs b/CodeQualityTalk.Metalama/CreditNote.cs index e32471f..e3e03d1 100644 --- a/CodeQualityTalk.Metalama/CreditNote.cs +++ b/CodeQualityTalk.Metalama/CreditNote.cs @@ -1,15 +1,18 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk; internal class CreditNote : IDocument { - public string OwnerId { get; } - public string Name { get; } + public string OwnerId { get; } + + public string Name { get; } - public CreditNote(string ownerId, string name) + public CreditNote( string ownerId, string name ) { - OwnerId = ownerId; - Name = name; + this.OwnerId = ownerId; + this.Name = name; } } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Documents/Invoice.cs b/CodeQualityTalk.Metalama/Documents/Invoice.cs index a6a1b45..f563431 100644 --- a/CodeQualityTalk.Metalama/Documents/Invoice.cs +++ b/CodeQualityTalk.Metalama/Documents/Invoice.cs @@ -1,15 +1,18 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk.Documents; internal class Invoice : IDocument { - public string OwnerId { get; } - public string Name { get; } + public string OwnerId { get; } + + public string Name { get; } - public Invoice(string ownerId, string name) + public Invoice( string ownerId, string name ) { - OwnerId = ownerId; - Name = name; + this.OwnerId = ownerId; + this.Name = name; } } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Factories/CreditNoteCreator.cs b/CodeQualityTalk.Metalama/Factories/CreditNoteCreator.cs index a9e7b5b..e7edba0 100644 --- a/CodeQualityTalk.Metalama/Factories/CreditNoteCreator.cs +++ b/CodeQualityTalk.Metalama/Factories/CreditNoteCreator.cs @@ -1,9 +1,10 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk.Factories; public class CreditNoteCreator : IDocumentFactory { - public IDocument CreateDocument(string name, DocumentCreationContext context) - => new CreditNote(context.OwnerId, name); + public IDocument CreateDocument( string name, DocumentCreationContext context ) => new CreditNote( context.OwnerId, name ); } \ No newline at end of file diff --git a/CodeQualityTalk.Metalama/Factories/InvoiceFactory.cs b/CodeQualityTalk.Metalama/Factories/InvoiceFactory.cs index a3674a2..347ec41 100644 --- a/CodeQualityTalk.Metalama/Factories/InvoiceFactory.cs +++ b/CodeQualityTalk.Metalama/Factories/InvoiceFactory.cs @@ -1,3 +1,5 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; using CodeQualityTalk.Documents; @@ -5,6 +7,5 @@ namespace CodeQualityTalk.Factories; public class InvoiceFactory : IDocumentFactory { - public IDocument CreateDocument(string name, DocumentCreationContext context) - => new Invoice(context.OwnerId, name); + public IDocument CreateDocument( string name, DocumentCreationContext context ) => new Invoice( context.OwnerId, name ); } \ No newline at end of file diff --git a/CodeQualityTalk.Verifier/CodeQualityTalk.Verifier.csproj b/CodeQualityTalk.Verifier/CodeQualityTalk.Verifier.csproj index 6f1cd51..5d327e4 100644 --- a/CodeQualityTalk.Verifier/CodeQualityTalk.Verifier.csproj +++ b/CodeQualityTalk.Verifier/CodeQualityTalk.Verifier.csproj @@ -6,14 +6,12 @@ enable enable - - - + - + - + diff --git a/CodeQualityTalk.Verifier/Program.cs b/CodeQualityTalk.Verifier/Program.cs index 04161fb..499e950 100644 --- a/CodeQualityTalk.Verifier/Program.cs +++ b/CodeQualityTalk.Verifier/Program.cs @@ -1,44 +1,51 @@ -using Metalama.Framework.Code; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using Metalama.Framework.Code; using Metalama.Framework.Diagnostics; using Metalama.Framework.Workspaces; -if (args.Length != 1) +if ( args.Length != 1 ) { - Console.Error.WriteLine("Usage CodeQualityTalk.Verifier.exe "); + Console.Error.WriteLine( "Usage CodeQualityTalk.Verifier.exe " ); + return 1; } -var workspace = Workspace.Load(args[0]); +var workspace = Workspace.Load( args[0] ); // TypesDerivedFromIFactory_ShouldBe_NamedFactory workspace.SourceCode.Types - .Single(t => t.Name == "IDocumentFactory") + .Single( t => t.Name == "IDocumentFactory" ) .GetDerivedTypes() - .Where(t => !t.Name.EndsWith("Factory")) - .Report(Severity.Warning, "MY001", "The type name must end with Factory because it implements IDocumentFactory."); - + .Where( t => !t.Name.EndsWith( "Factory" ) ) + .Report( Severity.Warning, "MY001", "The type name must end with Factory because it implements IDocumentFactory." ); // TypesDerivedFromIDocument_ShouldBe_InDocumentsNamespace workspace.SourceCode.Types - .Single(t => t.Name == "IDocument") + .Single( t => t.Name == "IDocument" ) .GetDerivedTypes() - .Where(t => t.ContainingNamespace.FullName != "CodeQualityTalk.Documents") - .Report(Severity.Warning, "MY002", - "The type must be in the CodeQualityTalk.Documents namespace because it implements IDocument."); + .Where( t => t.ContainingNamespace.FullName != "CodeQualityTalk.Documents" ) + .Report( + Severity.Warning, + "MY002", + "The type must be in the CodeQualityTalk.Documents namespace because it implements IDocument." ); // Abstractions_CannotUse_DocumentsNamespace workspace.SourceCode.Types - .Where(t => t.ContainingNamespace.FullName == "CodeQualityTalk.Abstractions") - .SelectMany(t => t.GetOutboundReferences()) - .Where(r => - { - var ns = r.DestinationDeclaration.GetNamespace()!.FullName; - return ns.StartsWith("CodeQualityTalk") && ns != "CodeQualityTalk.Abstractions"; - }) - .Report(Severity.Warning, "MY003", - "The CodeQualityTalks.Abstractions namespace must only not have dependencies to other namespaces."); - -Console.WriteLine( - $"{DiagnosticReporter.ReportedWarnings + DiagnosticReporter.ReportedErrors} architecture violations found."); + .Where( t => t.ContainingNamespace.FullName == "CodeQualityTalk.Abstractions" ) + .SelectMany( t => t.GetOutboundReferences() ) + .Where( + r => + { + var ns = r.DestinationDeclaration.GetNamespace()!.FullName; + + return ns.StartsWith( "CodeQualityTalk" ) && ns != "CodeQualityTalk.Abstractions"; + } ) + .Report( + Severity.Warning, + "MY003", + "The CodeQualityTalks.Abstractions namespace must only not have dependencies to other namespaces." ); + +Console.WriteLine( $"{DiagnosticReporter.ReportedWarnings + DiagnosticReporter.ReportedErrors} architecture violations found." ); return DiagnosticReporter.ReportedErrors > 0 ? 2 : DiagnosticReporter.ReportedWarnings > 0 ? 1 : 0; \ No newline at end of file diff --git a/CodeQualityTalk/Abstractions/DocumentCreationContext.cs b/CodeQualityTalk/Abstractions/DocumentCreationContext.cs index 5cb42d7..917c12d 100644 --- a/CodeQualityTalk/Abstractions/DocumentCreationContext.cs +++ b/CodeQualityTalk/Abstractions/DocumentCreationContext.cs @@ -1,3 +1,5 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + namespace CodeQualityTalk.Abstractions; public record DocumentCreationContext( string OwnerId ); \ No newline at end of file diff --git a/CodeQualityTalk/Abstractions/DocumentHelper.cs b/CodeQualityTalk/Abstractions/DocumentHelper.cs index e3a59f0..0e6fa14 100644 --- a/CodeQualityTalk/Abstractions/DocumentHelper.cs +++ b/CodeQualityTalk/Abstractions/DocumentHelper.cs @@ -1,8 +1,10 @@ -using CodeQualityTalk.Documents; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +using CodeQualityTalk.Documents; namespace CodeQualityTalk.Abstractions; public static class DocumentHelper { - public static bool IsValueInvoice(IDocument document) => document is Invoice { IsValid: true }; + public static bool IsValidInvoice( IDocument document ) => document is Invoice { IsValid: true }; } \ No newline at end of file diff --git a/CodeQualityTalk/Abstractions/IDocument.cs b/CodeQualityTalk/Abstractions/IDocument.cs index 255c1a4..e67b966 100644 --- a/CodeQualityTalk/Abstractions/IDocument.cs +++ b/CodeQualityTalk/Abstractions/IDocument.cs @@ -1,7 +1,10 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + namespace CodeQualityTalk.Abstractions; public interface IDocument { string OwnerId { get; } + string Name { get; } } \ No newline at end of file diff --git a/CodeQualityTalk/Abstractions/IDocumentFactory.cs b/CodeQualityTalk/Abstractions/IDocumentFactory.cs index 2927e2d..023dbfe 100644 --- a/CodeQualityTalk/Abstractions/IDocumentFactory.cs +++ b/CodeQualityTalk/Abstractions/IDocumentFactory.cs @@ -1,6 +1,8 @@ -namespace CodeQualityTalk.Abstractions; +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + +namespace CodeQualityTalk.Abstractions; public interface IDocumentFactory { - IDocument CreateDocument(string name, DocumentCreationContext context); + IDocument CreateDocument( string name, DocumentCreationContext context ); } \ No newline at end of file diff --git a/CodeQualityTalk/CreditNote.cs b/CodeQualityTalk/CreditNote.cs index e32471f..e3e03d1 100644 --- a/CodeQualityTalk/CreditNote.cs +++ b/CodeQualityTalk/CreditNote.cs @@ -1,15 +1,18 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk; internal class CreditNote : IDocument { - public string OwnerId { get; } - public string Name { get; } + public string OwnerId { get; } + + public string Name { get; } - public CreditNote(string ownerId, string name) + public CreditNote( string ownerId, string name ) { - OwnerId = ownerId; - Name = name; + this.OwnerId = ownerId; + this.Name = name; } } \ No newline at end of file diff --git a/CodeQualityTalk/Documents/Invoice.cs b/CodeQualityTalk/Documents/Invoice.cs index d1d010f..6858d2b 100644 --- a/CodeQualityTalk/Documents/Invoice.cs +++ b/CodeQualityTalk/Documents/Invoice.cs @@ -1,17 +1,20 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk.Documents; internal class Invoice : IDocument { - public string OwnerId { get; } - public string Name { get; } + public string OwnerId { get; } + + public string Name { get; } - public Invoice(string ownerId, string name) + public Invoice( string ownerId, string name ) { - OwnerId = ownerId; - Name = name; + this.OwnerId = ownerId; + this.Name = name; } - public bool IsValid => string.IsNullOrEmpty(this.OwnerId); + public bool IsValid => string.IsNullOrEmpty( this.OwnerId ); } \ No newline at end of file diff --git a/CodeQualityTalk/Factories/CreditNoteCreator.cs b/CodeQualityTalk/Factories/CreditNoteCreator.cs index a9e7b5b..e7edba0 100644 --- a/CodeQualityTalk/Factories/CreditNoteCreator.cs +++ b/CodeQualityTalk/Factories/CreditNoteCreator.cs @@ -1,9 +1,10 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; namespace CodeQualityTalk.Factories; public class CreditNoteCreator : IDocumentFactory { - public IDocument CreateDocument(string name, DocumentCreationContext context) - => new CreditNote(context.OwnerId, name); + public IDocument CreateDocument( string name, DocumentCreationContext context ) => new CreditNote( context.OwnerId, name ); } \ No newline at end of file diff --git a/CodeQualityTalk/Factories/InvoiceFactory.cs b/CodeQualityTalk/Factories/InvoiceFactory.cs index a3674a2..347ec41 100644 --- a/CodeQualityTalk/Factories/InvoiceFactory.cs +++ b/CodeQualityTalk/Factories/InvoiceFactory.cs @@ -1,3 +1,5 @@ +// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. + using CodeQualityTalk.Abstractions; using CodeQualityTalk.Documents; @@ -5,6 +7,5 @@ namespace CodeQualityTalk.Factories; public class InvoiceFactory : IDocumentFactory { - public IDocument CreateDocument(string name, DocumentCreationContext context) - => new Invoice(context.OwnerId, name); + public IDocument CreateDocument( string name, DocumentCreationContext context ) => new Invoice( context.OwnerId, name ); } \ No newline at end of file diff --git a/Directory.Packages.Props b/Directory.Packages.Props new file mode 100644 index 0000000..23102cf --- /dev/null +++ b/Directory.Packages.Props @@ -0,0 +1,18 @@ + + + true + 2024.2.24 + $(MetalamaVersion) + + + + + + + + + + + + + \ No newline at end of file diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..f2bd515 --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,29 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify IDE code to run analysis without container (Applied in CI/CD pipeline) +ide: QDNET + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com)