|
| 1 | +# PSScriptAnalyzer rule template guidance |
| 2 | + |
| 3 | +The [rule-template.md](rule-template.md) file illustrates the structure of the PSScriptAnalyzer rule |
| 4 | +articles. Replace all placeholder text, then remove optional sections that don't apply. |
| 5 | + |
| 6 | +## Required content |
| 7 | + |
| 8 | +Every rule article starts with these YAML frontmatter fields: |
| 9 | + |
| 10 | +- `description` |
| 11 | +- `ms.date` |
| 12 | +- `ms.topic: reference` |
| 13 | +- `title` |
| 14 | + |
| 15 | +Place the H1, severity line, and default-state line immediately after the frontmatter. Follow them |
| 16 | +with `## Description`, which explains the diagnostic, why it matters, and the preferred alternative. |
| 17 | + |
| 18 | +Each rule must have an `## Example` section. Each example includes a `### Noncompliant` code block |
| 19 | +followed by a `### Compliant` alternative. Give each scenario an H3 heading and use H4 headings for |
| 20 | +its noncompliant and compliant code pair. |
| 21 | + |
| 22 | +Every rule article includes `## Configure rule` after its example or examples. For a configurable |
| 23 | +rule, include a `Rules` hashtable entry. For an always-enabled or otherwise nonconfigurable rule, |
| 24 | +use the following text. |
| 25 | + |
| 26 | +```markdown |
| 27 | +This rule is always enabled and isn't configurable. Use one of the following methods to avoid using |
| 28 | +this rule: |
| 29 | + |
| 30 | +- Create a custom rule configuration file to include only the rules you want or exclude the rules |
| 31 | + you don't want. |
| 32 | +- Add the appropriate rule suppression attributes to your code to suppress the rule for specific |
| 33 | + code blocks. For more information, see the _Suppressing rules_ section of |
| 34 | + [Using PSScriptAnalyzer][02]. |
| 35 | +``` |
| 36 | + |
| 37 | +## Optional sections |
| 38 | + |
| 39 | +Use an additional H2 explanatory section between `## Description` and the example when readers need |
| 40 | +context before reviewing the code. Existing articles use this space for compatibility profile |
| 41 | +information, reference tables, supported values, and remediation guidance. For examples, see the |
| 42 | +following articles. |
| 43 | + |
| 44 | +- [AvoidUsingConvertToSecureStringWithPlainText](Rules/AvoidUsingConvertToSecureStringWithPlainText.md) |
| 45 | +- [UseConsistentParameterSetName](Rules/UseConsistentParameterSetName.md) |
| 46 | +- [UseConstrainedLanguageMode](Rules/UseConstrainedLanguageMode.md) |
| 47 | + |
| 48 | +When the rule is configurable, include `## Parameters` section after `## Configure rule`. Use an H3 |
| 49 | +heading for each setting and document what it controls, accepted values, and its default value. |
| 50 | + |
| 51 | +After the `## Configure rule` and any parameter sections, include a `## Suppression` section only |
| 52 | +when the rule needs specific suppression syntax or examples. Otherwise, link readers to the general |
| 53 | +_Suppressing rules_ guidance from **Configure rule**. |
| 54 | + |
| 55 | +In the `## Further reading` section, provide links to additional resources that help readers |
| 56 | +understand the rule, its context, or related topics. |
| 57 | + |
| 58 | +## Final checks |
| 59 | + |
| 60 | +- Include `## Configure rule` for every rule article. |
| 61 | +- Include `### Parameters` only for configurable settings that need individual documentation. |
| 62 | +- Pair noncompliant code with a practical compliant alternative. |
| 63 | +- Remove all unused optional headings, placeholder text, and link definitions. |
0 commit comments