about summary refs log tree commit diff
path: root/eslint/keep-i18n-patch-in-sync.js
blob: ee183a5c683412cec3fffef687db6a583a706a00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* eslint-disable bsky-internal/keep-i18n-patch-in-sync */
const LOCALE_DATA_FOLDER = '@formatjs/intl-pluralrules/locale-data/'
const GEN_MODULE_PATH =
  '@formatjs/intl-pluralrules/supported-locales.generated.js'

exports.create = function create(context) {
  delete require.cache[require.resolve(GEN_MODULE_PATH)]
  const {supportedLocales} = require(GEN_MODULE_PATH)
  return {
    Literal(node) {
      if (typeof node.value !== 'string') {
        return
      }
      if (!node.value.startsWith(LOCALE_DATA_FOLDER)) {
        return
      }
      const code = node.value.slice(LOCALE_DATA_FOLDER.length)
      if (!supportedLocales.includes(code)) {
        context.report({
          node,
          message:
            'Edit .patches/@formatjs+intl-pluralrules+XXX.patch to include ' +
            code,
        })
      }
    },
  }
}