Skip to content

Add --align and --spacing to fmt and the language server - #43

Merged
chdsbd merged 9 commits into
mainfrom
claude/formatting-cli-extension-option-zpeww8
Nov 10, 2026
Merged

chdsbd merged 9 commits into
mainfrom
claude/formatting-cli-extension-option-zpeww8

Conversation

@chdsbd

@chdsbd chdsbd commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

🤖 Adds options for where fmt puts owners, including the VS Code extension's pre-5.1.0 formatting, which was removed in chdsbd/vscode-github-code-owners#43. Releases 0.4.0.

CLI

gh codeowners fmt [--align group|file] [--spacing <n>]
  • --align group (the default) is the existing terraform fmt-like style. Each group of consecutive rules lines up its owners and comments.
  • --align file lines up the first owner of every rule in the file in one column, like the old extension. Only the space before the first owner changes. Indentation, the spacing between owners and comments stay as they are.
  • --spacing <n> is the exact number of spaces between the longest pattern and the owners. It defaults to 1 and must be at least 1. It applies to owners only, so trailing comments still get one space. The old extension's output is --align file --spacing 5.

Language server

It reads the settings from initializationOptions or from the settings of workspace/didChangeConfiguration:

{ "format": { "align": "file", "spacing": 5 } }

Invalid settings (an unknown align, or a spacing below 1) are logged to stderr, and the previous settings stay.

Library

format::format_with(text, Align, spacing), format_group and format_file. format(text) is still the group style with spacing 1.

format_file fixes bugs in the old extension's formatter. That formatter took the first @ on a line as the start of the owners, so it split email owners (gopher@example.com became gophe @example.com), indented rules that had no owners, and ignored a # inside a pattern. format_file uses the real line splitter instead.

Release

Bumps the version to 0.4.0 in Cargo.toml, Cargo.lock, wasm/Cargo.lock and CHANGELOG.md. s/check-version passes.

Tests

  • Unit tests for spacing in both styles, and the old extension's fixture (format_file(text, 5) gives byte-for-byte the same output)
  • Proptests: both styles, at spacings 1–5, are idempotent, change only whitespace, and keep the rules and problems
  • CLI tests for --align, --spacing, and for rejecting --spacing 0
  • An LSP test for settings from initializationOptions, for changing them with didChangeConfiguration, and for bad settings being ignored
  • cargo test, cargo clippy --all-targets and cargo fmt pass locally

The extension change that uses this is chdsbd/vscode-github-code-owners#44. It needs v0.4.0 released, and GH_CODEOWNERS_VERSION bumped to match.

🤖 Generated with Claude Code

https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM

`fmt --style legacy [--alignment-offset N]` formats like the VS Code
extension did before it used gh-codeowners: the first owner of every rule
in the file lines up after the longest pattern, and nothing else changes.

The language server reads the same choice from initializationOptions or
workspace/didChangeConfiguration:
{ "format": { "style": "legacy", "alignmentOffset": 4 } }

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM
claude and others added 5 commits November 9, 2026 14:13
…-offset

Clap can require another flag but not another flag's value, so with
--style it couldn't reject --style default --alignment-offset 2 itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM
--align group (the default) lines up owners in each group of rules, and
--align file lines up every rule's owners in one column, like the VS Code
extension did before 5.1.0. --spacing is the exact number of spaces
between the longest pattern and the owners, 1 by default for both.

The language server takes { "format": { "align": "file", "spacing": 5 } }.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM
@chdsbd chdsbd changed the title Add legacy formatting style to fmt and the language server Add --align and --spacing to fmt and the language server Nov 10, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018s9fHcEQxmXZ7pQ6v9W2KM
@chdsbd
chdsbd marked this pull request as ready for review November 10, 2026 02:28
@chdsbd
chdsbd merged commit f425b0a into main Nov 10, 2026
12 checks passed
@chdsbd
chdsbd deleted the claude/formatting-cli-extension-option-zpeww8 branch November 10, 2026 02:36
chdsbd added a commit to chdsbd/vscode-github-code-owners that referenced this pull request Nov 10, 2026
Add new formatting option (`file`) to match legacy behavior.

---

🤖 Adds settings for how the gh-codeowners language server formats
CODEOWNERS, including the pre-5.1.0 formatting, and bundles
gh-codeowners v0.4.0, which supports them.

- `githubCodeOwners.format.align`: `group` (the default, the current
behavior) or `file` (one column for the whole file, like before 5.1.0).
- `githubCodeOwners.format.spacing`: the number of spaces between the
longest pattern and the owners. It defaults to 1. To format exactly like
before 5.1.0, use `align: file` with `spacing: 5`.
- The deprecated `githubCodeOwners.format.alignmentOffset` and
`github-code-owners.format.alignment-offset` are deprecated again, now
pointing to `spacing`. If the user set one of them and hasn't set
`spacing`, the extension sends `offset + 1`, so their files format as
before.
- The deprecation message for `format.enabled` explains how to get the
old formatting.
- The extension sends `{ format: { align, spacing } }` as
`initializationOptions`, and sends `workspace/didChangeConfiguration`
when any of these settings change, so no restart is needed.
- `s/download-server` bundles gh-codeowners v0.4.0
(chdsbd/gh-codeowners#43), which reads these settings.
- Adds an integration test that covers the deprecated offset, and
`spacing` overriding it.
- Fixes a flaky test: "offers to escape brackets" now waits for the
language server's quick fix, since VS Code's own AI actions, which have
no edit, can arrive first.

## Verification
- `npm run typecheck`, `npm run eslint`, `npm run fmt:check` and `npm
run compile` pass.
- The published v0.4.0 linux-amd64 binary matches the release's SHA-256
digest, reports version 0.4.0, and formats with `--align file --spacing
3`.
- The test's expected text comes from the server's real output.
- I couldn't run the VS Code integration tests in my environment,
because the network blocks the VS Code download, so CI is the first full
run.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants