-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation about non-nullable, non-reference record properties
[Required] should be used if the non-nullable value will always be set.
- Loading branch information
1 parent
2a3f1ab
commit fb4ab32
Showing
60 changed files
with
350 additions
and
145 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
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,17 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet.Insights | ||
{ | ||
public static class DiagnosticIds | ||
{ | ||
public const string MissingICsvRecordInterface = "NI0001"; | ||
public const string CsvRecordNotMarkedAsPartial = "NI0002"; | ||
public const string MultipleKustoPartioningKeys = "NI0003"; | ||
public const string NoKustoPartitioningKeyDefined = "NI0004"; | ||
public const string IgnoredKustoPartitioningKey = "NI0005"; | ||
public const string MissingKustoTypeAttribute = "NI0006"; | ||
public const string MissingNoKustoDDLAttribute = "NI0007"; | ||
public const string NonNullablePropertyNotMarkedAsRequired = "NI0008"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace NuGet.Insights | ||
{ | ||
public class ValidatePropertyNullability : IPropertyVisitor | ||
{ | ||
public void OnProperty(PropertyVisitorContext context, IPropertySymbol symbol, string prettyPropType) | ||
{ | ||
if (context.HasNoDDLAttribute | ||
|| symbol.Type.IsReferenceType | ||
|| PropertyHelper.IsIgnoredInKusto(symbol) | ||
|| PropertyHelper.IsNullable(context, symbol, out _) | ||
|| PropertyHelper.IsRequired(context, symbol)) | ||
{ | ||
return; | ||
} | ||
|
||
context.GeneratorExecutionContext.ReportDiagnostic(Diagnostic.Create( | ||
new DiagnosticDescriptor( | ||
id: DiagnosticIds.NonNullablePropertyNotMarkedAsRequired, | ||
title: $"Non-nullable property is not marked as [Required].", | ||
messageFormat: $"Non-nullable value type {symbol.ToDisplayString()} is not marked as [Required]. Either make it nullable or mark it as [Required].", | ||
CsvRecordGenerator.Category, | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true), | ||
symbol.Locations.FirstOrDefault() ?? Location.None)); | ||
} | ||
|
||
public void Finish(PropertyVisitorContext context) | ||
{ | ||
} | ||
|
||
public string GetResult() | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.