i18n-validate
Advanced tools
Comparing version 0.1.0-next.1fbab2c.0 to 0.1.0-next.347dc75.0
#!/usr/bin/env node | ||
import { parseOptionsFile, log, parseFile, ValidationError, validateKey } from './chunk-UGNI3TRV.js'; | ||
import { parseOptionsFile, log, parseFile, ValidationError, validateKey } from './chunk-VFV2AZDU.js'; | ||
import process from 'node:process'; | ||
import { Command } from 'commander'; | ||
import { Glob } from 'glob'; | ||
import isCI from 'is-ci'; | ||
var command = new Command().version("0.1.0-next.1fbab2c.0").usage("[options] <file ...>").option("-c, --config <config>", "Path to the config file", "./i18n-validate.json").option("--log-level <logLevel>", "Log level", "info").option("--exclude <exclude...>", "Exclude files from parsing", "**/node_modules/**").option("--error-on-invalid-key", "Exit with error code 1 if invalid keys are found", isCI).option("--error-on-missing-variable", "Exit with error code 1 if missing variables are found", isCI).option("--error-on-unused-variable", "Exit with error code 1 if unused variables are found", false); | ||
var command = new Command().version("0.1.0-next.347dc75.0").usage("[options] <file ...>").option("-c, --config <config>", "Path to the config file", "./i18n-validate.json").option("--log-level <logLevel>", "Log level", "info").option("--exclude <exclude...>", "Exclude files from parsing", "**/node_modules/**").option("--exit-on-error", "Exit immediately if an error is found", false); | ||
command.on("--help", () => { | ||
@@ -15,3 +14,3 @@ console.log(""); | ||
console.log(" $ i18next-validate --config i18n-validate-custom.json 'src/**/*.{js,jsx}'"); | ||
console.log(' $ i18next-validate --exclude "**/node_modules/**" "src/**/*.{js,jsx}"'); | ||
console.log(' $ i18next-validate --exclude "**/node_modules/**" "src/**/*.{js,jsx}"'); | ||
console.log(""); | ||
@@ -31,2 +30,4 @@ }); | ||
}).filter(Boolean); | ||
log(`Parsed options: | ||
${JSON.stringify(options, null, 2)}`, "debug", options); | ||
if (options.inputs.length === 0) { | ||
@@ -39,13 +40,25 @@ program.help(); | ||
}); | ||
var errorCount = 0; | ||
for await (const file of glob) { | ||
log(`Parsing ${file}`, "debug", options); | ||
const translationNodes = parseFile(file, options); | ||
console.log(translationNodes); | ||
for (const node of translationNodes) { | ||
if (!node.key || !node.namespace) | ||
log(new ValidationError("Missing translation key or namespace", node.path, node.positions), "invalidKey", options); | ||
await validateKey(node, options); | ||
if (!node.key || !node.namespace) { | ||
log(new ValidationError("Missing translation key or namespace", node.path, node.positions), "error", options); | ||
errorCount++; | ||
} else { | ||
const valid = await validateKey(node, options); | ||
if (!valid) | ||
errorCount++; | ||
} | ||
} | ||
} | ||
if (errorCount > 0) { | ||
log(`Found ${errorCount} errors`, "error", options); | ||
process.exit(1); | ||
} else { | ||
log(`Found ${errorCount} errors`, "info", options); | ||
process.exit(0); | ||
} | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=cli.js.map |
@@ -10,33 +10,14 @@ type LogLevel = 'debug' | 'error' | 'info' | 'warn'; | ||
/** | ||
* Throw an error if invalid keys are found | ||
* Exclude files from parsing | ||
* | ||
* @defaultValue {isCI} | ||
* | ||
* @remarks | ||
* For CI/CD environments, it's default value is `true` else `false` | ||
* @defaultValue '**\/node_modules/**' | ||
*/ | ||
errorOnInvalidKey: boolean; | ||
exclude: string | string[]; | ||
/** | ||
* Throw an error if variables are missing in the source code | ||
* Exit immediately if an error is found | ||
* | ||
* @defaultValue {isCI} | ||
* | ||
* @remarks | ||
* For CI/CD environments, it's default value is `true` else `false` | ||
*/ | ||
errorOnMissingVariable: boolean; | ||
/** | ||
* Throw an error if variables are unused in the source code | ||
* | ||
* @defaultValue false | ||
* | ||
*/ | ||
errorOnUnusedVariable: boolean; | ||
exitOnError: boolean; | ||
/** | ||
* Exclude files from parsing | ||
* | ||
* @defaultValue '**\/node_modules/**' | ||
*/ | ||
exclude: string | string[]; | ||
/** | ||
* names of the translation function | ||
@@ -135,3 +116,3 @@ * | ||
declare const validateKey: (node: TranslationNode, options: OptionsWithDefault) => Promise<void>; | ||
declare const validateKey: (node: TranslationNode, options: OptionsWithDefault) => Promise<boolean>; | ||
@@ -138,0 +119,0 @@ type Options = Partial<OptionsWithDefault>; |
@@ -1,3 +0,3 @@ | ||
export { ValidationError, parseFile, parseOptionsFile, validateKey } from './chunk-UGNI3TRV.js'; | ||
export { ValidationError, parseFile, parseOptionsFile, validateKey } from './chunk-VFV2AZDU.js'; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "i18n-validate", | ||
"version": "0.1.0-next.1fbab2c.0", | ||
"version": "0.1.0-next.347dc75.0", | ||
"description": "A cli tool to find invalid i18n keys, missing variables and many more", | ||
@@ -34,2 +34,7 @@ "main": "./dist/index.js", | ||
], | ||
"dependencies": { | ||
"commander": "^11.0.0", | ||
"glob": "^10.3.3", | ||
"typescript": "^5.1.6" | ||
}, | ||
"devDependencies": { | ||
@@ -52,3 +57,2 @@ "@commitlint/cli": "^17.6.6", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6", | ||
"vitest": "^0.33.0" | ||
@@ -85,8 +89,3 @@ }, | ||
}, | ||
"packageManager": "yarn@3.6.1", | ||
"dependencies": { | ||
"commander": "^11.0.0", | ||
"glob": "^10.3.3", | ||
"is-ci": "^3.0.1" | ||
} | ||
"packageManager": "yarn@3.6.1" | ||
} |
@@ -21,8 +21,33 @@ <div align="center"> | ||
```ts | ||
```sh | ||
npx i18n-validate | ||
``` | ||
> **Note:** Currently, `i18n-validate` only supports `ts`, `tsx`, `js` and `jsx` source files and `json` translation files. | ||
<!-- prettier-ignore-start --> | ||
```sh | ||
Usage: i18n-validate [options] <file ...> | ||
Options: | ||
-V, --version output the version number | ||
-c, --config <config> Path to the config file (default: | ||
"./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) | ||
-h, --help display help for command | ||
Examples: | ||
$ i18next-validate "/path/to/src/app.js" | ||
$ i18next-validate --config i18n-validate-custom.json 'src/**/*.{js,jsx}' | ||
$ i18next-validate --exclude "**/node_modules/**" "src/**/*.{js,jsx}" | ||
``` | ||
<!-- prettier-ignore-end --> | ||
You can disable the `i18n-validate` for a specific line by adding `// i18n-validate-disable-next-line` before the line. | ||
> **Note**: Currently, `i18n-validate` only supports `ts`, `tsx`, `js` and `jsx` source files and `json` translation files. | ||
## Configuration | ||
@@ -32,5 +57,9 @@ | ||
<!-- Add info --> | ||
```json | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/imranbarbhuiya/i18n-validate/main/.github/i18n-validate.schema.json" | ||
} | ||
``` | ||
> **Note:** You can also use `js`, `cjs` or `mjs` file and with any name you want. Just make sure to pass the path of the config file to `i18n-validate` using `--config` option. | ||
> **Note**: You can also use `js`, `cjs` or `mjs` file and with any name you want. Just make sure to pass the path of the config file to `i18n-validate` using `--config` option. | ||
@@ -37,0 +66,0 @@ ## Buy me some doughnuts |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
17
79
36373
390
+ Addedtypescript@^5.1.6
+ Addedtypescript@5.7.3(transitive)
- Removedis-ci@^3.0.1
- Removedci-info@3.9.0(transitive)
- Removedis-ci@3.0.1(transitive)