diff options
| author | Fuwn <[email protected]> | 2026-02-11 11:12:10 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-11 11:12:10 +0000 |
| commit | f37a1ee1e2577a0e8fd76d4c965abb93cd99a6cf (patch) | |
| tree | 4923021c7a049a9b2badb9dab9bd0e71c1551e7a /README.md | |
| parent | fix(adapter): Suppress blank lines before continuation keywords (else/catch/f... (diff) | |
| download | iku-f37a1ee1e2577a0e8fd76d4c965abb93cd99a6cf.tar.xz iku-f37a1ee1e2577a0e8fd76d4c965abb93cd99a6cf.zip | |
feat: Support JSON configuration file
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 51 |
1 files changed, 46 insertions, 5 deletions
@@ -1,11 +1,11 @@ # 🚀 Iku -> Grammar-Aware Go Formatter: Structure through separation +> Grammar-Aware Code Formatter: Structure through separation Let your code breathe! -Iku is a grammar-based Go formatter that enforces consistent blank-line placement by statement and declaration type. +Iku is a grammar-based formatter that enforces consistent blank-line placement by statement and declaration type. It supports Go, JavaScript, TypeScript, JSX, and TSX. ## Philosophy @@ -20,7 +20,9 @@ Code structure should be visually apparent from its formatting. Iku groups state ## How It Works -Iku applies standard Go formatting (via [go/format](https://pkg.go.dev/go/format)) first ([formatter.go#29](https://github.com/Fuwn/iku/blob/main/formatter.go#L29)), then adds its grammar-based blank-line rules on top. Your code gets `go fmt` output plus structural separation. +For Go files, Iku applies standard Go formatting (via [go/format](https://pkg.go.dev/go/format)) first, then adds its grammar-based blank-line rules on top. Your code gets `go fmt` output plus structural separation. + +For JavaScript and TypeScript files (`.js`, `.ts`, `.jsx`, `.tsx`), Iku uses a heuristic line-based analyser that classifies statements by keyword (`function`, `class`, `if`, `for`, `try`, etc.) and applies the same blank-line rules. ## Installation @@ -42,11 +44,13 @@ echo 'package main ...' | iku # Format and print to stdout iku file.go +iku component.tsx # Format in-place iku -w file.go +iku -w src/ -# Format entire directory +# Format entire directory (Go, JS, TS, JSX, TSX) iku -w . # List files that need formatting @@ -63,9 +67,46 @@ iku -d file.go | `-w` | Write result to file instead of stdout | | `-l` | List files whose formatting differs | | `-d` | Display diffs instead of rewriting | -| `--comments` | Comment attachment mode: `follow`, `precede`, `standalone` | | `--version` | Print version | +## Configuration + +Iku looks for `.iku.json` or `iku.json` in the current working directory. + +```json +{ + "comment_mode": "follow", + "group_single_line_functions": false +} +``` + +All fields are optional. Omitted fields use their defaults. + +### `comment_mode` + +Controls how comments interact with blank-line insertion. Default: `"follow"`. + +| Mode | Behaviour | +|------|-----------| +| `follow` | Comments attach to the **next** statement. The blank line goes **before** the comment. | +| `precede` | Comments attach to the **previous** statement. The blank line goes **after** the comment. | +| `standalone` | Comments are independent. Blank lines are placed strictly by statement rules. | + +### `group_single_line_functions` + +When `true`, consecutive single-line function declarations of the same type are kept together without blank lines. Default: `false`. + +```go +// group_single_line_functions = true +func Base() string { return baseDirectory } +func Config() string { return configFile } + +// group_single_line_functions = false (default) +func Base() string { return baseDirectory } + +func Config() string { return configFile } +``` + ## Examples ### Before |