Commit a2a79e4
authored
🐛 Validate field default ordering in oneline config (#63)
### Problem
The oneline parser maps comma-separated values to `needs_fields`
strictly by position (index). When a field **without** a default is
defined after a field **with** a default, it becomes unreachable if the
user omits the optional fields — exactly like Python's `SyntaxError:
parameter without a default follows parameter with a default`.
Example invalid configuration:
```toml
needs_fields = [
{ "name" = "id" },
{ "name" = "implements", "type" = "list[str]", "default" = [] },
{ "name" = "type", "default" = "impl" },
{ "name" = "title" }, # required, but comes after optional fields
]
```
With this config, `@need MY_ID, My Title` maps `My Title` to
`implements` (index 1) instead of `title` (index 3), and `title` is
silently skipped.
### Solution
Add `check_fields_default_order()` validation to `OneLineCommentStyle`
that rejects configurations where a field without a default follows a
field with a default. This is checked alongside existing schema,
required-field, and uniqueness validations in
`check_fields_configuration()`.
### Changes
- `config.py`: New `check_fields_default_order()` method, integrated
into `check_fields_configuration()`
- `test_analyse_config.py`: Negative test case exercising the validation1 parent d30193c commit a2a79e4
2 files changed
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
279 | 296 | | |
280 | 297 | | |
281 | 298 | | |
282 | 299 | | |
283 | 300 | | |
| 301 | + | |
284 | 302 | | |
285 | 303 | | |
286 | 304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
155 | 172 | | |
156 | 173 | | |
157 | 174 | | |
| |||
0 commit comments