mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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
This commit is contained in:
parent
af2475415e
commit
a9cd0f19f4
2961
.betterer.results
2961
.betterer.results
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…
Reference in New Issue
Block a user