You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: CLAUDE.md
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ This style guide provides coding standards for dbatools PowerShell development t
13
13
**MODERN RULE**: Do NOT use `Mandatory = $true` or similar boolean attribute assignments. Boolean attributes do not require explicit value assignment in modern PowerShell.
14
14
15
15
```powershell
16
-
# CORRECT - Modern attribute syntax (no = $true)
16
+
# CORRECT - Modern attribute syntax (no = $true), Position preserved
17
17
param(
18
-
[Parameter(Mandatory)]
18
+
[Parameter(Mandatory, Position = 0)]
19
19
[string]$SqlInstance,
20
20
21
21
[Parameter(ValueFromPipeline)]
@@ -26,18 +26,28 @@ param(
26
26
27
27
# WRONG - Outdated PSv2 syntax (no longer needed)
28
28
param(
29
-
[Parameter(Mandatory = $true)]
29
+
[Parameter(Mandatory = $true, Position = 0)]
30
30
[string]$SqlInstance,
31
31
32
32
[Parameter(ValueFromPipeline = $true)]
33
33
[object[]]$InputObject
34
34
)
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
+
)
35
41
```
36
42
37
43
**Guidelines:**
38
44
- Use `[Parameter(Mandatory)]` not `[Parameter(Mandatory = $true)]`
39
45
- Use `[switch]` for boolean flags, not `[bool]` parameters
40
46
- 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`
41
51
42
52
### POWERSHELL v3 COMPATIBILITY
43
53
@@ -591,6 +601,7 @@ Don't add tests for existing functionality unless you're fixing a bug or adding
591
601
-[ ] Parameter names match original exactly without modification
592
602
-[ ] No backticks used for line continuation
593
603
-[ ] No `= $true` used in parameter attributes (use modern syntax)
604
+
-[ ] Position attributes preserved when modernizing parameters (critical for backward compatibility)
594
605
-[ ] Splats used only for 3+ parameters
595
606
596
607
**Version Compatibility:**
@@ -641,12 +652,13 @@ The golden rules for dbatools code:
641
652
642
653
1.**NEVER use backticks** - Use splats for 3+ parameters, direct syntax for 1-2
643
654
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