|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// |
| 3 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 4 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 5 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 6 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 7 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 8 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 9 | +// THE SOFTWARE. |
| 10 | + |
| 11 | +using System; |
| 12 | +using System.Collections.Generic; |
| 13 | +#if !CORECLR |
| 14 | +using System.ComponentModel.Composition; |
| 15 | +#endif |
| 16 | +using System.Globalization; |
| 17 | +using System.Linq; |
| 18 | +using System.Management.Automation.Language; |
| 19 | +using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic; |
| 20 | + |
| 21 | +namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules |
| 22 | +{ |
| 23 | + /// <summary> |
| 24 | + /// A class to walk an AST to check if consecutive assignment statements are aligned. |
| 25 | + /// </summary> |
| 26 | + #if !CORECLR |
| 27 | + [Export(typeof(IScriptRule))] |
| 28 | +#endif |
| 29 | + class AlignAssignmentStatement : ConfigurableRule |
| 30 | + { |
| 31 | + /// <summary> |
| 32 | + /// Analyzes the given ast to find if consecutive assignment statements are aligned. |
| 33 | + /// </summary> |
| 34 | + /// <param name="ast">AST to be analyzed. This should be non-null</param> |
| 35 | + /// <param name="fileName">Name of file that corresponds to the input AST.</param> |
| 36 | + /// <returns>A an enumerable type containing the violations</returns> |
| 37 | + public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) |
| 38 | + { |
| 39 | + if (ast == null) |
| 40 | + { |
| 41 | + throw new ArgumentNullException("ast"); |
| 42 | + } |
| 43 | + |
| 44 | + // your code goes here |
| 45 | + yield break; |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Retrieves the common name of this rule. |
| 50 | + /// </summary> |
| 51 | + public override string GetCommonName() |
| 52 | + { |
| 53 | + return string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementCommonName); |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Retrieves the description of this rule. |
| 58 | + /// </summary> |
| 59 | + public override string GetDescription() |
| 60 | + { |
| 61 | + return string.Format(CultureInfo.CurrentCulture, Strings.AlignAssignmentStatementDescription); |
| 62 | + } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Retrieves the name of this rule. |
| 66 | + /// </summary> |
| 67 | + public override string GetName() |
| 68 | + { |
| 69 | + return string.Format( |
| 70 | + CultureInfo.CurrentCulture, |
| 71 | + Strings.NameSpaceFormat, |
| 72 | + GetSourceName(), |
| 73 | + Strings.AlignAssignmentStatementName); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Retrieves the severity of the rule: error, warning or information. |
| 78 | + /// </summary> |
| 79 | + public override RuleSeverity GetSeverity() |
| 80 | + { |
| 81 | + return RuleSeverity.Warning; |
| 82 | + } |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Gets the severity of the returned diagnostic record: error, warning, or information. |
| 86 | + /// </summary> |
| 87 | + /// <returns></returns> |
| 88 | + public DiagnosticSeverity GetDiagnosticSeverity() |
| 89 | + { |
| 90 | + return DiagnosticSeverity.Warning; |
| 91 | + } |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Retrieves the name of the module/assembly the rule is from. |
| 95 | + /// </summary> |
| 96 | + public override string GetSourceName() |
| 97 | + { |
| 98 | + return string.Format(CultureInfo.CurrentCulture, Strings.SourceName); |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Retrieves the type of the rule, Builtin, Managed or Module. |
| 103 | + /// </summary> |
| 104 | + public override SourceType GetSourceType() |
| 105 | + { |
| 106 | + return SourceType.Builtin; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments