@x18n/builtins 0.0.10 → 0.0.12

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.
package/dist/checks.d.mts CHANGED
@@ -4,6 +4,7 @@ export declare const missingKey: Check;
4
4
  export declare const missingTranslation: Check;
5
5
  export declare const staleTranslation: Check;
6
6
  export declare const emptyTranslation: Check;
7
+ export declare const redundantTranslation: Check;
7
8
  export declare const keyConflict: Check;
8
9
  export declare const localeCodeConflict: Check;
9
10
  export declare const unusedKey: Check;
package/dist/checks.mjs CHANGED
@@ -92,13 +92,41 @@ const emptyTranslation = {
92
92
  defaultSeverity: "warning",
93
93
  description: "A message with an empty string value.",
94
94
  *run(ctx) {
95
- for (const message of ctx.messages()) if (message.value === "") yield {
95
+ for (const message of ctx.messages()) if (message.value === "" && ctx.fallbacks(message.locale).length === 0) yield {
96
96
  key: message.key,
97
97
  locale: message.locale,
98
98
  message: `"${message.key}" is empty in ${message.locale}.`
99
99
  };
100
100
  }
101
101
  };
102
+ const redundantTranslation = {
103
+ id: "redundant-translation",
104
+ defaultSeverity: "warning",
105
+ description: "A message in a locale with a fallback that equals the message it falls back to, so it can be removed.",
106
+ *run(ctx) {
107
+ for (const message of ctx.messages()) {
108
+ if (message.value === "") continue;
109
+ for (const code of ctx.fallbacks(message.locale)) {
110
+ const inherited = ctx.message(message.key, code);
111
+ if (!inherited || inherited.value === "") continue;
112
+ if (JSON.stringify(inherited.value) === JSON.stringify(message.value)) yield {
113
+ key: message.key,
114
+ locale: message.locale,
115
+ message: `"${message.key}" in ${message.locale} is the same as in ${code}, which it falls back to.`,
116
+ fixes: [{
117
+ title: `Remove "${message.key}" from ${message.locale}`,
118
+ ops: [{
119
+ type: "delete",
120
+ key: message.key,
121
+ locales: [message.locale]
122
+ }]
123
+ }]
124
+ };
125
+ break;
126
+ }
127
+ }
128
+ }
129
+ };
102
130
  const keyConflict = {
103
131
  id: "key-conflict",
104
132
  defaultSeverity: "error",
@@ -333,6 +361,7 @@ const allChecks = [
333
361
  missingTranslation,
334
362
  staleTranslation,
335
363
  emptyTranslation,
364
+ redundantTranslation,
336
365
  unusedKey,
337
366
  localeCodeConflict,
338
367
  dynamicKey,
@@ -349,4 +378,4 @@ function recommended() {
349
378
  };
350
379
  }
351
380
  //#endregion
352
- export { allChecks, dynamicKey, emptyTranslation, glossary, hardString, identicalToSource, invalidSyntax, keyConflict, keyStyle, localeCodeConflict, missingKey, missingTranslation, placeholderMismatch, recommended, staleTranslation, unusedKey };
381
+ export { allChecks, dynamicKey, emptyTranslation, glossary, hardString, identicalToSource, invalidSyntax, keyConflict, keyStyle, localeCodeConflict, missingKey, missingTranslation, placeholderMismatch, recommended, redundantTranslation, staleTranslation, unusedKey };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x18n/builtins",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "description": "Built-in x18n plugins and presets: formats, locale finders, scanners, checks and reporters",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@vue/compiler-sfc": "^3.5.44",
36
- "@x18n/core": "0.0.10",
36
+ "@x18n/core": "0.0.12",
37
37
  "json5": "^2.2.3",
38
38
  "jsonc-parser": "^3.3.1",
39
39
  "oxc-parser": "^0.155.0",