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
Copy file name to clipboardExpand all lines: src/docs/Coding-Standards/Code-Layout.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,11 @@ How code is structured on the page and across files. Layout is not cosmetic —
9
9
10
10
## Formatting is automated
11
11
12
-
Formatting is a solved problem — hand it to a tool. Every repository runs a formatter and a linter, and they run in the editor, on commit, and in CI.
12
+
The standard owns the formatting rules; the tooling enforces them automatically — in the editor, on commit, and in CI. A repository's formatter and linter configuration is **derived from these standards**, so the machine applies what is written here rather than defining it.
13
13
14
-
-**Do not argue about formatting in review.** If the formatter accepts it, it is correct. Disagreements are settled by changing the formatter config, in its own PR.
15
-
-**The formatter config lives in the repository**, in version control, so humans and agents apply the same rules.
14
+
-**Do not argue about formatting in review.** The standard has already decided; if the formatter accepts it, it matches the standard.
15
+
-**Change a rule by changing the standard, not the config.** Adjust it here first, in its own PR; the derived tool config follows.
16
+
-**The config lives in the repository**, in version control and traceable to this standard, so humans and agents apply the same rules.
16
17
- This frees review attention for what actually matters: correctness, design, and clarity.
17
18
18
19
See [Shift Left → pre-commit hooks](../Ways-of-Working/Principles/Engineering-Practices.md#pre-commit-hooks) for where these gates run.
- Negated booleans (`isNotReady`, `notReady`) — a negative name forces a double negative at every use, and a value turns it into a riddle: does `notReady = false` mean it *is* ready? Name the positive (`isReady`) and negate at the point of use.
46
46
- Names that lie — a `getUser` that also writes to a cache is a name that lies. Rename or split.
Copy file name to clipboardExpand all lines: src/docs/Coding-Standards/PowerShell/index.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,20 @@ These hold for all PowerShell, whatever the construct:
26
26
-**`Verb-Noun` naming** with an approved verb (`Get-Verb`) and a singular noun: `Get-RepositorySecret`, not `Fetch-Secrets`.
27
27
-**`PascalCase`** for functions, parameters, public variables, and class members; `camelCase` for local variables.
28
28
-**Full cmdlet names, never aliases** (`Where-Object`, not `?`; `ForEach-Object`, not `%`).
29
-
-**One True Brace Style (OTBS)** — opening brace on the statement line, closing brace on its own line; always brace control blocks, even single statements.
30
29
-**Set `$ErrorActionPreference = 'Stop'`** at the top of every script and module so errors are terminating, not silently swallowed.
31
30
-**Emit objects, not formatted text.** Return rich objects and let the caller format; reserve `Write-Host` for genuine console UX, and use `Write-Verbose` / `Write-Information` for progress narration.
32
31
32
+
## Formatting
33
+
34
+
These rules define the layout; [PSScriptAnalyzer](#toolchain) enforces them (its settings are derived from this standard, not the reverse), so author to them and let the formatter apply them:
35
+
36
+
-**One True Brace Style (OTBS).** Opening brace on the statement line, closing brace on its own line; always brace control blocks, even a single statement. No blank line straight after `{` or before `}`, and `else` / `elseif` / `catch` / `finally` sit on the line with the preceding closing brace.
37
+
-**Indent with four spaces, never tabs**, and indent comment-based help to align with the function it documents.
38
+
-**One space around operators and after commas** (`$a -eq $b`, `@(1, 2, 3)`), and **one space between a type and the name** — `[string] $Name`, not `[string]$Name`.
39
+
-**`elseif` is one word**, not `else if`.
40
+
-**Blank lines separate logical blocks.** No trailing whitespace, and end every file with a single newline.
41
+
-**Keep code lines readable — aim for roughly 120 columns.** When a call grows long, prefer [splatting](#idioms-and-pitfalls) over backtick line-continuations.
42
+
33
43
## Idioms and pitfalls
34
44
35
45
Beyond the basics, these language-specific habits keep PowerShell correct and fast:
@@ -43,7 +53,7 @@ Beyond the basics, these language-specific habits keep PowerShell correct and fa
43
53
44
54
## Toolchain
45
55
46
-
The toolchain is the enforcement mechanism, and it runs in CI:
56
+
The toolchain enforces this standard in CI — it does not define it. The rules above are the source of truth; each tool's configuration is derived from them:
47
57
48
-
-**[PSScriptAnalyzer](https://github.com/PowerShell/PSScriptAnalyzer)** is the linter and formatter; code must pass it cleanly. The shared settings file is the source of truth for formatting — do not hand-format.
58
+
-**[PSScriptAnalyzer](https://github.com/PowerShell/PSScriptAnalyzer)** is the linter and formatter; its settings are derived from this standard, so passing it cleanly means matching the standard. Let it format — do not hand-format.
49
59
-**[Pester](https://pester.dev/)** is the test framework; test files are named `*.Tests.ps1`. See the [Testing baseline](../Testing.md).
Copy file name to clipboardExpand all lines: src/docs/Coding-Standards/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: The shared baseline every repository inherits, and the per-language
7
7
8
8
Standards for code written anywhere in the MSX ecosystem, in two tiers. The **baseline** encodes the [Principles](../Ways-of-Working/Principles/index.md) at the level of day-to-day code — how it is named, laid out, documented, tested, and secured — and applies in every language. The **per-language standards** add the idioms of one language or tool on top, and never contradict the baseline.
9
9
10
-
These standards are prescriptive: a change is expected to follow them, and the relevant linter or formatter is the enforcement mechanism wherever one exists.
10
+
These standards are prescriptive, and they are the source of truth: the relevant linter or formatter is the enforcement mechanism, and its configuration is derived from the standard — never the other way around. Wherever a rule can be checked mechanically, a linter derived from the standard enforces it in CI.
0 commit comments