Chore: Update `no-untranslated-strings` rule to check some text props as well (#97190)

* Update no-untranslated-strings rule to check some props as well

* Update betterer with new no-untranslated-strings results
pull/97919/head
Tom Ratcliffe 7 months ago committed by GitHub
parent af2475415e
commit a9cd0f19f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2865
      .betterer.results
  2. 22
      packages/grafana-eslint-rules/rules/no-untranslated-strings.cjs

File diff suppressed because it is too large Load Diff

@ -5,12 +5,30 @@ const createRule = ESLintUtils.RuleCreator(
(name) => `https://github.com/grafana/grafana/blob/main/packages/grafana-eslint-rules/README.md#${name}`
);
const propsToCheck = ['label', 'description', 'placeholder', 'aria-label', 'title', 'text'];
const noUntranslatedStrings = createRule({
create(context) {
return {
JSXAttribute(node) {
if (!propsToCheck.includes(String(node.name.name)) || !node.value) {
return;
}
const isUntranslatedProp =
(node.value.type === 'Literal' && node.value.value !== '') ||
(node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'Literal');
if (isUntranslatedProp) {
return context.report({
node,
messageId: 'noUntranslatedStringsProp',
});
}
},
JSXText(node) {
const ancestors = context.sourceCode.getAncestors(node);
const isEmpty = !node.value.trim();
const isEmpty = !node.value.trim();
const hasTransAncestor = ancestors.some((ancestor) => {
return (
ancestor.type === AST_NODE_TYPES.JSXElement &&
@ -36,11 +54,11 @@ const noUntranslatedStrings = createRule({
},
messages: {
noUntranslatedStrings: 'No untranslated strings. Wrap text with <Trans />',
noUntranslatedStringsProp: `No untranslated strings in text props. Wrap text with <Trans /> or use t()`,
},
schema: [],
},
defaultOptions: [],
});
module.exports = noUntranslatedStrings;

Loading…
Cancel
Save