Skip to content

Commit

Permalink
Add ESLint rule to enforce the "widget-toolkit" translation namespace
Browse files Browse the repository at this point in the history
By that we avoid calls without namespace and translations not working in
packages depending on the SDK.

Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>
  • Loading branch information
weeman1337 committed Nov 19, 2024
1 parent 15ab9d5 commit 9d4dadc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ export default ts.config(
],
},
},
// mui package specific rules
{
files: ['packages/mui/**'],
rules: {
'no-restricted-syntax': [
'error',
{
selector:
"CallExpression[callee.name='useTranslation'][arguments.0.value!='widget-toolkit']",
message:
'useTranslation() must be invoked with the "widget-toolkit" namespace arg: useTranslation("widget-toolkit")',
},
{
selector:
"JSXElement[openingElement.name.name='Trans']:not(:has(JSXAttribute[name.name='ns'][value.value!='widget-toolkit']))",
message:
'<Trans> must be used with the "widget-toolkit" "ns" prop: <Trans … ns="widget-toolkit" … >',
},
],
},
},
// Relax some rules for test files only
{
files: ['**/*.test.*'],
Expand Down

0 comments on commit 9d4dadc

Please sign in to comment.