Skip to content

Commit ab9baf5

Browse files
committed
Enhance ScriptAnalyzer settings file validation and documentation
- Update Helper.cs to return null for empty output paths instead of an empty array. - Add new error message for invalid option types in Strings.resx. - Extend tests for New-ScriptAnalyzerSettingsFile to check for new keys: CustomRulePath, IncludeDefaultRules, and RecurseCustomRulePath. - Modify Test-ScriptAnalyzerSettingsFile tests to validate output and error handling for various scenarios, including type mismatches and invalid values. - Improve documentation for New-ScriptAnalyzerSettingsFile and Test-ScriptAnalyzerSettingsFile to clarify behavior and parameters, including handling of custom rules and output format.
1 parent a09c6de commit ab9baf5

8 files changed

Lines changed: 818 additions & 249 deletions

Engine/Commands/NewScriptAnalyzerSettingsFileCommand.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ private string GenerateFromPreset(string presetName)
188188
WriteSeverityArray(sb, parsed.Severities);
189189
sb.AppendLine();
190190

191+
sb.AppendLine(" # Paths to modules or directories containing custom rules.");
192+
sb.AppendLine(" # When specified, these rules are loaded in addition to (or instead");
193+
sb.AppendLine(" # of) the built-in rules, depending on IncludeDefaultRules.");
194+
sb.AppendLine(" # Note: Relative paths are resolved from the caller's working directory,");
195+
sb.AppendLine(" # not the location of this settings file.");
196+
WriteStringArray(sb, "CustomRulePath", parsed.CustomRulePath);
197+
sb.AppendLine();
198+
199+
sb.AppendLine(" # When set to $true and CustomRulePath is specified, built-in rules");
200+
sb.AppendLine(" # are loaded alongside custom rules. Has no effect without CustomRulePath.");
201+
sb.AppendLine(string.Format(CultureInfo.InvariantCulture,
202+
" IncludeDefaultRules = {0}", parsed.IncludeDefaultRules ? "$true" : "$false"));
203+
sb.AppendLine();
204+
205+
sb.AppendLine(" # When set to $true, searches sub-folders under CustomRulePath for");
206+
sb.AppendLine(" # additional rule modules. Has no effect without CustomRulePath.");
207+
sb.AppendLine(string.Format(CultureInfo.InvariantCulture,
208+
" RecurseCustomRulePath = {0}", parsed.RecurseCustomRulePath ? "$true" : "$false"));
209+
sb.AppendLine();
210+
191211
sb.AppendLine(" # Per-rule configuration. Only configurable rules appear here.");
192212
sb.AppendLine(" # Values from the preset are shown; other properties use defaults.");
193213

@@ -256,6 +276,24 @@ private string GenerateFromAllRules()
256276
WriteSeverityArray(sb, Enumerable.Empty<string>());
257277
sb.AppendLine();
258278

279+
sb.AppendLine(" # Paths to modules or directories containing custom rules.");
280+
sb.AppendLine(" # When specified, these rules are loaded in addition to (or instead");
281+
sb.AppendLine(" # of) the built-in rules, depending on IncludeDefaultRules.");
282+
sb.AppendLine(" # Note: Relative paths are resolved from the caller's working directory,");
283+
sb.AppendLine(" # not the location of this settings file.");
284+
WriteStringArray(sb, "CustomRulePath", Enumerable.Empty<string>());
285+
sb.AppendLine();
286+
287+
sb.AppendLine(" # When set to $true and CustomRulePath is specified, built-in rules");
288+
sb.AppendLine(" # are loaded alongside custom rules. Has no effect without CustomRulePath.");
289+
sb.AppendLine(" IncludeDefaultRules = $false");
290+
sb.AppendLine();
291+
292+
sb.AppendLine(" # When set to $true, searches sub-folders under CustomRulePath for");
293+
sb.AppendLine(" # additional rule modules. Has no effect without CustomRulePath.");
294+
sb.AppendLine(" RecurseCustomRulePath = $false");
295+
sb.AppendLine();
296+
259297
sb.AppendLine(" # Per-rule configuration. Only configurable rules appear here.");
260298
sb.AppendLine(" Rules = @{");
261299

0 commit comments

Comments
 (0)