Skip to content

Commit ae0b374

Browse files
Adding DscExamplesPresent rule scaffolding
1 parent 2af9cb8 commit ae0b374

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

Rules/DscExamplesPresent.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10+
// THE SOFTWARE.
11+
//
12+
13+
using System;
14+
using System.Collections.Generic;
15+
using System.Linq;
16+
using System.Management.Automation.Language;
17+
using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic;
18+
using System.ComponentModel.Composition;
19+
using System.Globalization;
20+
21+
namespace Microsoft.Windows.Powershell.ScriptAnalyzer.BuiltinRules
22+
{
23+
/// <summary>
24+
/// DscExamplesExist: Checks that DSC examples for given resource are present
25+
/// </summary>
26+
[Export(typeof(IDSCResourceRule))]
27+
public class DscExamplesPresent : IDSCResourceRule
28+
{
29+
/// <summary>
30+
/// AnalyzeDSCResource: Analyzes given DSC Resource
31+
/// </summary>
32+
/// <param name="ast">The script's ast</param>
33+
/// <param name="fileName">The name of the script file being analyzed</param>
34+
/// <returns>The results of the analysis</returns>
35+
public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName)
36+
{
37+
38+
}
39+
40+
/// <summary>
41+
/// AnalyzeDSCClass: Analyzes given DSC class
42+
/// </summary>
43+
/// <param name="ast"></param>
44+
/// <param name="fileName"></param>
45+
/// <returns></returns>
46+
public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
47+
{
48+
49+
}
50+
51+
52+
/// <summary>
53+
/// GetName: Retrieves the name of this rule.
54+
/// </summary>
55+
/// <returns>The name of this rule</returns>
56+
public string GetName()
57+
{
58+
return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.DscExamplesPresent);
59+
}
60+
61+
/// <summary>
62+
/// GetCommonName: Retrieves the Common name of this rule.
63+
/// </summary>
64+
/// <returns>The common name of this rule</returns>
65+
public string GetCommonName()
66+
{
67+
return string.Format(CultureInfo.CurrentCulture, Strings.DscExamplesPresentCommonName);
68+
}
69+
70+
/// <summary>
71+
/// GetDescription: Retrieves the description of this rule.
72+
/// </summary>
73+
/// <returns>The description of this rule</returns>
74+
public string GetDescription()
75+
{
76+
return string.Format(CultureInfo.CurrentCulture, Strings.DscExamplesPresentDescription);
77+
}
78+
79+
/// <summary>
80+
/// GetSourceType: Retrieves the type of the rule: builtin, managed or module.
81+
/// </summary>
82+
public SourceType GetSourceType()
83+
{
84+
return SourceType.Builtin;
85+
}
86+
87+
/// <summary>
88+
/// GetSeverity: Retrieves the severity of the rule: error, warning or information.
89+
/// </summary>
90+
/// <returns></returns>
91+
public RuleSeverity GetSeverity()
92+
{
93+
return RuleSeverity.Information;
94+
}
95+
96+
/// <summary>
97+
/// GetSourceName: Retrieves the module/assembly name the rule is from.
98+
/// </summary>
99+
public string GetSourceName()
100+
{
101+
return string.Format(CultureInfo.CurrentCulture, Strings.DSCSourceName);
102+
}
103+
}
104+
105+
}

Rules/Strings.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,4 +690,13 @@
690690
<data name="UseOutputTypeCorrectlyName" xml:space="preserve">
691691
<value>UseOutputTypeCorrectly</value>
692692
</data>
693+
<data name="DscExamplesPresent" xml:space="preserve">
694+
<value>DscExamplesPresent</value>
695+
</data>
696+
<data name="DscExamplesPresentCommonName" xml:space="preserve">
697+
<value>DSC examples are present</value>
698+
</data>
699+
<data name="DscExamplesPresentDescription" xml:space="preserve">
700+
<value>Every DSC resource module should contain folder "Examples" with sample configurations for every resource. Sample configurations should have resource name they are demonstrating in the title.</value>
701+
</data>
693702
</root>

0 commit comments

Comments
 (0)