Skip to content

Commit 59ccace

Browse files
author
Kapil Borle
committed
Format and add inline doc to public fields
1 parent 6f022f1 commit 59ccace

File tree

4 files changed

+314
-233
lines changed

4 files changed

+314
-233
lines changed

Engine/Generic/ConfigurableScriptRule.cs

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,33 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
88
// This is still an experimental class. Use at your own risk!
99
public abstract class ConfigurableScriptRule : IScriptRule
1010
{
11-
// Configurable rule properties should define a default value
12-
// because if reading the configuration fails
13-
// we use the property's default value
11+
/// <summary>
12+
/// Indicates if the rule is enabled or not.
13+
///
14+
/// If the rule is enabled ScriptAnalyzer engine will run it
15+
/// otherwise it will not.
16+
///
17+
/// Configurable rule properties should define a default value
18+
/// because if reading the configuration fails we use the
19+
/// property's default value
20+
/// </summary>
1421
[ConfigurableRuleProperty(defaultValue: false)]
1522
public bool Enable { get; protected set; }
1623

24+
/// <summary>
25+
/// Initialize the configurable properties of a configurable rule.
26+
/// </summary>
1727
protected ConfigurableScriptRule()
1828
{
1929
SetDefaultValues();
2030
}
2131

32+
/// <summary>
33+
/// Sets the configurable properties of the rule.
34+
///
35+
/// Properties having ConfigurableRuleProperty attribute are called configurable properties.
36+
/// </summary>
37+
/// <param name="paramValueMap">A dictionary that maps parameter name to it value. Must be non-null</param>
2238
public virtual void ConfigureRule(IDictionary<string, object> paramValueMap)
2339
{
2440
if (paramValueMap == null)
@@ -45,6 +61,50 @@ public virtual void ConfigureRule(IDictionary<string, object> paramValueMap)
4561
}
4662
}
4763

64+
/// <summary>
65+
/// Analyzes the given abstract syntax tree (AST) and returns diagnostic records based on the analysis.
66+
/// </summary>
67+
/// <param name="ast">AST representing the file content</param>
68+
/// <param name="fileName">Path of the file corresponding to the AST</param>
69+
/// <returns>The results of the analysis</returns>
70+
public abstract IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName);
71+
72+
/// <summary>
73+
/// Retrieves the Common name of the rule.
74+
/// </summary>
75+
/// <returns>The name of the rule.</returns>
76+
public abstract string GetCommonName();
77+
78+
/// <summary>
79+
/// Retrieves the description of the rule.
80+
/// </summary>
81+
/// <returns>The description of the rule.</returns>
82+
public abstract string GetDescription();
83+
84+
/// <summary>
85+
/// Retrieves the name of the rule.
86+
/// </summary>
87+
/// <returns>The name of the rule.</returns>
88+
public abstract string GetName();
89+
90+
/// <summary>
91+
/// Retrieves severity of the rule.
92+
/// </summary>
93+
/// <returns>The severity of the rule.</returns>
94+
public abstract RuleSeverity GetSeverity();
95+
96+
/// <summary>
97+
/// Retrieves the source name of the rule.
98+
/// </summary>
99+
/// <returns>The source name of the rule.</returns>
100+
public abstract string GetSourceName();
101+
102+
/// <summary>
103+
/// Retrieves the source type of the rule.
104+
/// </summary>
105+
/// <returns>The source type of the rule.</returns>
106+
public abstract SourceType GetSourceType();
107+
48108
private void SetDefaultValues()
49109
{
50110
foreach (var property in GetConfigurableProperties())
@@ -82,21 +142,23 @@ private Object GetDefaultValue(PropertyInfo property)
82142

83143
return ((ConfigurableRulePropertyAttribute)attr).DefaultValue;
84144
}
85-
86-
public abstract IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName);
87-
public abstract string GetCommonName();
88-
public abstract string GetDescription();
89-
public abstract string GetName();
90-
public abstract RuleSeverity GetSeverity();
91-
public abstract string GetSourceName();
92-
public abstract SourceType GetSourceType();
93145
}
94146

147+
/// <summary>
148+
/// The attribute class to designate if a property is configurable or not.
149+
/// </summary>
95150
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
96151
public class ConfigurableRulePropertyAttribute : Attribute
97152
{
153+
/// <summary>
154+
/// Default value of the property that the attribute decorates.
155+
/// </summary>
98156
public object DefaultValue { get; private set; }
99157

158+
/// <summary>
159+
/// Initialize the attribute with the decorated property's default value.
160+
/// </summary>
161+
/// <param name="defaultValue"></param>
100162
public ConfigurableRulePropertyAttribute(object defaultValue)
101163
{
102164
if (defaultValue == null)

Rules/PlaceCloseBrace.cs

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2828
#endif
2929
public class PlaceCloseBrace : ConfigurableScriptRule
3030
{
31+
/// <summary>
32+
/// Indicates if there should or should not be an empty line before a close brace.
33+
///
34+
/// Default value if false.
35+
/// </summary>
3136
[ConfigurableRuleProperty(defaultValue:false)]
3237
public bool NoEmptyLineBefore { get; protected set; }
3338

3439
/// <summary>
35-
/// Analyzes the given ast to find the [violation]
40+
/// Analyzes the given ast to find violations.
3641
/// </summary>
3742
/// <param name="ast">AST to be analyzed. This should be non-null</param>
3843
/// <param name="fileName">Name of file that corresponds to the input AST.</param>
@@ -102,6 +107,67 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
102107
return diagnosticRecords;
103108
}
104109

110+
/// <summary>
111+
/// Retrieves the common name of this rule.
112+
/// </summary>
113+
public override string GetCommonName()
114+
{
115+
return string.Format(CultureInfo.CurrentCulture, Strings.PlaceCloseBraceCommonName);
116+
}
117+
118+
/// <summary>
119+
/// Retrieves the description of this rule.
120+
/// </summary>
121+
public override string GetDescription()
122+
{
123+
return string.Format(CultureInfo.CurrentCulture, Strings.PlaceCloseBraceDescription);
124+
}
125+
126+
/// <summary>
127+
/// Retrieves the name of this rule.
128+
/// </summary>
129+
public override string GetName()
130+
{
131+
return string.Format(
132+
CultureInfo.CurrentCulture,
133+
Strings.NameSpaceFormat,
134+
GetSourceName(),
135+
Strings.PlaceCloseBraceName);
136+
}
137+
138+
/// <summary>
139+
/// Retrieves the severity of the rule: error, warning or information.
140+
/// </summary>
141+
public override RuleSeverity GetSeverity()
142+
{
143+
return RuleSeverity.Information;
144+
}
145+
146+
/// <summary>
147+
/// Gets the severity of the returned diagnostic record: error, warning, or information.
148+
/// </summary>
149+
/// <returns></returns>
150+
public DiagnosticSeverity GetDiagnosticSeverity()
151+
{
152+
return DiagnosticSeverity.Information;
153+
}
154+
155+
/// <summary>
156+
/// Retrieves the name of the module/assembly the rule is from.
157+
/// </summary>
158+
public override string GetSourceName()
159+
{
160+
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
161+
}
162+
163+
/// <summary>
164+
/// Retrieves the type of the rule, Builtin, Managed or Module.
165+
/// </summary>
166+
public override SourceType GetSourceType()
167+
{
168+
return SourceType.Builtin;
169+
}
170+
105171
private DiagnosticRecord GetViolationForBraceShouldNotFollowEmptyLine(
106172
Token[] tokens,
107173
int closeBracePos,
@@ -258,75 +324,9 @@ private List<Token> GetTokens(Ast ast, List<Token> tokens, ref Dictionary<Ast, L
258324
return tokenSet;
259325
}
260326

261-
/// <summary>
262-
/// Retrieves the error message of this rule
263-
/// </summary>
264-
private string GetError(string errorString)
327+
private static string GetError(string errorString)
265328
{
266329
return string.Format(CultureInfo.CurrentCulture, errorString);
267330
}
268-
269-
/// <summary>
270-
/// Retrieves the common name of this rule.
271-
/// </summary>
272-
public override string GetCommonName()
273-
{
274-
return string.Format(CultureInfo.CurrentCulture, Strings.PlaceCloseBraceCommonName);
275-
}
276-
277-
/// <summary>
278-
/// Retrieves the description of this rule.
279-
/// </summary>
280-
public override string GetDescription()
281-
{
282-
return string.Format(CultureInfo.CurrentCulture, Strings.PlaceCloseBraceDescription);
283-
}
284-
285-
/// <summary>
286-
/// Retrieves the name of this rule.
287-
/// </summary>
288-
public override string GetName()
289-
{
290-
return string.Format(
291-
CultureInfo.CurrentCulture,
292-
Strings.NameSpaceFormat,
293-
GetSourceName(),
294-
Strings.PlaceCloseBraceName);
295-
}
296-
297-
/// <summary>
298-
/// Retrieves the severity of the rule: error, warning or information.
299-
/// </summary>
300-
public override RuleSeverity GetSeverity()
301-
{
302-
return RuleSeverity.Information;
303-
}
304-
305-
/// <summary>
306-
/// Gets the severity of the returned diagnostic record: error, warning, or information.
307-
/// </summary>
308-
/// <returns></returns>
309-
public DiagnosticSeverity GetDiagnosticSeverity()
310-
{
311-
return DiagnosticSeverity.Information;
312-
}
313-
314-
/// <summary>
315-
/// Retrieves the name of the module/assembly the rule is from.
316-
/// </summary>
317-
public override string GetSourceName()
318-
{
319-
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
320-
}
321-
322-
/// <summary>
323-
/// Retrieves the type of the rule, Builtin, Managed or Module.
324-
/// </summary>
325-
public override SourceType GetSourceType()
326-
{
327-
return SourceType.Builtin;
328-
}
329-
330-
331331
}
332332
}

0 commit comments

Comments
 (0)