@ryuugg/stanza 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +163 -0
- package/package.json +63 -0
- package/src/cli.ts +820 -0
- package/src/compile/darwin-arm64.ts +3 -0
- package/src/compile/darwin-x64.ts +3 -0
- package/src/compile/linux-arm64-musl.ts +3 -0
- package/src/compile/linux-arm64.ts +3 -0
- package/src/compile/linux-x64-musl.ts +3 -0
- package/src/compile/linux-x64.ts +3 -0
- package/src/compiled.ts +6 -0
- package/src/engine/attach.ts +62 -0
- package/src/engine/directives.ts +154 -0
- package/src/engine/doc.ts +93 -0
- package/src/engine/edits.ts +79 -0
- package/src/engine/explain.ts +333 -0
- package/src/engine/gaps.ts +329 -0
- package/src/engine/hunks.ts +320 -0
- package/src/engine/index.ts +254 -0
- package/src/engine/model.ts +102 -0
- package/src/engine/rules.ts +103 -0
- package/src/engine/types.ts +37 -0
- package/src/files.ts +822 -0
- package/src/gitignore.ts +279 -0
- package/src/hook.ts +282 -0
- package/src/languages/index.ts +32 -0
- package/src/languages/javascript/ast.ts +199 -0
- package/src/languages/javascript/braces.ts +374 -0
- package/src/languages/javascript/config/biome.ts +112 -0
- package/src/languages/javascript/config/eslint.ts +128 -0
- package/src/languages/javascript/config/evaluate.ts +278 -0
- package/src/languages/javascript/config/find.ts +108 -0
- package/src/languages/javascript/config/glob.ts +150 -0
- package/src/languages/javascript/config/index.ts +48 -0
- package/src/languages/javascript/config/layers.ts +425 -0
- package/src/languages/javascript/config/module.ts +326 -0
- package/src/languages/javascript/config/oxlint.ts +170 -0
- package/src/languages/javascript/config/width.ts +715 -0
- package/src/languages/javascript/entry.ts +39 -0
- package/src/languages/javascript/facts.ts +268 -0
- package/src/languages/javascript/index.ts +20 -0
- package/src/languages/javascript/lists.ts +49 -0
- package/src/languages/javascript/oracle.ts +191 -0
- package/src/languages/javascript/parse.ts +58 -0
- package/src/languages/javascript/scan.ts +68 -0
- package/src/languages/language.ts +109 -0
- package/src/launcher +21 -0
- package/src/native-file.d.ts +4 -0
- package/src/step.ts +108 -0
- package/src/usage.ts +30 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryuu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<h1 align="center">Stanza</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
An opinionated formatter for turning function bodies into readable steps.
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://stanza.ryuu.gg">Documentation</a>
|
|
9
|
+
ยท
|
|
10
|
+
<a href="https://github.com/ryuudotgg/stanza/issues">Issues</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="LICENSE.md"><img src="https://img.shields.io/github/license/ryuudotgg/stanza?style=for-the-badge&labelColor=000000" alt="MIT License"></a>
|
|
15
|
+
<a href="https://github.com/ryuudotgg/stanza/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ryuudotgg/stanza/ci.yml?branch=main&style=for-the-badge&labelColor=000000&label=CI" alt="CI"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
## โจ What is Stanza?
|
|
19
|
+
|
|
20
|
+
Stanza formats the spacing inside TypeScript and JavaScript function bodies, the one thing other formatters leave alone, so it runs alongside them without fighting. It edits only blank lines and brace tokens, is deterministic and idempotent, and checks seven hundred files in about half a second.
|
|
21
|
+
|
|
22
|
+
The style is mine, hence opinionated. A function body reads as a sequence of steps, one blank line between steps, none inside a step. A fetch and the `if (!response.ok)` that guards it are one step. A ten line query and the `return` after it are two. If that is not how you read code, this tool will annoy you.
|
|
23
|
+
|
|
24
|
+
Before and after `stanza --fix`:
|
|
25
|
+
|
|
26
|
+
```diff
|
|
27
|
+
function publish(draft: Draft) {
|
|
28
|
+
if (!draft.title) throw new Error("title required");
|
|
29
|
+
+
|
|
30
|
+
const slug = slugify(draft.title);
|
|
31
|
+
if (exists(slug)) throw new Error(`${slug} is taken`);
|
|
32
|
+
+
|
|
33
|
+
save(draft, slug);
|
|
34
|
+
notify(draft.author);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## ๐ Getting Started
|
|
39
|
+
|
|
40
|
+
Stanza needs Bun 1.4 or later, even when npm installs it.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bunx @ryuugg/stanza --check src # run once without installing
|
|
44
|
+
bun add -g @ryuugg/stanza # put stanza on your PATH
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
<details>
|
|
48
|
+
<summary>Release binaries, for machines without Bun</summary>
|
|
49
|
+
|
|
50
|
+
Take the binary for your machine from the [latest release](https://github.com/ryuudotgg/stanza/releases/latest), check it against `SHA256SUMS`, and put it on your `PATH`. There is no Windows binary: run the Linux build inside WSL. [Release Binaries](https://stanza.ryuu.gg/guides/release-binaries) walks through the download, the checksum and musl.
|
|
51
|
+
|
|
52
|
+
| Asset | Platform |
|
|
53
|
+
| ------------------------- | --------------------------------------------------------- |
|
|
54
|
+
| `stanza-darwin-arm64` | macOS on Apple silicon |
|
|
55
|
+
| `stanza-darwin-x64` | macOS on Intel |
|
|
56
|
+
| `stanza-linux-x64` | Linux x64 with glibc: Debian, Ubuntu, Fedora, most others |
|
|
57
|
+
| `stanza-linux-arm64` | Linux arm64 with glibc |
|
|
58
|
+
| `stanza-linux-x64-musl` | Linux x64 with musl: Alpine and other musl distributions |
|
|
59
|
+
| `stanza-linux-arm64-musl` | Linux arm64 with musl |
|
|
60
|
+
|
|
61
|
+
> **Warning:** The macOS binaries are signed ad hoc, not notarized, so Gatekeeper stops a copy downloaded through a browser. Clear the flag once with `xattr -d com.apple.quarantine ~/.local/bin/stanza`, or download with curl.
|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
### Commands
|
|
66
|
+
|
|
67
|
+
| Command | What it does |
|
|
68
|
+
| ------------------------------ | --------------------------------------------------------- |
|
|
69
|
+
| `stanza --check <paths>` | Report findings and change nothing. |
|
|
70
|
+
| `stanza --fix <paths>` | Apply every rule it can decide on its own. |
|
|
71
|
+
| `stanza --fix --changed` | Fix the files changed against HEAD, plus untracked files. |
|
|
72
|
+
| `stanza --check --staged` | Check what is staged, for a pre-commit hook. |
|
|
73
|
+
| `stanza explain <file>:<line>` | Say which rule decides the gap at that line, and why. |
|
|
74
|
+
| `stanza hook` | Run as a Claude Code or Codex hook. |
|
|
75
|
+
|
|
76
|
+
### Hooks
|
|
77
|
+
|
|
78
|
+
To format each Write before it lands, fix each Edit and MultiEdit as soon as it lands, and run a Stop pass at the end of each turn in Claude Code, add the three hooks to `.claude/settings.json`:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"hooks": {
|
|
83
|
+
"PreToolUse": [
|
|
84
|
+
{
|
|
85
|
+
"matcher": "Write",
|
|
86
|
+
"hooks": [
|
|
87
|
+
{
|
|
88
|
+
"type": "command",
|
|
89
|
+
"command": "stanza hook"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"PostToolUse": [
|
|
95
|
+
{
|
|
96
|
+
"matcher": "Edit|MultiEdit",
|
|
97
|
+
"hooks": [
|
|
98
|
+
{
|
|
99
|
+
"type": "command",
|
|
100
|
+
"command": "stanza hook"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"Stop": [
|
|
106
|
+
{
|
|
107
|
+
"hooks": [
|
|
108
|
+
{
|
|
109
|
+
"type": "command",
|
|
110
|
+
"command": "stanza hook"
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
To check what you are about to commit, add this to `.git/hooks/pre-commit` and make the file executable:
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
#!/bin/sh
|
|
123
|
+
exec stanza --check --staged
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
> [!IMPORTANT]
|
|
127
|
+
> In a repository whose existing code does not follow these rules, add `--hunks` to each: `stanza hook --hunks` and `exec stanza --check --staged --hunks`. See [Existing Codebases](https://stanza.ryuu.gg/guides/existing-codebases).
|
|
128
|
+
|
|
129
|
+
## ๐ญ Why
|
|
130
|
+
|
|
131
|
+
Agent-written code tends to arrive as one block: a forty line function without a single blank line, the guard for a value three lines away from it. It is correct, and it is painful to read.
|
|
132
|
+
|
|
133
|
+
Writing the rules into an `AGENTS.md` helps less than you would think. The two agents that wrote the first version of this tool had these exact rules in their prompts. One came back clean. The other came back with eighteen findings, nine of them plain rule violations.
|
|
134
|
+
|
|
135
|
+
So I turned the rules into a tool and run it as a hook at the end of every agent turn. It fixes what it can decide on its own and reports the rest.
|
|
136
|
+
|
|
137
|
+
Also, I just wanted to play around with oxc-parser. Everything above is a very elaborate excuse.
|
|
138
|
+
|
|
139
|
+
## ๐ Documentation
|
|
140
|
+
|
|
141
|
+
Read the full docs at [stanza.ryuu.gg](https://stanza.ryuu.gg).
|
|
142
|
+
|
|
143
|
+
- [Getting Started](https://stanza.ryuu.gg/getting-started)
|
|
144
|
+
- [Rules](https://stanza.ryuu.gg/rules)
|
|
145
|
+
- [Directives](https://stanza.ryuu.gg/rules/directives)
|
|
146
|
+
- [CLI Reference](https://stanza.ryuu.gg/reference/cli)
|
|
147
|
+
- [Output and Exit Codes](https://stanza.ryuu.gg/reference/output)
|
|
148
|
+
- [Pre-Commit Hook](https://stanza.ryuu.gg/guides/pre-commit)
|
|
149
|
+
- [Editors](https://stanza.ryuu.gg/guides/editors)
|
|
150
|
+
- [Claude Code](https://stanza.ryuu.gg/agents/claude-code)
|
|
151
|
+
- [Codex](https://stanza.ryuu.gg/agents/codex)
|
|
152
|
+
|
|
153
|
+
## ๐ค Contributing
|
|
154
|
+
|
|
155
|
+
To build from source and run the checks, see [CONTRIBUTING.md](CONTRIBUTING.md). Report bugs on [GitHub Issues](https://github.com/ryuudotgg/stanza/issues).
|
|
156
|
+
|
|
157
|
+
## ๐ฅ Authors
|
|
158
|
+
|
|
159
|
+
- Ryuu ([@ryuudotgg](https://github.com/ryuudotgg))
|
|
160
|
+
|
|
161
|
+
## ๐ License
|
|
162
|
+
|
|
163
|
+
This project is licensed under the MIT License, see [LICENSE.md](LICENSE.md) for details.
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ryuugg/stanza",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "An opinionated code formatter for TypeScript.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"formatter",
|
|
7
|
+
"code-formatter",
|
|
8
|
+
"code-style",
|
|
9
|
+
"typescript",
|
|
10
|
+
"javascript",
|
|
11
|
+
"oxc",
|
|
12
|
+
"claude-code",
|
|
13
|
+
"codex",
|
|
14
|
+
"ai-agents"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://stanza.ryuu.gg",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ryuudotgg/stanza/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ryuudotgg/stanza.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Ryuu",
|
|
27
|
+
"url": "https://ryuu.gg"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"bin": {
|
|
31
|
+
"stanza": "src/launcher"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"workspaces": [
|
|
37
|
+
"docs"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"bench": "bun scripts/bench.ts",
|
|
41
|
+
"build": "bun scripts/build.ts",
|
|
42
|
+
"check": "oxlint && oxfmt --check",
|
|
43
|
+
"check:fix": "oxlint --fix && oxfmt",
|
|
44
|
+
"self-check": "bun run src/cli.ts --check src scripts tests/*.ts",
|
|
45
|
+
"test": "bun test --parallel",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"oxc-parser": "^0.151.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/bun": "latest",
|
|
53
|
+
"oxfmt": "^0.70.0",
|
|
54
|
+
"oxlint": "^1.85.0",
|
|
55
|
+
"typescript": "5"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"bun": ">=1.4.0"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
}
|
|
63
|
+
}
|