Skip to content

Commit

Permalink
Merge pull request #272 from tinestaric/SemicolonInternalToolTip
Browse files Browse the repository at this point in the history
New Rules for Procedure Semicolon, Internal Procedures and ToolTip punctuation
  • Loading branch information
Arthurvdv authored Nov 4, 2023
2 parents 0b5d0f6 + 3393f8f commit 5bf98ac
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 51 deletions.
2 changes: 1 addition & 1 deletion BusinessCentral.LinterCop.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
29 changes: 29 additions & 0 deletions Design/Rule0024SemicolonAfterProcedureDeclaration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Immutable;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;

namespace BusinessCentral.LinterCop.Design
{
[DiagnosticAnalyzer]
public class Rule0024SemicolonAfterProcedureDeclaration : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0024SemicolonAfterProcedureDeclaration);

public override void Initialize(AnalysisContext context) => context.RegisterSyntaxNodeAction(new Action<SyntaxNodeAnalysisContext>(this.AnalyzeSemicolonAfterProcedureDeclaration), SyntaxKind.MethodDeclaration);

private void AnalyzeSemicolonAfterProcedureDeclaration(SyntaxNodeAnalysisContext ctx)
{
if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return;
if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return;

MethodDeclarationSyntax syntax = ctx.Node as MethodDeclarationSyntax;

if (syntax.SemicolonToken.Kind != SyntaxKind.None)
{
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0024SemicolonAfterProcedureDeclaration, syntax.SemicolonToken.GetLocation()));
}
}
}
}
29 changes: 29 additions & 0 deletions Design/Rule0025InternalProcedureModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Immutable;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;

namespace BusinessCentral.LinterCop.Design
{
[DiagnosticAnalyzer]
public class Rule0025InternalProcedureModifier : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0025InternalProcedureModifier);

public override void Initialize(AnalysisContext context) => context.RegisterSyntaxNodeAction(new Action<SyntaxNodeAnalysisContext>(this.AnalyzeInternalProcedures), SyntaxKind.MethodDeclaration);

private void AnalyzeInternalProcedures(SyntaxNodeAnalysisContext ctx)
{
if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return;
if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return;

MethodDeclarationSyntax syntax = ctx.Node as MethodDeclarationSyntax;
SyntaxNodeOrToken accessModifier = syntax.ProcedureKeyword.GetPreviousToken();

if (accessModifier.Kind != SyntaxKind.LocalKeyword && accessModifier.Kind != SyntaxKind.InternalKeyword)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0025InternalProcedureModifier, syntax.ProcedureKeyword.GetLocation()));

}
}
}
32 changes: 32 additions & 0 deletions Design/Rule0026ToolTipPunctuation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Immutable;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;

namespace BusinessCentral.LinterCop.Design
{
[DiagnosticAnalyzer]
public class Rule0026ToolTipPunctuation : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0026ToolTipPunctuation);

public override void Initialize(AnalysisContext context) => context.RegisterSyntaxNodeAction(new Action<SyntaxNodeAnalysisContext>(this.AnalyzeToolTipPunctuation), SyntaxKind.PageField, SyntaxKind.PageAction);

private void AnalyzeToolTipPunctuation(SyntaxNodeAnalysisContext ctx)
{
if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return;
if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return;

PropertySyntax tooltipProperty = ctx.Node.GetProperty("ToolTip");

if (tooltipProperty != null)
{
string tooltipValue = tooltipProperty.Value.GetText().ToString();
if (!tooltipValue.EndsWith(".'"))
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0026ToolTipPunctuation, tooltipProperty.GetLocation()));
}

}
}
}
Loading

0 comments on commit 5bf98ac

Please sign in to comment.