Use DefaultRazorDiagnostic in DefaultDirectiveSyntaxTreePass

This commit is contained in:
Ajay Bhargav Baaskaran 2017-12-14 16:10:02 -08:00
parent 4164821e4c
commit 6bbd063e26
5 changed files with 27 additions and 24 deletions

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
{ {
private const string DiagnosticPrefix = "RZ"; private const string DiagnosticPrefix = "RZ";
public static readonly RazorDiagnosticDescriptor ViewComponent_CannotFindMethod = internal static readonly RazorDiagnosticDescriptor ViewComponent_CannotFindMethod =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3900", $"{DiagnosticPrefix}3900",
() => ViewComponentResources.ViewComponent_CannotFindMethod, () => ViewComponentResources.ViewComponent_CannotFindMethod,
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_AmbiguousMethods = internal static readonly RazorDiagnosticDescriptor ViewComponent_AmbiguousMethods =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3901", $"{DiagnosticPrefix}3901",
() => ViewComponentResources.ViewComponent_AmbiguousMethods, () => ViewComponentResources.ViewComponent_AmbiguousMethods,
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_AsyncMethod_ShouldReturnTask = internal static readonly RazorDiagnosticDescriptor ViewComponent_AsyncMethod_ShouldReturnTask =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3902", $"{DiagnosticPrefix}3902",
() => ViewComponentResources.ViewComponent_AsyncMethod_ShouldReturnTask, () => ViewComponentResources.ViewComponent_AsyncMethod_ShouldReturnTask,
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_ShouldReturnValue = internal static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_ShouldReturnValue =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3903", $"{DiagnosticPrefix}3903",
() => ViewComponentResources.ViewComponent_SyncMethod_ShouldReturnValue, () => ViewComponentResources.ViewComponent_SyncMethod_ShouldReturnValue,
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_CannotReturnTask = internal static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_CannotReturnTask =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3904", $"{DiagnosticPrefix}3904",
() => ViewComponentResources.ViewComponent_SyncMethod_CannotReturnTask, () => ViewComponentResources.ViewComponent_SyncMethod_CannotReturnTask,

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
private const string DiagnosticPrefix = "RZ"; private const string DiagnosticPrefix = "RZ";
public static readonly RazorDiagnosticDescriptor ViewComponent_CannotFindMethod = internal static readonly RazorDiagnosticDescriptor ViewComponent_CannotFindMethod =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3900", $"{DiagnosticPrefix}3900",
() => ViewComponentResources.ViewComponent_CannotFindMethod, () => ViewComponentResources.ViewComponent_CannotFindMethod,
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_AmbiguousMethods = internal static readonly RazorDiagnosticDescriptor ViewComponent_AmbiguousMethods =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3901", $"{DiagnosticPrefix}3901",
() => ViewComponentResources.ViewComponent_AmbiguousMethods, () => ViewComponentResources.ViewComponent_AmbiguousMethods,
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_AsyncMethod_ShouldReturnTask = internal static readonly RazorDiagnosticDescriptor ViewComponent_AsyncMethod_ShouldReturnTask =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3902", $"{DiagnosticPrefix}3902",
() => ViewComponentResources.ViewComponent_AsyncMethod_ShouldReturnTask, () => ViewComponentResources.ViewComponent_AsyncMethod_ShouldReturnTask,
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_ShouldReturnValue = internal static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_ShouldReturnValue =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3903", $"{DiagnosticPrefix}3903",
() => ViewComponentResources.ViewComponent_SyncMethod_ShouldReturnValue, () => ViewComponentResources.ViewComponent_SyncMethod_ShouldReturnValue,
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_CannotReturnTask = internal static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_CannotReturnTask =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3904", $"{DiagnosticPrefix}3904",
() => ViewComponentResources.ViewComponent_SyncMethod_CannotReturnTask, () => ViewComponentResources.ViewComponent_SyncMethod_CannotReturnTask,
@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return diagnostic; return diagnostic;
} }
public static readonly RazorDiagnosticDescriptor PageDirective_CannotBeImported = internal static readonly RazorDiagnosticDescriptor PageDirective_CannotBeImported =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}3905", $"{DiagnosticPrefix}3905",
() => Resources.PageDirectiveCannotBeImported, () => Resources.PageDirectiveCannotBeImported,

View File

@ -45,11 +45,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
var directiveStart = block.Children.First(child => !child.IsBlock && ((Span)child).Kind == SpanKindInternal.Transition).Start; var directiveStart = block.Children.First(child => !child.IsBlock && ((Span)child).Kind == SpanKindInternal.Transition).Start;
var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length; var errorLength = /* @ */ 1 + SectionDirective.Directive.Directive.Length;
var error = RazorDiagnostic.Create( var error = RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(new SourceSpan(directiveStart, errorLength));
new RazorError(
LegacyResources.FormatParseError_Sections_Cannot_Be_Nested(LegacyResources.SectionExample_CS),
directiveStart,
errorLength));
chunkGenerator.Diagnostics.Add(error); chunkGenerator.Diagnostics.Add(error);
} }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// General Errors ID Offset = 0 // General Errors ID Offset = 0
public static readonly RazorDiagnosticDescriptor Directive_BlockDirectiveCannotBeImported = internal static readonly RazorDiagnosticDescriptor Directive_BlockDirectiveCannotBeImported =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}0000", $"{DiagnosticPrefix}0000",
() => Resources.BlockDirectiveCannotBeImported, () => Resources.BlockDirectiveCannotBeImported,
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Semantic Errors ID Offset = 2000 // Semantic Errors ID Offset = 2000
public static readonly RazorDiagnosticDescriptor CodeTarget_UnsupportedExtension = internal static readonly RazorDiagnosticDescriptor CodeTarget_UnsupportedExtension =
new RazorDiagnosticDescriptor( new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}2000", $"{DiagnosticPrefix}2000",
() => Resources.Diagnostic_CodeTarget_UnsupportedExtension, () => Resources.Diagnostic_CodeTarget_UnsupportedExtension,
@ -55,6 +55,16 @@ namespace Microsoft.AspNetCore.Razor.Language
return RazorDiagnostic.Create(Parsing_DuplicateDirective, location, directive); return RazorDiagnostic.Create(Parsing_DuplicateDirective, location, directive);
} }
internal static readonly RazorDiagnosticDescriptor Parsing_SectionsCannotBeNested =
new RazorDiagnosticDescriptor(
$"{DiagnosticPrefix}2002",
() => LegacyResources.ParseError_Sections_Cannot_Be_Nested,
RazorDiagnosticSeverity.Error);
public static RazorDiagnostic CreateParsing_SectionsCannotBeNested(SourceSpan location)
{
return RazorDiagnostic.Create(Parsing_SectionsCannotBeNested, location, LegacyResources.SectionExample_CS);
}
#endregion #endregion
#region TagHelper Errors #region TagHelper Errors
@ -116,7 +126,7 @@ namespace Microsoft.AspNetCore.Razor.Language
() => Resources.TagHelper_InvalidBoundAttributeName, () => Resources.TagHelper_InvalidBoundAttributeName,
RazorDiagnosticSeverity.Error); RazorDiagnosticSeverity.Error);
public static RazorDiagnostic CreateTagHelper_InvalidBoundAttributeName( public static RazorDiagnostic CreateTagHelper_InvalidBoundAttributeName(
string tagHelperDisplayName, string tagHelperDisplayName,
string propertyDisplayName, string propertyDisplayName,
string invalidName, string invalidName,
char invalidCharacter) char invalidCharacter)

View File

@ -182,11 +182,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
new SourceLocation(16, 0, 16), new SourceLocation(16, 0, 16),
7))); 7)));
erroredChunkGenerator.Diagnostics.Add( erroredChunkGenerator.Diagnostics.Add(
RazorDiagnostic.Create( RazorDiagnosticFactory.CreateParsing_SectionsCannotBeNested(
new RazorError( new SourceSpan(new SourceLocation(15, 0, 15), 8)));
LegacyResources.FormatParseError_Sections_Cannot_Be_Nested(LegacyResources.SectionExample_CS),
new SourceLocation(15, 0, 15),
8)));
// Act & Assert // Act & Assert
ParseDocumentTest( ParseDocumentTest(