forked from maroontress/StyleChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoDocumentationConfig.cs
More file actions
103 lines (93 loc) · 3.04 KB
/
NoDocumentationConfig.cs
File metadata and controls
103 lines (93 loc) · 3.04 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
namespace StyleChecker.Analyzers.Config;
using System.Collections.Generic;
using System.Linq;
using Maroontress.Oxbind;
using Maroontress.Roastery;
using StyleChecker.Analyzers.Document.NoDocumentation;
/// <summary>
/// The configuration data of NoDocumentation analyzer.
/// </summary>
[ForElement(Analyzer.DiagnosticId, Namespace)]
public sealed class NoDocumentationConfig(
[Multiple] IEnumerable<NoDocumentationConfig.Ignore> ignoreElements)
: AbstractConfig
{
/// <summary>
/// Initializes a new instance of the <see cref="NoDocumentationConfig"/>
/// class.
/// </summary>
[Ignored]
public NoDocumentationConfig()
: this([])
{
}
private IEnumerable<Ignore> IgnoreElements { get; } = ignoreElements;
/// <summary>
/// Gets the attribute classes, with which the element annotated and
/// the elements it contains are ignored.
/// </summary>
/// <returns>
/// The attribute classes.
/// </returns>
public IEnumerable<string> GetInclusiveAttributes()
{
return IgnoreElements.Where(e => e.IsInclusive())
.Select(e => e.With)
.FilterNonNullReference();
}
/// <summary>
/// Gets the attribute classes, with which the element annotated only
/// is ignored.
/// </summary>
/// <returns>
/// The attribute classes.
/// </returns>
public IEnumerable<string> GetAttributes()
{
return IgnoreElements.Where(e => !e.IsInclusive())
.Select(e => e.With)
.FilterNonNullReference();
}
/// <inheritdoc/>
public override IEnumerable<WhereWhy> Validate()
{
return IgnoreElements.SelectMany(e => e.Validate());
}
/// <summary>
/// Represents the attribute class with which the element annotated
/// must be ignored.
/// </summary>
[ForElement("ignore", Namespace)]
public sealed class Ignore(
[ForAttribute("with")] string? with,
[ForAttribute("inclusive")] BindResult<string>? inclusiveResult)
: Validateable
{
/// <summary>
/// Gets the attribute class.
/// </summary>
public string? With { get; } = with;
/// <summary>
/// Gets whether the element only is ignored or all the elements it
/// contains are ignored.
/// </summary>
public BindResult<string>? InclusiveResult { get; } = inclusiveResult;
/// <inheritdoc/>
public IEnumerable<WhereWhy> Validate()
=> ParseKit.ValidateBoolean(
InclusiveResult,
"invalid boolean value of 'inclusive' attribute");
/// <summary>
/// Returns the whether the range to be ignored is only the element
/// itself or all the elements it contains.
/// </summary>
/// <returns>
/// <c>false</c> if the range to be ignored is only the element,
/// <c>true</c> otherwise.
/// </returns>
public bool IsInclusive()
{
return ParseKit.ToBooleanValue(InclusiveResult, false);
}
}
}