-
Notifications
You must be signed in to change notification settings - Fork 95
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 #1751 from riganti/validation-target-warning
control usage validators can produce warning + validate attached properties
- Loading branch information
Showing
8 changed files
with
272 additions
and
102 deletions.
There are no files selected for viewing
23 changes: 21 additions & 2 deletions
23
src/Framework/Framework/Compilation/Validation/ControlUsageError.cs
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 |
---|---|---|
@@ -1,18 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DotVVM.Framework.Binding.Properties; | ||
using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; | ||
|
||
namespace DotVVM.Framework.Compilation.Validation | ||
{ | ||
/// <summary> Represents an error or a warning reported by a control usage validation method. </summary> | ||
/// <seealso cref="ControlUsageValidatorAttribute"/> | ||
public class ControlUsageError | ||
{ | ||
public string ErrorMessage { get; } | ||
/// <summary> The error will be shown on the these syntax nodes. When empty, the start tag is underlined. </summary> | ||
public DothtmlNode[] Nodes { get; } | ||
public ControlUsageError(string message, IEnumerable<DothtmlNode?> nodes) | ||
/// <summary> Error - the page compilation will fail. Warning - the user will only be notified about the reported problem (in the log, for example). Other severities are currently not shown at all. </summary> | ||
public DiagnosticSeverity Severity { get; } = DiagnosticSeverity.Error; | ||
public ControlUsageError(string message, DiagnosticSeverity severity, IEnumerable<DothtmlNode?> nodes) | ||
{ | ||
ErrorMessage = message; | ||
Nodes = nodes.Where(n => n != null).ToArray()!; | ||
Severity = severity; | ||
} | ||
public ControlUsageError(string message, IEnumerable<DothtmlNode?> nodes) : this(message, DiagnosticSeverity.Error, nodes) { } | ||
public ControlUsageError(string message, params DothtmlNode?[] nodes) : this(message, DiagnosticSeverity.Error, nodes.AsEnumerable()) { } | ||
public ControlUsageError(string message, DiagnosticSeverity severity, params DothtmlNode?[] nodes) : this(message, severity, nodes.AsEnumerable()) { } | ||
|
||
public override string ToString() | ||
{ | ||
var core = $"{Severity} {ErrorMessage}"; | ||
var someToken = Nodes.SelectMany(n => n.Tokens).FirstOrDefault(); | ||
if (someToken == null) | ||
return core; | ||
else | ||
return $"{core} (at {someToken.LineNumber}:{someToken.ColumnNumber})"; | ||
} | ||
public ControlUsageError(string message, params DothtmlNode?[] nodes) : this(message, nodes.AsEnumerable()) { } | ||
} | ||
} |
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.