in lib/rules/i18n-no-template-literal.js [33:76]
create(context) {
return {
CallExpression(node) {
const { callee, arguments: args } = node;
if (!callee.type === 'MemberExpression' || !args.length) {
return;
}
const { object, property } = node.callee;
if (object?.name !== 'i18n') {
return;
}
const positions = I18N_METHODS[property.name] || [];
positions.forEach((position) => {
const arg = args[position];
if (arg.type === 'TemplateLiteral') {
// Template literal without dynamic placeholders
const reportObject = {
node,
messageId: 'noStaticTemplate',
data: {
method: property.name,
position,
},
};
if (!arg.expressions || arg.expressions.length === 0) {
reportObject.fix = (fixer) => {
const fixedValue = toStaticString(arg.quasis);
return fixer.replaceText(arg, `'${fixedValue}'`);
};
}
context.report(reportObject);
}
});
},
};
},