-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleProvider.cs
More file actions
60 lines (48 loc) · 2.54 KB
/
RuleProvider.cs
File metadata and controls
60 lines (48 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using JulianVerdurmen.SlnxValidator.Core.ValidationResults;
namespace JulianVerdurmen.SlnxValidator.Core.Reporting;
public static class RuleProvider
{
private static (ValidationErrorCode Key, Rule Rule) Create(
ValidationErrorCode code, string name, string description,
RuleSeverity severity = RuleSeverity.MAJOR) =>
(code, new Rule(code.ToCode(), name, description, severity));
private static readonly Dictionary<ValidationErrorCode, Rule> Rules =
new (ValidationErrorCode Key, Rule Rule)[]
{
Create(ValidationErrorCode.FileNotFound,
"SLNX file not found",
"The specified .slnx file does not exist."),
Create(ValidationErrorCode.InvalidExtension,
"Invalid solution file extension",
"The input file does not have a .slnx extension.",
RuleSeverity.MINOR),
Create(ValidationErrorCode.NotATextFile,
"SLNX file is not a text file",
"The file is binary and cannot be parsed as XML."),
Create(ValidationErrorCode.InvalidXml,
"Invalid XML",
"The .slnx file is not valid XML."),
Create(ValidationErrorCode.ReferencedFileNotFound,
"Referenced file not found",
"A file referenced in a <File Path=\"...\"> element does not exist on disk."),
Create(ValidationErrorCode.InvalidWildcardUsage,
"Invalid wildcard usage",
"A <File Path=\"...\"> element contains a wildcard pattern, which is not supported.",
RuleSeverity.MINOR),
Create(ValidationErrorCode.XsdViolation,
"XSD schema violation",
"The XML structure violates the .slnx schema."),
Create(ValidationErrorCode.RequiredFileDoesntExistOnSystem,
"Required file does not exist on the system",
"A file required by '--required-files' does not exist on the file system."),
Create(ValidationErrorCode.RequiredFileNotReferencedInSolution,
"Required file not referenced in solution",
"A file required by '--required-files' exists on the file system but is not referenced as a <File> element in the solution."),
}.ToDictionary(e => e.Key, e => e.Rule);
public static Rule Get(ValidationErrorCode code)
{
if (Rules.TryGetValue(code, out var rule))
return rule;
throw new ArgumentOutOfRangeException(nameof(code), code, null);
}
}