Fix i18n lint rule with emoji->emojify component
This commit is contained in:
parent
35e07832a6
commit
5e8c22bf28
7 changed files with 48 additions and 21 deletions
|
@ -81,19 +81,19 @@ const tests: Record<string, Test> = {
|
|||
expectErrors: ['wrapEmoji'],
|
||||
},
|
||||
'icu:wrapEmoji:2': {
|
||||
messageformat: '<emoji>👩 extra</emoji>',
|
||||
messageformat: '<emojify>👩 extra</emojify>',
|
||||
expectErrors: ['wrapEmoji'],
|
||||
},
|
||||
'icu:wrapEmoji:3': {
|
||||
messageformat: '<emoji>👩👩</emoji>',
|
||||
messageformat: '<emojify>👩👩</emojify>',
|
||||
expectErrors: ['wrapEmoji'],
|
||||
},
|
||||
'icu:wrapEmoji:4': {
|
||||
messageformat: '<emoji>{emoji}</emoji>',
|
||||
messageformat: '<emojify>{emoji}</emojify>',
|
||||
expectErrors: ['wrapEmoji'],
|
||||
},
|
||||
'icu:wrapEmoji:5': {
|
||||
messageformat: '<emoji>👩</emoji>',
|
||||
messageformat: '<emojify>👩</emojify>',
|
||||
expectErrors: [],
|
||||
},
|
||||
};
|
||||
|
|
|
@ -12,24 +12,26 @@ import {
|
|||
} from '@formatjs/icu-messageformat-parser';
|
||||
import { rule } from '../utils/rule';
|
||||
|
||||
function isEmojiTag(
|
||||
function isEmojifyTag(
|
||||
element: MessageFormatElement | null
|
||||
): element is TagElement {
|
||||
return element != null && isTagElement(element) && element.value === 'emoji';
|
||||
return (
|
||||
element != null && isTagElement(element) && element.value === 'emojify'
|
||||
);
|
||||
}
|
||||
|
||||
export default rule('wrapEmoji', context => {
|
||||
const emojiRegex = getEmojiRegex();
|
||||
return {
|
||||
enterTag(element) {
|
||||
if (!isEmojiTag(element)) {
|
||||
if (!isEmojifyTag(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (element.children.length !== 1) {
|
||||
// multiple children
|
||||
context.report(
|
||||
'Only use a single literal emoji in <emoji> tags with no additional text.',
|
||||
'Only use a single literal emoji in <emojify> tags with no additional text.',
|
||||
element.location
|
||||
);
|
||||
return;
|
||||
|
@ -39,7 +41,7 @@ export default rule('wrapEmoji', context => {
|
|||
if (!isLiteralElement(child)) {
|
||||
// non-literal
|
||||
context.report(
|
||||
'Only use a single literal emoji in <emoji> tags with no additional text.',
|
||||
'Only use a single literal emoji in <emojify> tags with no additional text.',
|
||||
child.location
|
||||
);
|
||||
}
|
||||
|
@ -51,10 +53,10 @@ export default rule('wrapEmoji', context => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!isEmojiTag(parent)) {
|
||||
if (!isEmojifyTag(parent)) {
|
||||
// unwrapped
|
||||
context.report(
|
||||
'Use <emoji> to wrap emoji in translation strings.',
|
||||
'Use <emojify> to wrap emoji in translation strings.',
|
||||
element.location
|
||||
);
|
||||
return;
|
||||
|
@ -64,7 +66,7 @@ export default rule('wrapEmoji', context => {
|
|||
if (emoji !== element.value) {
|
||||
// extra text other than emoji
|
||||
context.report(
|
||||
'Only use a single literal emoji in <emoji> tags with no additional text.',
|
||||
'Only use a single literal emoji in <emojify> tags with no additional text.',
|
||||
element.location
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue