Skip to content

Commit

Permalink
fix(eslint-plugin-formatjs): fix extraction filter, fix #2238
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Oct 25, 2020
1 parent 556cb3b commit f9f2c3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ defineMessage({
{
code: `
import {FormattedMessage} from 'react-intl'
const a = <FormattedMessage defaultMessage={defaultMessage} description="this is description"></FormattedMessage>`,
const a = <FormattedMessage defaultMessage={defaultMessage} description="this is description"/>`,
errors: [
{
message:
'`defaultMessage` must be a string literal (not function call or variable)',
},
],
options: ['literal'],
},
{
code: `
import {FormattedMessage} from 'react-intl'
const a = <FormattedMessage defaultMessage={defaultMessage}/>`,
errors: [
{
message:
Expand All @@ -155,5 +167,17 @@ defineMessage({
],
options: ['literal'],
},
{
code: `
import {FormattedMessage} from 'react-intl'
const a = <FormattedMessage defaultMessage={\`asf\`}/>`,
errors: [
{
message:
'`defaultMessage` must be a string literal (not function call or variable)',
},
],
options: ['literal'],
},
],
});
6 changes: 5 additions & 1 deletion packages/eslint-plugin-formatjs/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ function extractMessageDescriptorFromJSXElement(
break;
}
}
if (!Object.keys(result.message).length) {
if (
!result.messagePropNode &&
!result.descriptionNode &&
!result.idPropNode
) {
return;
}
return [result, values];
Expand Down

0 comments on commit f9f2c3e

Please sign in to comment.