Skip to content

Commit ca39127

Browse files
committed
feat: apply rules to a pattern instead of single file (#6)
1 parent c1398c1 commit ca39127

39 files changed

Lines changed: 818 additions & 869 deletions

‎CLAUDE.md‎

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,49 @@ just quality-tools # Auto-format code with rustfmt
1919

2020
### Running the Tool
2121

22+
**Single file mode** — refactor one PHP file:
2223
```bash
23-
cargo run -- path/to/file.php
24-
# or
25-
./target/debug/php-refactor path/to/file.php
24+
cargo run -- app.php
25+
./target/debug/php-refactor app.php
2626
```
2727

28+
**Directory mode** — refactor all PHP files in a directory (recursive):
29+
```bash
30+
cargo run -- src/
31+
./target/debug/php-refactor tests/
32+
```
33+
34+
**Config mode** — refactor multiple directories defined in a TOML config file:
35+
```bash
36+
cargo run -- config.toml
37+
./target/debug/php-refactor target/config.toml
38+
```
39+
40+
### Config File Format
41+
42+
Create a `config.toml` file to process multiple directories at once:
43+
44+
```toml
45+
[source]
46+
paths = ["src", "tests", "app"]
47+
```
48+
49+
Paths can be:
50+
- Relative to the project root (where you run the command): `"src"`, `"./app"`
51+
- Absolute: `"/home/user/project/src"`
52+
- Nested: `"src/components/php"`
53+
54+
The tool will recursively walk each path and apply all rules to every `.php` file found.
55+
56+
## How Rules Work
57+
58+
Rules receive a **path** (file, directory, or config file) and are responsible for:
59+
1. Expanding it to actual PHP files (single file, directory walk, config parsing)
60+
2. Reading each file, applying transformations, writing back if changed
61+
3. Returning stats: how many files changed and how many were analyzed
62+
63+
This design keeps `main.rs` simple — it just passes the input path to each rule in sequence. Each rule is autonomous and can process different subsets of files if needed.
64+
2865
## How to Find What You Need
2966

3067
- **Writing or modifying a rule?** → See `.claude/rules/rule-contract.md` (function contract, return semantics)
@@ -34,21 +71,25 @@ cargo run -- path/to/file.php
3471
- **Looking at architecture in `src/`?** → `.claude/rules/architecture.md` (loaded automatically when working in src/)
3572
- **Understanding test fixtures in `tests/`?** → `.claude/rules/testing-patterns.md` (loaded automatically when working in tests/)
3673
- **Need a definition?** → Invoke `/glossary` skill (Rule, Fixture, AST, Span, Bump Arena, Idempotent, mago-syntax)
74+
- **Understanding file discovery?** → See `src/resolver.rs` (handles single files, directories, and TOML config expansion)
3775

3876
## Project Structure
3977

4078
```
4179
src/
42-
├── main.rs # CLI entry, rule chaining, file I/O
80+
├── main.rs # CLI entry: get path, loop rules, report results
4381
├── lib.rs # Module re-exports
44-
├── reporter.rs # Timing and memory reporting
45-
└── rules/mod.rs # Rule registry (all_rules)
82+
└── rules/
83+
├── mod.rs # Rule registry (all_rules, all_source_transforms)
84+
└── quality/ # Quality rules by category
85+
├── mod.rs
86+
└── add_final_keyword.rs # Example rule (adds final to classes)
4687
4788
tests/
48-
├── rules_test.rs # Fixture-based integration test runner
49-
└── rules/ # Test fixtures by rule path
89+
├── *_test.rs # Individual unit tests
90+
├── rules_test.rs # Rule integration tests (uses source fixtures)
91+
└── fixtures/ # Versioned fixtures for test data
5092
51-
.github/workflows/quality.yml # CI: check, fmt, clippy, test
52-
Cargo.toml / Cargo.lock # Dependencies
53-
justfile # Task automation
93+
Cargo.toml / Cargo.lock # Dependencies
94+
justfile # Task automation
5495
```

0 commit comments

Comments
 (0)