-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from StefanMaron/development
New rule LC0034 Set explicit Extensible property
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; | ||
using Microsoft.Dynamics.Nav.CodeAnalysis; | ||
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; | ||
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols; | ||
using System.Collections.Immutable; | ||
|
||
namespace BusinessCentral.LinterCop.Design | ||
{ | ||
[DiagnosticAnalyzer] | ||
public class Rule0034ExtensiblePropertyShouldAlwaysBeSet : DiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0034ExtensiblePropertyShouldAlwaysBeSet); | ||
|
||
public override void Initialize(AnalysisContext context) | ||
=> context.RegisterSymbolAction(new Action<SymbolAnalysisContext>(this.CheckForMissingExtensibleProperty), new SymbolKind[] { | ||
SymbolKind.Table, | ||
SymbolKind.Page, | ||
SymbolKind.Report | ||
}); | ||
|
||
private void CheckForMissingExtensibleProperty(SymbolAnalysisContext ctx) | ||
{ | ||
// The Extensible property (and DeclaredAccessibility) is supported from runtime versions 4.0 or greater. | ||
var manifest = AppSourceCopConfigurationProvider.GetManifest(ctx.Compilation); | ||
if (manifest.Runtime < RuntimeVersion.Fall2019) return; | ||
|
||
if (ctx.Symbol.IsObsoletePending || ctx.Symbol.IsObsoleteRemoved) return; | ||
|
||
if (ctx.Symbol.GetTypeSymbol().Kind == SymbolKind.Table && ctx.Symbol.DeclaredAccessibility != Accessibility.Public) return; | ||
if (ctx.Symbol.GetTypeSymbol().Kind == SymbolKind.Page && ((IPageTypeSymbol)ctx.Symbol.GetTypeSymbol()).PageType == PageTypeKind.API) return; | ||
|
||
if (ctx.Symbol.GetProperty(PropertyKind.Extensible) is null) | ||
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0034ExtensiblePropertyShouldAlwaysBeSet, ctx.Symbol.GetLocation(), new object[] { Accessibility.Public.ToString().ToLower() })); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters