feat(checks): Add safety checks for MDX format#19814
Conversation
|
@nijel I'm not sure if |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
|
|
||
| def get_jsx_expression_matches(self, text: str): | ||
| # matches expressions like {props.name.toUpperCase()} | ||
| jsx_expression_pattern = r"\{[^{}]+\}" |
There was a problem hiding this comment.
I'm afraid this is too simple; you can have curly braces inside the expression:
<button onClick={() => {
console.log("Clicked!");
setCount(count + 1);
}}>
Click Me
</button>
<div style={{ color: 'blue', fontSize: '14px' }}>Text</div>
<div>
{users.map(({ id, name }) => (
<p key={id}>{name}</p>
))}
</div>
PS: I've just quickly Googled for examples, these might be wrong, so first properly evaluate the JSX syntax.
There was a problem hiding this comment.
You're right, I'll make changes to handle that.
From what I understand, it's a valid example JSX, but the MDX parser would skip the content inside markups.
But something like the following would be correctly parsed
Test {
[1, 2, 3].map(
({ id }) => (<p key={id}>{id}</p>)
)
}There was a problem hiding this comment.
Pull request overview
Adds a new MDX-specific translation safety check intended to prevent JSX expression changes in .mdx strings, and wires it into the MDX format’s default check flags and documentation.
Changes:
- Introduces
SafeMDXCheckand registers it in the default checks list. - Enables the
safe-mdxflag for MDX via format defaults and location-based flag inference. - Updates tests and autogenerated documentation snippets to reflect the new check/flag.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| weblate/settings_example.py | Documents the new check in the example check list. |
| weblate/formats/tests/test_convert.py | Adds an assertion for MDX format default check flags. |
| weblate/formats/convert.py | Adds MDX safe-mdx to format-level check_flags (and a minor typing tweak). |
| weblate/formats/base.py | Adds safe-mdx to location-derived flags for .mdx paths. |
| weblate/checks/tests/test_flags.py | Updates expected location-derived flags for .mdx. |
| weblate/checks/test_mdx.py | Adds unit tests for the new MDX check. |
| weblate/checks/mdx.py | Implements the new SafeMDXCheck. |
| weblate/checks/defaults.py | Registers SafeMDXCheck in the default checks. |
| docs/snippets/format-features/mdx-features.rst | Updates MDX format feature snippet to include the new check. |
| docs/snippets/checks-autogenerated.rst | Adds autogenerated docs section for check-safe-mdx. |
| docs/snippets/check-flags-autogenerated.rst | Adds ignore-safe-mdx to the ignore-flags documentation. |
| docs/changes.rst | Adds a 2026.7 changelog entry describing the new check. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This only handles the JSX expressions like
{propos.name}, assuming the other inline codes are already handled by the Markdown check and/or Auto safe HTML checks