i18next-cli 1.12.0 → 1.12.1
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/CHANGELOG.md +4 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/linter.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/linter.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/linter.ts +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.12.1](https://github.com/i18next/i18next-cli/compare/v1.12.0...v1.12.1) - 2025-10-23
|
|
9
|
+
|
|
10
|
+
- try to improve linter for spread operator usage [#72](https://github.com/i18next/i18next-cli/issues/72)
|
|
11
|
+
|
|
8
12
|
## [1.12.0](https://github.com/i18next/i18next-cli/compare/v1.11.14...v1.12.0) - 2025-10-23
|
|
9
13
|
|
|
10
14
|
- feat(default-value): add value parameter to defaultValue function [#71](https://github.com/i18next/i18next-cli/pull/71)
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),d=require("./init.js"),g=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.12.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),d=require("./init.js"),g=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.12.1"),m.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async e=>{try{const n=await a.ensureConfig(),i=async()=>{const t=await c.runExtractor(n,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.extract.input),a=y(n.extract.ignore),r=h(n.extract.output),c=[...a,...r].filter(Boolean),s=e.filter(e=>!c.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),m.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,t)=>{let n=await a.loadConfig();if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await r.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await p.runStatus(n,{detail:e,namespace:t.namespace})}),m.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const n=await a.ensureConfig(),i=()=>s.runTypesGenerator(n);if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.types?.input||[]),a=[...y(n.extract?.ignore)].filter(Boolean),r=e.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=await a.ensureConfig();await l.runSyncer(e)}),m.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),m.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d.runInit),m.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const n=async()=>{let e=await a.loadConfig();if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await r.detectConfig();t||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=t}await g.runLinter(e)};if(await n(),e.watch){console.log("\nWatching for changes...");const e=await a.loadConfig();if(e?.extract?.input){const i=await w(e.extract.input),a=[...y(e.extract.ignore),...h(e.extract.output)].filter(Boolean),r=i.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),n()})}}}),m.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeSync(t,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeDownload(t,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeMigrate(t,e)}),m.parse(process.argv);const y=e=>Array.isArray(e)?e:e?[e]:[],h=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],w=async(e=[])=>{const t=y(e),o=await Promise.all(t.map(e=>n.glob(e||"",{nodir:!0})));return Array.from(new Set(o.flat()))};
|
package/dist/cjs/linter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("glob"),t=require("node:fs/promises"),r=require("@swc/core"),n=require("chalk"),s=require("ora");const o=e=>/^(https|http|\/\/|^\/)/.test(e);function i(e,t,r){const n=[],s=[],i=e=>t.substring(0,e).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),u=r.extract.ignoredAttributes||[],f=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...u]),p=(e,t)=>{if(!e||"object"!=typeof e)return;const r=[...t,e];if("JSXText"===e.type){if(!r.some(e=>{if("JSXElement"!==e.type)return!1;const t=e.opening?.name?.value;return l.has(t)})){const t=e.value.trim();t&&t.length>1&&!o(t)&&isNaN(Number(t))&&!t.startsWith("{{")&&s.push(e)}}if("StringLiteral"===e.type){const t=r[r.length-2];if("JSXAttribute"===t?.type&&!f.has(t.name.value)){const t=e.value.trim();t&&!o(t)&&isNaN(Number(t))&&s.push(e)}}for(const t of Object.keys(e)){if("span"===t)continue;const n=e[t];Array.isArray(n)?n.forEach(e=>p(e,r)):n&&"object"==typeof n&&p(n,r)}};p(e,[]);let g=0;for(const e of s){const r=e.raw??e.value,s=t.indexOf(r,g);s>-1&&(n.push({text:e.value.trim(),line:i(s)}),g=s+r.length)}return n}exports.runLinter=async function(o){const a=s("Analyzing source files...\n").start();try{const s=["node_modules/**"],c=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[],l=await e.glob(o.extract.input,{ignore:[...s,...c]});let u=0;const f=new Map;for(const e of l){const n=await t.readFile(e,"utf-8"),s=i(await r.parse(n,{syntax:"typescript",tsx:!0,decorators:!0}),n,o);s.length>0&&(u+=s.length,f.set(e,s))}if(u>0){a.fail(n.red.bold(`Linter found ${u} potential issues.`));for(const[e,t]of f.entries())console.log(n.yellow(`\n${e}`)),t.forEach(({text:e,line:t})=>{console.log(` ${n.gray(`${t}:`)} ${n.red("Error:")} Found hardcoded string: "${e}"`)});process.exit(1)}else a.succeed(n.green.bold("No issues found."))}catch(e){a.fail(n.red("Linter failed to run.")),console.error(e),process.exit(1)}};
|
|
1
|
+
"use strict";var e=require("glob"),t=require("node:fs/promises"),r=require("@swc/core"),n=require("chalk"),s=require("ora");const o=e=>/^(https|http|\/\/|^\/)/.test(e);function i(e,t,r){const n=[],s=[],i=e=>t.substring(0,e).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),u=r.extract.ignoredAttributes||[],f=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...u]),p=(e,t)=>{if(!e||"object"!=typeof e)return;const r=[...t,e];if("JSXText"===e.type){if(!r.some(e=>{if("JSXElement"!==e.type)return!1;const t=e.opening?.name?.value;return l.has(t)})){const t=e.value.trim();t&&t.length>1&&"..."!==t&&!o(t)&&isNaN(Number(t))&&!t.startsWith("{{")&&s.push(e)}}if("StringLiteral"===e.type){const t=r[r.length-2];if("JSXAttribute"===t?.type&&!f.has(t.name.value)){const t=e.value.trim();t&&"..."!==t&&!o(t)&&isNaN(Number(t))&&s.push(e)}}for(const t of Object.keys(e)){if("span"===t)continue;const n=e[t];Array.isArray(n)?n.forEach(e=>p(e,r)):n&&"object"==typeof n&&p(n,r)}};p(e,[]);let g=0;for(const e of s){const r=e.raw??e.value,s=t.indexOf(r,g);s>-1&&(n.push({text:e.value.trim(),line:i(s)}),g=s+r.length)}return n}exports.runLinter=async function(o){const a=s("Analyzing source files...\n").start();try{const s=["node_modules/**"],c=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[],l=await e.glob(o.extract.input,{ignore:[...s,...c]});let u=0;const f=new Map;for(const e of l){const n=await t.readFile(e,"utf-8"),s=i(await r.parse(n,{syntax:"typescript",tsx:!0,decorators:!0}),n,o);s.length>0&&(u+=s.length,f.set(e,s))}if(u>0){a.fail(n.red.bold(`Linter found ${u} potential issues.`));for(const[e,t]of f.entries())console.log(n.yellow(`\n${e}`)),t.forEach(({text:e,line:t})=>{console.log(` ${n.gray(`${t}:`)} ${n.red("Error:")} Found hardcoded string: "${e}"`)});process.exit(1)}else a.succeed(n.green.bold("No issues found."))}catch(e){a.fail(n.red("Linter failed to run.")),console.error(e),process.exit(1)}};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as t}from"commander";import e from"chokidar";import{glob as o}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as d}from"./init.js";import{runLinter as f}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as g,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.12.
|
|
2
|
+
import{Command as t}from"commander";import e from"chokidar";import{glob as o}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as d}from"./init.js";import{runLinter as f}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as g,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.12.1"),w.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async t=>{try{const o=await a(),i=async()=>{const e=await s(o,{isWatchMode:!!t.watch,isDryRun:!!t.dryRun,syncPrimaryWithDefaults:!!t.syncPrimary});return t.ci&&!e?(console.log("✅ No files were updated."),process.exit(0)):t.ci&&e&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),e};if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.extract.input),a=x(o.extract.ignore),r=j(o.extract.output),c=[...a,...r].filter(Boolean),s=t.filter(t=>!c.some(e=>n(t,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}catch(t){console.error("Error running extractor:",t),process.exit(1)}}),w.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(t,e)=>{let o=await r();if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=t}await u(o,{detail:t,namespace:e.namespace})}),w.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async t=>{const o=await a(),i=()=>l(o);if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.types?.input||[]),a=[...x(o.extract?.ignore)].filter(Boolean),r=t.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=await a();await p(t)}),w.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d),w.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async t=>{const o=async()=>{let t=await r();if(!t){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),t=e}await f(t)};if(await o(),t.watch){console.log("\nWatching for changes...");const t=await r();if(t?.extract?.input){const i=await z(t.extract.input),a=[...x(t.extract.ignore),...j(t.extract.output)].filter(Boolean),r=i.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),o()})}}}),w.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async t=>{const e=await a();await g(e,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const e=await a();await y(e,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const e=await a();await h(e,t)}),w.parse(process.argv);const x=t=>Array.isArray(t)?t:t?[t]:[],j=t=>t&&"string"==typeof t?[t.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(t=[])=>{const e=x(t),n=await Promise.all(e.map(t=>o(t||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
|
package/dist/esm/linter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{glob as t}from"glob";import{readFile as e}from"node:fs/promises";import{parse as r}from"@swc/core";import o from"chalk";import n from"ora";async function s(s){const i=n("Analyzing source files...\n").start();try{const n=["node_modules/**"],c=Array.isArray(s.extract.ignore)?s.extract.ignore:s.extract.ignore?[s.extract.ignore]:[],l=await t(s.extract.input,{ignore:[...n,...c]});let f=0;const u=new Map;for(const t of l){const o=await e(t,"utf-8"),n=a(await r(o,{syntax:"typescript",tsx:!0,decorators:!0}),o,s);n.length>0&&(f+=n.length,u.set(t,n))}if(f>0){i.fail(o.red.bold(`Linter found ${f} potential issues.`));for(const[t,e]of u.entries())console.log(o.yellow(`\n${t}`)),e.forEach(({text:t,line:e})=>{console.log(` ${o.gray(`${e}:`)} ${o.red("Error:")} Found hardcoded string: "${t}"`)});process.exit(1)}else i.succeed(o.green.bold("No issues found."))}catch(t){i.fail(o.red("Linter failed to run.")),console.error(t),process.exit(1)}}const i=t=>/^(https|http|\/\/|^\/)/.test(t);function a(t,e,r){const o=[],n=[],s=t=>e.substring(0,t).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),f=r.extract.ignoredAttributes||[],u=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...f]),p=(t,e)=>{if(!t||"object"!=typeof t)return;const r=[...e,t];if("JSXText"===t.type){if(!r.some(t=>{if("JSXElement"!==t.type)return!1;const e=t.opening?.name?.value;return l.has(e)})){const e=t.value.trim();e&&e.length>1&&!i(e)&&isNaN(Number(e))&&!e.startsWith("{{")&&n.push(t)}}if("StringLiteral"===t.type){const e=r[r.length-2];if("JSXAttribute"===e?.type&&!u.has(e.name.value)){const e=t.value.trim();e&&!i(e)&&isNaN(Number(e))&&n.push(t)}}for(const e of Object.keys(t)){if("span"===e)continue;const o=t[e];Array.isArray(o)?o.forEach(t=>p(t,r)):o&&"object"==typeof o&&p(o,r)}};p(t,[]);let g=0;for(const t of n){const r=t.raw??t.value,n=e.indexOf(r,g);n>-1&&(o.push({text:t.value.trim(),line:s(n)}),g=n+r.length)}return o}export{s as runLinter};
|
|
1
|
+
import{glob as t}from"glob";import{readFile as e}from"node:fs/promises";import{parse as r}from"@swc/core";import o from"chalk";import n from"ora";async function s(s){const i=n("Analyzing source files...\n").start();try{const n=["node_modules/**"],c=Array.isArray(s.extract.ignore)?s.extract.ignore:s.extract.ignore?[s.extract.ignore]:[],l=await t(s.extract.input,{ignore:[...n,...c]});let f=0;const u=new Map;for(const t of l){const o=await e(t,"utf-8"),n=a(await r(o,{syntax:"typescript",tsx:!0,decorators:!0}),o,s);n.length>0&&(f+=n.length,u.set(t,n))}if(f>0){i.fail(o.red.bold(`Linter found ${f} potential issues.`));for(const[t,e]of u.entries())console.log(o.yellow(`\n${t}`)),e.forEach(({text:t,line:e})=>{console.log(` ${o.gray(`${e}:`)} ${o.red("Error:")} Found hardcoded string: "${t}"`)});process.exit(1)}else i.succeed(o.green.bold("No issues found."))}catch(t){i.fail(o.red("Linter failed to run.")),console.error(t),process.exit(1)}}const i=t=>/^(https|http|\/\/|^\/)/.test(t);function a(t,e,r){const o=[],n=[],s=t=>e.substring(0,t).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),f=r.extract.ignoredAttributes||[],u=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...f]),p=(t,e)=>{if(!t||"object"!=typeof t)return;const r=[...e,t];if("JSXText"===t.type){if(!r.some(t=>{if("JSXElement"!==t.type)return!1;const e=t.opening?.name?.value;return l.has(e)})){const e=t.value.trim();e&&e.length>1&&"..."!==e&&!i(e)&&isNaN(Number(e))&&!e.startsWith("{{")&&n.push(t)}}if("StringLiteral"===t.type){const e=r[r.length-2];if("JSXAttribute"===e?.type&&!u.has(e.name.value)){const e=t.value.trim();e&&"..."!==e&&!i(e)&&isNaN(Number(e))&&n.push(t)}}for(const e of Object.keys(t)){if("span"===e)continue;const o=t[e];Array.isArray(o)?o.forEach(t=>p(t,r)):o&&"object"==typeof o&&p(o,r)}};p(t,[]);let g=0;for(const t of n){const r=t.raw??t.value,n=e.indexOf(r,g);n>-1&&(o.push({text:t.value.trim(),line:s(n)}),g=n+r.length)}return o}export{s as runLinter};
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
package/src/linter.ts
CHANGED
|
@@ -110,6 +110,7 @@ const isUrlOrPath = (text: string) => /^(https|http|\/\/|^\/)/.test(text)
|
|
|
110
110
|
* - Skips script and style tag content (technical, not user-facing)
|
|
111
111
|
* - Filters out numeric values (usually not translatable)
|
|
112
112
|
* - Ignores interpolation syntax starting with `{{`
|
|
113
|
+
* - Filters out ellipsis/spread operator notation `...`
|
|
113
114
|
* - Only reports non-empty, trimmed strings
|
|
114
115
|
*
|
|
115
116
|
* @param ast - The parsed AST to analyze
|
|
@@ -157,7 +158,8 @@ function findHardcodedStrings (ast: any, code: string, config: I18nextToolkitCon
|
|
|
157
158
|
|
|
158
159
|
if (!isIgnored) {
|
|
159
160
|
const text = node.value.trim()
|
|
160
|
-
|
|
161
|
+
// Filter out: empty strings, single chars, URLs, numbers, interpolations, and ellipsis
|
|
162
|
+
if (text && text.length > 1 && text !== '...' && !isUrlOrPath(text) && isNaN(Number(text)) && !text.startsWith('{{')) {
|
|
161
163
|
nodesToLint.push(node) // Collect the node
|
|
162
164
|
}
|
|
163
165
|
}
|
|
@@ -167,7 +169,8 @@ function findHardcodedStrings (ast: any, code: string, config: I18nextToolkitCon
|
|
|
167
169
|
const parent = currentAncestors[currentAncestors.length - 2]
|
|
168
170
|
if (parent?.type === 'JSXAttribute' && !ignoredAttributes.has(parent.name.value)) {
|
|
169
171
|
const text = node.value.trim()
|
|
170
|
-
|
|
172
|
+
// Filter out: empty strings, URLs, numbers, and ellipsis
|
|
173
|
+
if (text && text !== '...' && !isUrlOrPath(text) && isNaN(Number(text))) {
|
|
171
174
|
nodesToLint.push(node) // Collect the node
|
|
172
175
|
}
|
|
173
176
|
}
|