From 5c848056c52595dfa8f68e2a62b290e211b62935 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 20 Apr 2022 20:27:53 +0300 Subject: [PATCH] Add more contextual information to diagnostics --- CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs | 6 ++++-- CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs | 6 ++++-- CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs | 2 +- CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs | 2 +- .../ParameterMustBeLastIfNonRequiredAnalyzer.cs | 8 ++++++-- CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs | 8 ++++++-- .../ParameterMustBeSingleIfNonRequiredAnalyzer.cs | 8 ++++++-- .../ParameterMustBeSingleIfNonScalarAnalyzer.cs | 8 ++++++-- CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs | 6 ++++-- CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs | 6 ++++-- 10 files changed, 42 insertions(+), 18 deletions(-) diff --git a/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs index 08efe92..22841d1 100644 --- a/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs @@ -15,7 +15,8 @@ public class OptionMustHaveUniqueNameAnalyzer : AnalyzerBase : base( "Options must have unique names", "This option's name must be unique within the command (comparison IS NOT case sensitive). " + - "Specified name: '{0}'.") + "Specified name: `{0}`. " + + "Property bound to another option with the same name: `{1}`.") { } @@ -55,7 +56,8 @@ public class OptionMustHaveUniqueNameAnalyzer : AnalyzerBase context.ReportDiagnostic( CreateDiagnostic( propertyDeclaration.Identifier.GetLocation(), - option.Name + option.Name, + otherProperty.Name ) ); } diff --git a/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs index f271cb5..2c06d93 100644 --- a/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs @@ -14,7 +14,8 @@ public class OptionMustHaveUniqueShortNameAnalyzer : AnalyzerBase : base( "Options must have unique short names", "This option's short name must be unique within the command (comparison IS case sensitive). " + - "Specified short name: '{0}'.") + "Specified short name: `{0}` " + + "Property bound to another option with the same short name: `{1}`.") { } @@ -54,7 +55,8 @@ public class OptionMustHaveUniqueShortNameAnalyzer : AnalyzerBase context.ReportDiagnostic( CreateDiagnostic( propertyDeclaration.Identifier.GetLocation(), - option.ShortName + option.ShortName, + otherProperty.Name ) ); } diff --git a/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs index a5e2dbe..e49d1bb 100644 --- a/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs @@ -13,7 +13,7 @@ public class OptionMustHaveValidNameAnalyzer : AnalyzerBase : base( "Options must have valid names", "This option's name must be at least 2 characters long and must start with a letter. " + - "Specified name: '{0}'.") + "Specified name: `{0}`.") { } diff --git a/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs index e3b8265..838293c 100644 --- a/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs @@ -13,7 +13,7 @@ public class OptionMustHaveValidShortNameAnalyzer : AnalyzerBase : base( "Option short names must be letter characters", "This option's short name must be a single letter character. " + - "Specified short name: '{0}'.") + "Specified short name: `{0}`.") { } diff --git a/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs index afe96b2..4508227 100644 --- a/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs @@ -13,7 +13,8 @@ public class ParameterMustBeLastIfNonRequiredAnalyzer : AnalyzerBase public ParameterMustBeLastIfNonRequiredAnalyzer() : base( "Parameters marked as non-required must be the last in order", - "This parameter is non-required so it must be the last in order (its order must be highest within the command).") + "This parameter is non-required so it must be the last in order (its order must be highest within the command). " + + "Property bound to another non-required parameter: `{0}`.") { } @@ -48,7 +49,10 @@ public class ParameterMustBeLastIfNonRequiredAnalyzer : AnalyzerBase if (otherParameter.Order > parameter.Order) { context.ReportDiagnostic( - CreateDiagnostic(propertyDeclaration.Identifier.GetLocation()) + CreateDiagnostic( + propertyDeclaration.Identifier.GetLocation(), + otherProperty.Name + ) ); } } diff --git a/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs index f698a89..985b56e 100644 --- a/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs @@ -13,7 +13,8 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase public ParameterMustBeLastIfNonScalarAnalyzer() : base( "Parameters of non-scalar types must be the last in order", - "This parameter has a non-scalar type so it must be the last in order (its order must be highest within the command).") + "This parameter has a non-scalar type so it must be the last in order (its order must be highest within the command). " + + "Property bound to another non-scalar parameter: `{0}`.") { } @@ -48,7 +49,10 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase if (otherParameter.Order > parameter.Order) { context.ReportDiagnostic( - CreateDiagnostic(propertyDeclaration.Identifier.GetLocation()) + CreateDiagnostic( + propertyDeclaration.Identifier.GetLocation(), + otherProperty.Name + ) ); } } diff --git a/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs index 73db9bb..832b90e 100644 --- a/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs @@ -13,7 +13,8 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzer : AnalyzerBase public ParameterMustBeSingleIfNonRequiredAnalyzer() : base( "Parameters marked as non-required are limited to one per command", - "This parameter is non-required so it must be the only such parameter in the command.") + "This parameter is non-required so it must be the only such parameter in the command. " + + "Property bound to another non-required parameter: `{0}`.") { } @@ -48,7 +49,10 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzer : AnalyzerBase if (otherParameter.IsRequired == false) { context.ReportDiagnostic( - CreateDiagnostic(propertyDeclaration.Identifier.GetLocation()) + CreateDiagnostic( + propertyDeclaration.Identifier.GetLocation(), + otherProperty.Name + ) ); } } diff --git a/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs index e014c14..be66a4a 100644 --- a/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs @@ -13,7 +13,8 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase public ParameterMustBeSingleIfNonScalarAnalyzer() : base( "Parameters of non-scalar types are limited to one per command", - "This parameter has a non-scalar type so it must be the only such parameter in the command.") + "This parameter has a non-scalar type so it must be the only such parameter in the command. " + + "Property bound to another non-scalar parameter: `{0}`.") { } @@ -48,7 +49,10 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase if (!otherParameter.IsScalar()) { context.ReportDiagnostic( - CreateDiagnostic(propertyDeclaration.Identifier.GetLocation()) + CreateDiagnostic( + propertyDeclaration.Identifier.GetLocation(), + otherProperty.Name + ) ); } } diff --git a/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs index d7fde82..d23121e 100644 --- a/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs @@ -15,7 +15,8 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase : base( "Parameters must have unique names", "This parameter's name must be unique within the command (comparison IS NOT case sensitive). " + - "Specified name: '{0}'.") + "Specified name: `{0}`. " + + "Property bound to another parameter with the same name: `{1}`.") { } @@ -55,7 +56,8 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase context.ReportDiagnostic( CreateDiagnostic( propertyDeclaration.Identifier.GetLocation(), - parameter.Name + parameter.Name, + otherProperty.Name ) ); } diff --git a/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs index f4ed009..2caa3d3 100644 --- a/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs @@ -14,7 +14,8 @@ public class ParameterMustHaveUniqueOrderAnalyzer : AnalyzerBase : base( "Parameters must have unique order", "This parameter's order must be unique within the command. " + - "Specified order: {0}.") + "Specified order: {0}. " + + "Property bound to another parameter with the same order: `{1}`.") { } @@ -48,7 +49,8 @@ public class ParameterMustHaveUniqueOrderAnalyzer : AnalyzerBase context.ReportDiagnostic( CreateDiagnostic( propertyDeclaration.Identifier.GetLocation(), - parameter.Order + parameter.Order, + otherProperty.Name ) ); }