blob: 6b76688873e6377fa310878dd0ef63c6e21c4616 [file] [log] [blame]
Zachary Turner1122be82016-09-07 18:28:55 +00001using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Text;
6using YamlDotNet.Serialization;
7using YamlDotNet.Serialization.NamingConventions;
8
9namespace LLVM.ClangTidy
10{
11 public class CheckInfo
12 {
13 [YamlAlias("Name")]
14 public string Name { get; set; }
15
16 [YamlAlias("Label")]
17 public string Label { get; set; }
18
19 [YamlAlias("Description")]
20 public string Desc { get; set; }
21
22 [YamlAlias("Category")]
23 public string Category { get; set; }
24 }
25
26 /// <summary>
27 /// Reads the list of checks from Yaml and builds a description of each one.
28 /// This list of checks is then used by the PropertyGrid to determine what
29 /// items to display.
30 /// </summary>
31 public static class CheckDatabase
32 {
33 static CheckInfo[] Checks_ = null;
34
35 class CheckRoot
36 {
37 [YamlAlias("Checks")]
38 public CheckInfo[] Checks { get; set; }
39 }
40
41 static CheckDatabase()
42 {
43 using (StringReader Reader = new StringReader(Resources.ClangTidyChecks))
44 {
45 Deserializer D = new Deserializer(namingConvention: new PascalCaseNamingConvention());
46 var Root = D.Deserialize<CheckRoot>(Reader);
47 Checks_ = Root.Checks;
48
49 HashSet<string> Names = new HashSet<string>();
50 foreach (var Check in Checks_)
51 {
52 if (Names.Contains(Check.Name))
Zachary Turner8c9a7d72016-09-07 19:41:19 +000053 continue;
Zachary Turner1122be82016-09-07 18:28:55 +000054 Names.Add(Check.Name);
55 }
56 }
57 }
58
59 public static IEnumerable<CheckInfo> Checks
60 {
61 get
62 {
63 return Checks_;
64 }
65 }
66 }
67}