Skip to content

Rules for Rules #1964

Closed
Closed
@iRon7

Description

@iRon7

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:

  • It violates the best practice rule Rule request: Avoid using the Assignment by Addition Operator (+=) 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 specific RuleName 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 a StringConstantExpressionAst, or nothing) assigned to the RuleSuppressionID property of the [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord] object.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions