mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 20:22:21 +08:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
// @ts-check
|
|
const { ESLintUtils, AST_NODE_TYPES } = require('@typescript-eslint/utils');
|
|
|
|
const createRule = ESLintUtils.RuleCreator(
|
|
(name) => `https://github.com/grafana/grafana/blob/main/packages/grafana-eslint-rules/README.md#${name}`
|
|
);
|
|
|
|
const noUntranslatedStrings = createRule({
|
|
create(context) {
|
|
return {
|
|
JSXText(node) {
|
|
const ancestors = context.getAncestors();
|
|
const isEmpty = !node.value.trim();
|
|
const hasTransAncestor = ancestors.some((ancestor) => {
|
|
return (
|
|
ancestor.type === AST_NODE_TYPES.JSXElement &&
|
|
ancestor.openingElement.type === AST_NODE_TYPES.JSXOpeningElement &&
|
|
ancestor.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier &&
|
|
ancestor.openingElement.name.name === 'Trans'
|
|
);
|
|
});
|
|
if (!isEmpty && !hasTransAncestor) {
|
|
context.report({
|
|
node,
|
|
messageId: 'noUntranslatedStrings',
|
|
});
|
|
}
|
|
},
|
|
};
|
|
},
|
|
name: 'no-untranslated-strings',
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
description: 'Check untranslated strings',
|
|
},
|
|
messages: {
|
|
noUntranslatedStrings: 'No untranslated strings. Wrap text with <Trans />',
|
|
},
|
|
schema: [],
|
|
},
|
|
defaultOptions: [],
|
|
});
|
|
|
|
|
|
module.exports = noUntranslatedStrings;
|