Skip to content

Commit 72f8720

Browse files
Standards own the linter config; define PowerShell formatting; sharpen negated-boolean rule
1 parent f626b6b commit 72f8720

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/docs/Coding-Standards/Code-Layout.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ How code is structured on the page and across files. Layout is not cosmetic —
99

1010
## Formatting is automated
1111

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.
1313

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.
1617
- This frees review attention for what actually matters: correctness, design, and clarity.
1718

1819
See [Shift Left → pre-commit hooks](../Ways-of-Working/Principles/Engineering-Practices.md#pre-commit-hooks) for where these gates run.

src/docs/Coding-Standards/Naming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ Name length should track scope. A loop index living for three lines can be `i`.
4242

4343
- Encoding type into the name (`strName`, `arrUsers`) — the type system already knows.
4444
- Numbered suffixes (`user1`, `user2`, `dataNew`) — they signal a missing concept.
45-
- Negated booleans (`isNotReady`) — double negatives read badly in conditionals.
45+
- 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.
4646
- Names that lie — a `getUser` that also writes to a cache is a name that lies. Rename or split.

src/docs/Coding-Standards/PowerShell/index.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ These hold for all PowerShell, whatever the construct:
2626
- **`Verb-Noun` naming** with an approved verb (`Get-Verb`) and a singular noun: `Get-RepositorySecret`, not `Fetch-Secrets`.
2727
- **`PascalCase`** for functions, parameters, public variables, and class members; `camelCase` for local variables.
2828
- **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.
3029
- **Set `$ErrorActionPreference = 'Stop'`** at the top of every script and module so errors are terminating, not silently swallowed.
3130
- **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.
3231

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+
3343
## Idioms and pitfalls
3444

3545
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
4353

4454
## Toolchain
4555

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:
4757

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.
4959
- **[Pester](https://pester.dev/)** is the test framework; test files are named `*.Tests.ps1`. See the [Testing baseline](../Testing.md).

src/docs/Coding-Standards/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: The shared baseline every repository inherits, and the per-language
77

88
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.
99

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.
1111

1212
## Contents
1313

0 commit comments

Comments
 (0)