Skip to content

🐛 Validate field default ordering in oneline config#63

Merged
ubmarco merged 2 commits into
mainfrom
mh-field-order
Apr 12, 2026
Merged

🐛 Validate field default ordering in oneline config#63
ubmarco merged 2 commits into
mainfrom
mh-field-order

Conversation

@ubmarco
Copy link
Copy Markdown
Member

@ubmarco ubmarco commented Apr 12, 2026

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:

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 validation

@ubmarco ubmarco changed the title 🐛 Validate field default ordering in oneline comment configuration 🐛 Validate field default ordering in oneline config Apr 12, 2026
@ubmarco ubmarco requested review from juiwenchen and patdhlk April 12, 2026 15:37
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.80%. Comparing base (d30193c) to head (410e560).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   89.87%   89.80%   -0.07%     
==========================================
  Files          29       29              
  Lines        2548     2560      +12     
  Branches      297      300       +3     
==========================================
+ Hits         2290     2299       +9     
- Misses        163      165       +2     
- Partials       95       96       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ubmarco ubmarco merged commit a2a79e4 into main Apr 12, 2026
9 checks passed
@ubmarco ubmarco deleted the mh-field-order branch April 12, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants