Skip to content

fix(mrml-core): warn on duplicate attributes and keep first value#638

Merged
jdrouet merged 1 commit into
jdrouet:mainfrom
federicobond:fix/duplicate-attribute-warning
Apr 26, 2026
Merged

fix(mrml-core): warn on duplicate attributes and keep first value#638
jdrouet merged 1 commit into
jdrouet:mainfrom
federicobond:fix/duplicate-attribute-warning

Conversation

@federicobond
Copy link
Copy Markdown
Contributor

The shared parse_attributes_map helper silently overwrote earlier attribute values when the same attribute appeared twice on an element.

I modified it to keep the first occurrence, which matches HTML and MJML behavior, and emit a DuplicateAttribute warning on the span of the duplicate so callers can surface it.

@federicobond federicobond force-pushed the fix/duplicate-attribute-warning branch from 79a90bc to 99dd60f Compare April 15, 2026 01:06
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.96%. Comparing base (5311e58) to head (42b410e).
⚠️ Report is 201 commits behind head on main.

Files with missing lines Patch % Lines
packages/mrml-core/src/prelude/parser/output.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #638      +/-   ##
==========================================
+ Coverage   92.89%   92.96%   +0.06%     
==========================================
  Files         227      206      -21     
  Lines       12203    11733     -470     
==========================================
- Hits        11336    10907     -429     
+ Misses        867      826      -41     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@federicobond federicobond force-pushed the fix/duplicate-attribute-warning branch 2 times, most recently from 990c212 to 80a1d1c Compare April 15, 2026 01:28
Copy link
Copy Markdown
Owner

@jdrouet jdrouet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny optimization, mostly a nitpick 😉 But thanks a lot with that fix!

Comment on lines +398 to +402
if result.contains_key(&name) {
cursor.add_warning(WarningKind::DuplicateAttribute, attr.span);
continue;
}
result.insert(name, attr.value.map(|inner| inner.to_string()));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good fix but requires 2 accesses to the entry in the map.
Instead, could we use .entry(attr.qualified_name()) and, if it's occupied, we warn, instead we set it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed.

The shared parse_attributes_map helper silently overwrote earlier
attribute values when the same attribute appeared twice on an element.
Keep the first occurrence and emit a DuplicateAttribute warning on the
span of the duplicate so callers can surface it.

Signed-off-by: Federico Bond <federicobond@gmail.com>
@federicobond federicobond force-pushed the fix/duplicate-attribute-warning branch from 80a1d1c to 42b410e Compare April 25, 2026 23:39
@jdrouet
Copy link
Copy Markdown
Owner

jdrouet commented Apr 26, 2026

Thanks a lot for this!

@jdrouet jdrouet merged commit fdae346 into jdrouet:main Apr 26, 2026
19 of 20 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 26, 2026
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.

2 participants