Closed iRon7 closed 9 months ago
1st one is not specific to custom rules and second is probably a good use for a custom rule, which a community member could publish as this is a narrow use cases as most PSSA users don't use custom rules in first place
The PSScriptAnalyzer is a static code checker for PowerShell modules and scripts where it allows for creating custom rules in PowerShell. Yet, there aren't any rules to check whether the custom rules are written according the best practices (which potentially could lead to pitfalls). The examples at Creating custom rules could be improved for at least the known best practices:
+=
) to build a collection(don't say here it it is ok for small collection, as you can't determine how big the collection will be at runtime.)
There is a static value assigned for the
RuleSuppressionID
which will not help to differentiate between specificRuleName
warnings.(I assume this just an example, but simple might misslead someone.)
For the later point, I think it should be possible to write a rule that checks whether there is a
VariableExpressionAst
(rather than aStringConstantExpressionAst
, or nothing) assigned to theRuleSuppressionID
property of the[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]
object.