Skip to content

Rules for Rules #1964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iRon7 opened this issue Feb 4, 2024 · 1 comment
Closed

Rules for Rules #1964

iRon7 opened this issue Feb 4, 2024 · 1 comment

Comments

@iRon7
Copy link

iRon7 commented Feb 4, 2024

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.

@bergmeister
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants