Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some bugs on ignore path #51

Merged
merged 14 commits into from
May 31, 2024
5 changes: 5 additions & 0 deletions .changeset/early-years-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

Fix some bugs
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Simplifies managing and cleaning up unused translation keys in localization file
- Analyzes source files to identify used and unused translation keys.
- Supports multiple scoped translation functions.
- Can display or remove unused translation keys.
- Configurable through a JSON, JS, or TS config file.
- Configurable through a JSON, CJS, or JS config file.

## Installation

Expand All @@ -25,10 +25,8 @@ npm install -D unused-i18n

Create a unused-i18n.config.json or unused-i18n.config.js file in the root of your project. Here's an example configuration:

```ts
import type { Config } from 'unused-i18n'

const config = {
```cjs
module.exports = {
paths: [
{
srcPath: ['src/pages/products'],
Expand All @@ -40,9 +38,7 @@ const config = {
scopedNames: ['scopedT', 'scopedTOne'],
ignorePaths: ['src/pages/products/ignoreThisFolder'],
excludeKey: ['someKey'],
} satisfies Config

export default config
}
```

| Option | Type | Default | Required | Description |
Expand Down Expand Up @@ -118,6 +114,7 @@ Contributions are welcome! Please open an issue or submit a pull request if you

Acknowledgements

- [Rollup](https://rollupjs.org/) - Module bundler used in this project.
- [Vite](https://vitejs.dev/) - Next Generation Frontend Tooling.
- [TypeScript](https://www.typescriptlang.org/) - Typed JavaScript used in this project.
- [Vitest](https://vitest.dev/guide/cli) - Testing framework used in this project.
- [Commander](https://github.com/tj/commander.js#readme) - Node.js command-line interfaces.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export const processTranslations = async ({
let pathUnusedLocalesCount = 0

srcPath.forEach((pathEntry) => {
if (config.ignorePaths && config.ignorePaths.includes(pathEntry)) return
const ignorePathExists = config.ignorePaths?.some(
(ignorePath) => ignorePath === pathEntry
)
if (ignorePathExists) return
const files = searchFilesRecursively({
excludePatterns,
regex: /use-i18n/,
Expand Down Expand Up @@ -83,8 +86,8 @@ export const processTranslations = async ({
.join('\n')

const message = missingTranslations.length
? `Missing translations for \x1b[33m${localeFilePath}\x1b[0m : \x1b[31m${pathUnusedLocalesCount} \n${formattedMissingTranslations}\x1b[0m`
: `\x1b[32mNo missing translations for \x1b[33m${localeFilePath}\x1b[0m\x1b[0m`
? `Unused translations in \x1b[33m${localeFilePath}\x1b[0m : \x1b[31m${pathUnusedLocalesCount} \n${formattedMissingTranslations}\x1b[0m`
: `\x1b[32mNo unused translations in \x1b[33m${localeFilePath}\x1b[0m\x1b[0m`

unusedLocalesCountByPath.push({
path: localPath,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/summary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SummaryArgs } from '../types'
import { exit } from 'process'

export const summary = ({
unusedLocalesCountByPath,
Expand All @@ -12,4 +13,7 @@ export const summary = ({
})

console.log(`Total unused locales: \x1b[33m${totalUnusedLocales}\x1b[0m`)
if (unusedLocalesCountByPath.length === 1) {
exit(1)
}
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const external = (id: string) => {
id.endsWith('fs') ||
id.endsWith('path') ||
id.endsWith('perf_hooks') ||
id.endsWith('process') ||
id.endsWith('commander')
) {
return true
Expand Down
12 changes: 0 additions & 12 deletions vitest.config.ts

This file was deleted.

Loading