Skip to content

Commit 9c04a44

Browse files
Settings file creation and validation (#2176)
* Add RuleOptionInfo class and update RuleInfo to include options for configurable rules * Add Test and New Cmdlets for PSScriptAnalyzer Settings Management - Implemented `New-ScriptAnalyzerSettingsFile` cmdlet to create a new PSScriptAnalyzer settings file, with options for presets and overwriting existing files. - Added `Test-ScriptAnalyzerSettingsFile` cmdlet to validate settings files, checking for parseability, rule existence, and valid options. - Created comprehensive tests for both cmdlets to ensure functionality and error handling. - Updated module manifest to export the new cmdlets. - Added documentation for both cmdlets, including usage examples and parameter descriptions. - Enhanced error messages in the strings resource file for better clarity during validation failures. * 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. * Apply docs suggestions from Sean's review Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com> * Add Copilot review suggestions --------- Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
1 parent 940024a commit 9c04a44

14 files changed

Lines changed: 2460 additions & 3 deletions

Engine/Commands/GetScriptAnalyzerRuleCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ protected override void ProcessRecord()
114114

115115
foreach (IRule rule in rules)
116116
{
117+
var ruleOptions = rule is ConfigurableRule
118+
? RuleOptionInfo.GetRuleOptions(rule)
119+
: null;
120+
117121
WriteObject(new RuleInfo(rule.GetName(), rule.GetCommonName(), rule.GetDescription(),
118-
rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity(), rule.GetType()));
122+
rule.GetSourceType(), rule.GetSourceName(), rule.GetSeverity(), rule.GetType(), ruleOptions));
119123
}
120124
}
121125
}

Engine/Commands/NewScriptAnalyzerSettingsFileCommand.cs

Lines changed: 537 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)