Skip to content

Commit 5353cf6

Browse files
CLAUDE.md - Add guidance for preserving Position attributes when modernizing parameter syntax
When modernizing parameter attributes from PSv2 style (Mandatory = $true) to modern style (Mandatory), always preserve Position attributes to avoid breaking changes. Removing Position attributes breaks positional parameter usage (e.g., Test-DbaAvailabilityGroup $instance). Added: - Critical guideline about preserving Position attributes - Code examples showing correct vs incorrect modernization - Updated verification checklist with Position attribute requirement - Added golden rule #3 about never removing Position attributes Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
1 parent 1195c89 commit 5353cf6

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

CLAUDE.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ This style guide provides coding standards for dbatools PowerShell development t
1313
**MODERN RULE**: Do NOT use `Mandatory = $true` or similar boolean attribute assignments. Boolean attributes do not require explicit value assignment in modern PowerShell.
1414

1515
```powershell
16-
# CORRECT - Modern attribute syntax (no = $true)
16+
# CORRECT - Modern attribute syntax (no = $true), Position preserved
1717
param(
18-
[Parameter(Mandatory)]
18+
[Parameter(Mandatory, Position = 0)]
1919
[string]$SqlInstance,
2020
2121
[Parameter(ValueFromPipeline)]
@@ -26,18 +26,28 @@ param(
2626
2727
# WRONG - Outdated PSv2 syntax (no longer needed)
2828
param(
29-
[Parameter(Mandatory = $true)]
29+
[Parameter(Mandatory = $true, Position = 0)]
3030
[string]$SqlInstance,
3131
3232
[Parameter(ValueFromPipeline = $true)]
3333
[object[]]$InputObject
3434
)
35+
36+
# ALSO WRONG - Removing Position when it existed in original
37+
param(
38+
[Parameter(Mandatory)] # Missing Position = 0 (breaking change!)
39+
[string]$SqlInstance
40+
)
3541
```
3642

3743
**Guidelines:**
3844
- Use `[Parameter(Mandatory)]` not `[Parameter(Mandatory = $true)]`
3945
- Use `[switch]` for boolean flags, not `[bool]` parameters
4046
- Keep non-boolean attributes with values: `[Parameter(ValueFromPipelineByPropertyName = "Name")]`
47+
- **CRITICAL**: Always preserve `Position` attributes when modernizing - removing them is a breaking change
48+
- `[Parameter(Mandatory, Position = 0)]` NOT `[Parameter(Mandatory)]` if Position was present
49+
- Positional parameters allow users to call commands without parameter names
50+
- Example: `Test-DbaAvailabilityGroup $instance` instead of `Test-DbaAvailabilityGroup -SqlInstance $instance`
4151

4252
### POWERSHELL v3 COMPATIBILITY
4353

@@ -591,6 +601,7 @@ Don't add tests for existing functionality unless you're fixing a bug or adding
591601
- [ ] Parameter names match original exactly without modification
592602
- [ ] No backticks used for line continuation
593603
- [ ] No `= $true` used in parameter attributes (use modern syntax)
604+
- [ ] Position attributes preserved when modernizing parameters (critical for backward compatibility)
594605
- [ ] Splats used only for 3+ parameters
595606

596607
**Version Compatibility:**
@@ -641,12 +652,13 @@ The golden rules for dbatools code:
641652

642653
1. **NEVER use backticks** - Use splats for 3+ parameters, direct syntax for 1-2
643654
2. **NEVER use `= $true` in parameter attributes** - Use modern syntax: `[Parameter(Mandatory)]` not `[Parameter(Mandatory = $true)]`
644-
3. **NEVER use `::new()` syntax** - Use `New-Object` for PowerShell v3 compatibility
645-
4. **NEVER "fix" Microsoft SMO typos** - Properties like `AvailabilityDateabaseId` are correct as-is
646-
5. **ALWAYS align hashtables** - Equals signs must line up vertically
647-
6. **ALWAYS preserve comments** - Every comment stays exactly as written
648-
7. **ALWAYS use double quotes** - SQL Server module standard
649-
8. **ALWAYS use unique variable names** - Prevent scope collisions
650-
9. **ALWAYS use descriptive splatnames** - `$splatConnection`, not `$splat`
651-
10. **ALWAYS register new commands** - Add to both dbatools.psd1 and dbatools.psm1
652-
11. **ALWAYS use singular nouns** - Command names use singular, not plural
655+
3. **NEVER remove Position attributes** - Preserve `Position = 0` when modernizing parameters to avoid breaking changes
656+
4. **NEVER use `::new()` syntax** - Use `New-Object` for PowerShell v3 compatibility
657+
5. **NEVER "fix" Microsoft SMO typos** - Properties like `AvailabilityDateabaseId` are correct as-is
658+
6. **ALWAYS align hashtables** - Equals signs must line up vertically
659+
7. **ALWAYS preserve comments** - Every comment stays exactly as written
660+
8. **ALWAYS use double quotes** - SQL Server module standard
661+
9. **ALWAYS use unique variable names** - Prevent scope collisions
662+
10. **ALWAYS use descriptive splatnames** - `$splatConnection`, not `$splat`
663+
11. **ALWAYS register new commands** - Add to both dbatools.psd1 and dbatools.psm1
664+
12. **ALWAYS use singular nouns** - Command names use singular, not plural

0 commit comments

Comments
 (0)