@lingual/i18n-check 0.8.15 → 0.8.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
41
41
  const ts = __importStar(require("typescript"));
42
42
  const USE_TRANSLATIONS = 'useTranslations';
43
43
  const GET_TRANSLATIONS = 'getTranslations';
44
- const COMMENT_CONTAINS_STATIC_KEY_REGEX = /t\((["'])(.*?[^\\])(["'])\)/;
44
+ const COMMENT_CONTAINS_STATIC_KEY_REGEX = /i18n-check t\((["'])(.*?[^\\])(["'])\)/;
45
45
  const extract = (filesPaths) => {
46
46
  return filesPaths.flatMap(getKeys).sort((a, b) => {
47
47
  return a.key > b.key ? 1 : -1;
@@ -281,14 +281,14 @@ const getKeys = (path) => {
281
281
  // Example:
282
282
  // const someKeys = messages[selectedOption];
283
283
  // Define as a single-line comment all the possible static keys for that dynamic key
284
- // t('some.static.key.we.want.to.extract');
285
- // t('some.other.key.we.want.to.extract.without.semicolons')
284
+ // i18n-check t('some.static.key.we.want.to.extract');
285
+ // i18n-check t('some.other.key.we.want.to.extract.without.semicolons')
286
286
  const commentRanges = ts.getLeadingCommentRanges(sourceFile.getFullText(), node.getFullStart());
287
287
  if (commentRanges?.length && commentRanges.length > 0) {
288
288
  commentRanges.forEach((range) => {
289
289
  const comment = sourceFile.getFullText().slice(range.pos, range.end);
290
290
  // parse the string and check if it includes the following format:
291
- // t('someString')
291
+ // i18n-check t('someString')
292
292
  const hasStaticKeyComment = COMMENT_CONTAINS_STATIC_KEY_REGEX.test(comment);
293
293
  if (hasStaticKeyComment) {
294
294
  // capture the string comment
@@ -296,12 +296,18 @@ const getKeys = (path) => {
296
296
  if (commentKey) {
297
297
  const namespace = getCurrentNamespaces();
298
298
  const namespaceName = namespace ? namespace[0]?.name : '';
299
- foundKeys.push({
300
- key: namespaceName
301
- ? `${namespaceName}.${commentKey}`
302
- : commentKey,
303
- meta: { file: path, namespace: namespaceName },
299
+ const key = namespaceName
300
+ ? `${namespaceName}.${commentKey}`
301
+ : commentKey;
302
+ const keyExists = foundKeys.find((foundKey) => {
303
+ return foundKey.key === key;
304
304
  });
305
+ if (!keyExists) {
306
+ foundKeys.push({
307
+ key,
308
+ meta: { file: path, namespace: namespaceName },
309
+ });
310
+ }
305
311
  }
306
312
  }
307
313
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingual/i18n-check",
3
- "version": "0.8.15",
3
+ "version": "0.8.16",
4
4
  "description": "i18n translation messages check",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",