Commit 9c29a42
Split ProjectMetadata::discover() into focused helpers (#535)
## Summary
`ProjectMetadata::discover()` was a 96-line method with 4-level nesting
that mixed file system traversal, TOML parsing, precedence logic, and
fallback state tracking all in one place.
This PR extracts three focused helper functions to flatten the loop body
and make the algorithm easier to follow:
- **`try_load_karva_toml(dir)`** — checks for `karva.toml` in the given
directory and parses it if present. Returns `Ok(None)` if the file
doesn't exist.
- **`try_load_pyproject(dir)`** — checks for `pyproject.toml` in the
given directory and parses it if present. Returns `Ok(None)` if the file
doesn't exist.
- **`has_karva_section(pyproject)`** — returns whether a parsed
pyproject contains a `[tool.karva]` section.
The main `discover()` loop now reads as a clear sequence: load
pyproject, check for karva.toml (highest precedence), check for
pyproject with `[tool.karva]`, track closest plain pyproject as
fallback.
The precedence rules are preserved exactly:
1. `karva.toml` takes precedence over `pyproject.toml` (with a warning
if both have karva config)
2. `pyproject.toml` with `[tool.karva]` section
3. Closest `pyproject.toml` without `[tool.karva]`
4. Fallback to default settings at the given path
## Test plan
- [x] All 685 tests pass (`just test`)
- [x] All pre-commit checks pass (`uvx prek run -a`)
- [x] Pure refactor — no behavioral changes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 2e528db commit 9c29a42
1 file changed
+58
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
142 | 115 | | |
143 | 116 | | |
144 | 117 | | |
145 | 118 | | |
146 | 119 | | |
147 | 120 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
153 | 126 | | |
154 | 127 | | |
155 | 128 | | |
156 | | - | |
| 129 | + | |
157 | 130 | | |
158 | 131 | | |
159 | 132 | | |
160 | | - | |
| 133 | + | |
161 | 134 | | |
162 | | - | |
163 | 135 | | |
164 | 136 | | |
165 | 137 | | |
166 | | - | |
167 | 138 | | |
168 | 139 | | |
169 | 140 | | |
170 | 141 | | |
171 | 142 | | |
172 | 143 | | |
173 | | - | |
174 | | - | |
| 144 | + | |
175 | 145 | | |
176 | 146 | | |
177 | 147 | | |
178 | 148 | | |
179 | | - | |
180 | | - | |
| 149 | + | |
181 | 150 | | |
182 | 151 | | |
183 | 152 | | |
184 | 153 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 154 | + | |
| 155 | + | |
191 | 156 | | |
192 | 157 | | |
193 | 158 | | |
| |||
214 | 179 | | |
215 | 180 | | |
216 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
217 | 223 | | |
218 | 224 | | |
219 | 225 | | |
| |||
0 commit comments