Skip to content

Commit f2365ce

Browse files
authored
feat(valiate-icu): add option to ignore html tag (#2451)
1 parent c7bc9b4 commit f2365ce

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

.changeset/few-weeks-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/validate-icu-locales": patch
3+
---
4+
5+
Add ignore tag option to validate icu

packages/validate-icu-locales/src/__tests__/locales/en-1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const locales = {
66
'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}',
77
'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}',
88
'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}',
9+
'units.chevron': '<ip.coucou>',
910
}

packages/validate-icu-locales/src/__tests__/locales/en-ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export default {
66
'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}',
77
'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}',
88
'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}',
9+
'units.chevron': '<ip.coucou>',
910
} as const

packages/validate-icu-locales/src/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
#!/usr/bin/env node
22

3-
import * as fs from 'fs/promises'
3+
import { readFile } from 'node:fs/promises'
4+
import { parseArgs } from 'node:util'
5+
import type { ParseArgsConfig } from 'node:util'
46
import { parse } from '@formatjs/icu-messageformat-parser'
57
import type { ParserError } from '@formatjs/icu-messageformat-parser/error'
68
import { globby } from 'globby'
79
import { importFromString } from 'module-from-string'
810

9-
const args = process.argv.slice(2)
10-
const pattern = args[0]
11+
const options: ParseArgsConfig['options'] = {
12+
ignoreTag: {
13+
type: 'boolean',
14+
short: 'i',
15+
default: false,
16+
},
17+
}
18+
19+
const { values, positionals } = parseArgs({ options, allowPositionals: true })
20+
21+
const pattern = positionals[0]
1122

1223
type Locales = Record<string, string>
1324
type ErrorICU = {
@@ -29,7 +40,10 @@ const findICUErrors = (
2940
const errors = Object.entries(locales)
3041
.map(([key, value]) => {
3142
try {
32-
parse(value)
43+
parse(value, {
44+
// Need to cast as node doesn't allow generic to parseArgs
45+
ignoreTag: values['ignoreTag'] as boolean,
46+
})
3347

3448
return undefined
3549
} catch (err) {
@@ -57,7 +71,7 @@ const readFiles = async (files: string[]): Promise<ErrorsICU> => {
5771

5872
if (extension === 'json') {
5973
try {
60-
const data = await fs.readFile(file)
74+
const data = await readFile(file)
6175
const jsonFile = data.toString()
6276

6377
const locales = JSON.parse(jsonFile) as Locales
@@ -71,7 +85,7 @@ const readFiles = async (files: string[]): Promise<ErrorsICU> => {
7185

7286
if (extension === 'ts' || extension === 'js') {
7387
try {
74-
const data = await fs.readFile(file)
88+
const data = await readFile(file)
7589
const javascriptFile = data.toString()
7690

7791
const mod: unknown = await importFromString(javascriptFile, {

0 commit comments

Comments
 (0)