Skip to content

Commit

Permalink
Fix(eslint-plugin-formatjs/enforce-id): Continue to next message afte…
Browse files Browse the repository at this point in the history
…r whitelist match (#4389)
  • Loading branch information
gustavlrsn committed Apr 11, 2024
1 parent acd8c3f commit c063f7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-plugin-formatjs/rules/enforce-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function checkNode(
idWhitelistRegexps.some((r: RegExp) => r.test(id))
) {
// messageId is allowlisted so skip interpolation id check
return
continue
}

const correctId = interpolateName(
Expand Down
20 changes: 20 additions & 0 deletions packages/eslint-plugin-formatjs/tests/enforce-id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,25 @@ intl.formatMessage({defaultMessage: "{count, plural, one {#} other {# more}}", d
output: `
intl.formatMessage({defaultMessage: "{count, plural, one {#} other {# more}}", id: 'j9qhn+', description: "asd"})`,
},
{
code: `
import { defineMessages } from 'react-intl'
defineMessages({ example: { defaultMessage: 'example1', id: 'payment_string' }, example2: { defaultMessage: 'example2' } })`,
options: optionsWithWhitelist,
errors: [
{
messageId: 'enforceIdMatchingAllowlisted',
data: {
idInterpolationPattern: '[sha512:contenthash:base64:6]',
expected: 'FnMvk8',
actual: 'undefined',
idWhitelist: '"/\\./i", "/^payment_.*/i"',
},
},
],
output: `
import { defineMessages } from 'react-intl'
defineMessages({ example: { defaultMessage: 'example1', id: 'payment_string' }, example2: { defaultMessage: 'example2', id: 'FnMvk8' } })`,
},
],
})

0 comments on commit c063f7b

Please sign in to comment.