i18n-validate
Advanced tools
Comparing version 1.3.1-next.2b2002c.0 to 1.4.0-next.3673637.0
#!/usr/bin/env node | ||
import { parseOptionsFile, log, parseFile, ValidationError, validateKey } from './chunk-XQBZQDUM.js'; | ||
import { parseOptionsFile, log, parseFile, ValidationError, validateKey } from './chunk-3VN7B33Q.js'; | ||
import process from 'node:process'; | ||
@@ -8,3 +8,3 @@ import { Command } from 'commander'; | ||
var start = performance.now(); | ||
var command = new Command().version("1.3.1-next.2b2002c.0").usage("[options] <file ...>").option("-c, --config <config>", "Path to the config file", "./i18n-validate.json").option("--log-level <logLevel>", "Log level").option("--exclude <exclude...>", "Exclude files from parsing").option("--exit-on-error", "Exit immediately if an error is found"); | ||
var command = new Command().version("1.4.0-next.3673637.0").usage("[options] <file ...>").option("-c, --config <config>", "Path to the config file", "./i18n-validate.json").option("--log-level <logLevel>", "Log level").option("--exclude <exclude...>", "Exclude files from parsing").option("--exit-on-error", "Exit immediately if an error is found"); | ||
command.on("--help", () => { | ||
@@ -50,3 +50,7 @@ console.log(""); | ||
log( | ||
new ValidationError(node.key ? "Dynamic keys are not supported yet. Skipping" : "No key provided", node.path, node.positions), | ||
new ValidationError( | ||
node.key ? "Dynamically typed keys aren't supported. Please add a const type to the key for it to work.\nPlease check https://github.com/imranbarbhuiya/i18n-validate#dynamic-keys for more information" : "No key provided", | ||
node.path, | ||
node.positions | ||
), | ||
"warn", | ||
@@ -75,3 +79,3 @@ options | ||
log( | ||
`Found ${errorCount + warningCount} issues${errorCount || warningCount ? ` (${errorCount} errors and ${warningCount} warnings)` : ""}.Validated ${fileCount} in ${timeTaken}`, | ||
`Found ${errorCount + warningCount} issues${errorCount || warningCount ? ` (${errorCount} errors and ${warningCount} warnings)` : ""}.Validated ${fileCount} file${fileCount > 1 ? "s" : ""} in ${timeTaken}`, | ||
"info", | ||
@@ -78,0 +82,0 @@ options |
@@ -1,3 +0,3 @@ | ||
export { ValidationError, parseFile, parseOptionsFile, validateKey } from './chunk-XQBZQDUM.js'; | ||
export { ValidationError, parseFile, parseOptionsFile, validateKey } from './chunk-3VN7B33Q.js'; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "i18n-validate", | ||
"version": "1.3.1-next.2b2002c.0", | ||
"version": "1.4.0-next.3673637.0", | ||
"description": "A cli tool to find invalid i18n keys, missing variables and many more", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -21,3 +21,3 @@ <div align="center"> | ||
- Fully customizable | ||
- Use of ternary operator or string concatenation using `+` operator is supported | ||
- Supports dynamic keys using typescript const types | ||
@@ -32,3 +32,3 @@ ## Usage | ||
```sh | ||
Usage: i18n-validate [options] <file ...> | ||
Usage: cli [options] <file ...> | ||
@@ -39,7 +39,5 @@ Options: | ||
"./i18n-validate.json") | ||
--log-level <logLevel> Log level (default: "info") | ||
--exclude <exclude...> Exclude files from parsing (default: | ||
"**/node_modules/**") | ||
--exit-on-error Exit immediately if an error is found (default: | ||
false) | ||
--log-level <logLevel> Log level | ||
--exclude <exclude...> Exclude files from parsing | ||
--exit-on-error Exit immediately if an error is found | ||
-h, --help display help for command | ||
@@ -52,10 +50,43 @@ | ||
$ i18next-validate --exclude "**/node_modules/**" "src/**/*.{js,jsx}" | ||
``` | ||
<!-- prettier-ignore-end --> | ||
- You can ignore a specific function by adding `// i18n-validate-disable-next-line` comment before the function call or ignore all the functions in a file by adding `/* i18n-validate-disable */` comment at the top of the file. | ||
- Dynamic keys aren't supported yet but ternary operators, string concatenation using `+` operator are supported. | ||
> **Note**: Currently, `i18n-validate` supports `typescript` and `javascript` (including `tsx` and `jsx`) source files and `json` translation files only. | ||
### Ignoring function or file | ||
You can ignore a specific function by adding `// i18n-validate-disable-next-line` comment before the function call or ignore all the functions in a file by adding `/* i18n-validate-disable */` comment at the top of the file. | ||
### Dynamic keys | ||
For dynamic keys, we check the typescript type of the key. If the type is a `const` type, the type is used as the key. Otherwise, the key is ignored. Type can be an union type or a literal type. | ||
```ts | ||
const a = 'namespace:key1'; | ||
t(a); | ||
const b = `namespace:${b}` as const; | ||
t(b); | ||
t(`namespace:${b}` as const); | ||
declare const c: 'namespace:key3' | 'namespace:key4'; | ||
t(c); | ||
/** | ||
* @type {'a:key5' | 'a:key6'} | ||
*/ | ||
const d = `a:${b}`; | ||
t(d); | ||
const e = /** @type {'a:key7' | 'a:key8'} */ `a:${b}`; | ||
t(e); | ||
``` | ||
### Use with lint-staged | ||
@@ -62,0 +93,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
56879
517
134
1