Skip to content

Commit a3ecda5

Browse files
committed
refactor: rename lintDirective to outputPrefix and update related docs and tests
1 parent cb63b2f commit a3ecda5

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

packages/cli/src/api/compile.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ describe("createCompiledCatalog", () => {
288288
})
289289
})
290290

291-
describe("options.lintDirective", () => {
292-
const getCompiledCatalog = (lintDirective?: string) =>
291+
describe("options.outputPrefix", () => {
292+
const getCompiledCatalog = (outputPrefix?: string) =>
293293
createCompiledCatalog(
294294
"en",
295295
{
296296
Hello: "Hello",
297297
},
298298
{
299-
lintDirective,
299+
outputPrefix,
300300
}
301301
).source
302302

@@ -306,19 +306,24 @@ describe("createCompiledCatalog", () => {
306306
})
307307

308308
it("should use oxlint-disable directive", () => {
309-
const result = getCompiledCatalog("oxlint-disable")
309+
const result = getCompiledCatalog("/*oxlint-disable*/")
310310
expect(result).toContain("/*oxlint-disable*/")
311311
})
312312

313-
it("should use custom lint directive when specified", () => {
314-
const result = getCompiledCatalog("biome-ignore lint: auto-generated")
313+
it("should use custom prefix when specified", () => {
314+
const result = getCompiledCatalog("/*biome-ignore lint: auto-generated*/")
315315
expect(result).toContain("/*biome-ignore lint: auto-generated*/")
316316
expect(result).not.toContain("eslint-disable")
317317
})
318318

319-
it("should handle empty string directive", () => {
319+
it("should handle empty string prefix (no header)", () => {
320320
const result = getCompiledCatalog("")
321-
expect(result).toContain("/**/")
321+
expect(
322+
result.startsWith("export") ||
323+
result.startsWith("module") ||
324+
result.startsWith("window") ||
325+
result.startsWith("global")
326+
).toBeTruthy()
322327
})
323328
})
324329

packages/cli/src/api/compile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type CreateCompileCatalogOptions = {
1717
namespace?: CompiledCatalogNamespace
1818
pseudoLocale?: string
1919
compilerBabelOptions?: GeneratorOptions
20-
lintDirective?: string
20+
outputPrefix?: string
2121
}
2222

2323
export type MessageCompilationError = {
@@ -45,7 +45,7 @@ export function createCompiledCatalog(
4545
namespace = "cjs",
4646
pseudoLocale,
4747
compilerBabelOptions = {},
48-
lintDirective = "eslint-disable",
48+
outputPrefix = "/*eslint-disable*/",
4949
} = options
5050
const shouldPseudolocalize = locale === pseudoLocale
5151

@@ -93,7 +93,7 @@ export function createCompiledCatalog(
9393
...compilerBabelOptions,
9494
}).code
9595

96-
return { source: `/*${lintDirective}*/` + code, errors }
96+
return { source: `${outputPrefix}` + code, errors }
9797
}
9898

9999
function buildExportStatement(

packages/cli/src/api/compile/compileLocale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async function compileAndWrite(
110110
{
111111
strict: false,
112112
namespace,
113-
lintDirective: options.lintDirective,
113+
outputPrefix: options.outputPrefix,
114114
pseudoLocale: config.pseudoLocale,
115115
compilerBabelOptions: config.compilerBabelOptions,
116116
}

packages/cli/src/lingui-compile.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type CliCompileOptions = {
2222
watch?: boolean
2323
namespace?: string
2424
workersOptions: WorkersOptions
25-
lintDirective?: string
25+
outputPrefix?: string
2626
}
2727

2828
export async function command(
@@ -114,7 +114,7 @@ type CliArgs = {
114114
config?: string
115115
debounce?: number
116116
workers?: number
117-
lintDirective?: string
117+
outputPrefix?: string
118118
}
119119

120120
if (require.main === module) {
@@ -138,8 +138,8 @@ if (require.main === module) {
138138
"Debounces compilation for given amount of milliseconds"
139139
)
140140
.option(
141-
"--lint-directive <directive>",
142-
"Add custom lint directive to the compiled files. Useful for enforcing linting rules on generated files. Defaults to 'eslint-disable'"
141+
"--output-prefix <prefix>",
142+
"Add a custom string to the beginning of compiled files (header/prefix). Useful for tools like linters or coverage directives. Defaults to '/*eslint-disable*/'"
143143
)
144144
.on("--help", function () {
145145
console.log("\n Examples:\n")
@@ -171,7 +171,7 @@ if (require.main === module) {
171171
typescript:
172172
options.typescript || config.compileNamespace === "ts" || false,
173173
namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
174-
lintDirective: options.lintDirective,
174+
outputPrefix: options.outputPrefix,
175175
})
176176
)
177177

packages/cli/src/test/compile.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ msgstr "{plural, }"
457457
})
458458
})
459459

460-
describe("lintDirective", () => {
461-
it("Should use custom lint directive in compiled files", async () => {
460+
describe("outputPrefix", () => {
461+
it("Should use custom output prefix in compiled files", async () => {
462462
const rootDir = await createFixtures({
463463
"en.po": `
464464
msgid "Hello World"
@@ -474,7 +474,7 @@ msgstr "Witaj świecie"
474474

475475
await mockConsole(async () => {
476476
const result = await command(config, {
477-
lintDirective: "biome-ignore lint: auto-generated",
477+
outputPrefix: "/*biome-ignore lint: auto-generated*/",
478478
workersOptions: {
479479
poolSize: 0,
480480
},
@@ -494,7 +494,7 @@ msgstr "Witaj świecie"
494494
})
495495
})
496496

497-
it("Should use oxlint-disable directive", async () => {
497+
it("Should use oxlint-disable prefix directive", async () => {
498498
const rootDir = await createFixtures({
499499
"en.po": `
500500
msgid "Test"
@@ -510,7 +510,7 @@ msgstr "Test PL"
510510

511511
await mockConsole(async () => {
512512
const result = await command(config, {
513-
lintDirective: "oxlint-disable",
513+
outputPrefix: "/*oxlint-disable*/",
514514
workersOptions: {
515515
poolSize: 0,
516516
},

website/docs/ref/cli.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ lingui compile
172172
[--namespace <namespace>]
173173
[--watch [--debounce <delay>]]
174174
[--workers]
175-
[--lint-directive <directive>]
175+
[--output-prefix <prefix>]
176176
```
177177
178178
Once you have all the catalogs ready and translated, you can use this command to compile all the catalogs into minified JS/TS files. It compiles message catalogs located in the [`path`](/ref/conf#catalogs) directory and generates minified JavaScript files. The resulting file is a string that is parsed into a plain JS object using `JSON.parse`.
@@ -251,28 +251,31 @@ Worker threads can significantly improve performance on large projects. However,
251251
252252
A larger worker pool also increases memory usage. Adjust this value for your project to achieve the best performance.
253253
254-
#### `--lint-directive <directive>` {#compile-lint-directive}
254+
#### `--output-prefix <prefix>` {#compile-output-prefix}
255255
256-
Customize the lint directive added to the header of compiled message catalogs. By default, Lingui adds `/*eslint-disable*/` to prevent linters from reporting issues in generated files.
256+
Adds a custom string to the beginning of compiled message catalogs (a header/prefix). By default, Lingui adds `/*eslint-disable*/` to prevent linters from reporting issues in generated files.
257257
258-
This option is useful when using different linters or tools that require specific directive formats.
258+
Use this option for other tools that rely on header directives (e.g., different linters, coverage tools, or formatters). Provide the full prefix exactly as it should appear in the output.
259259
260-
**Default value:** `eslint-disable`
260+
**Default value:** `/*eslint-disable*/`
261261
262262
**Examples:**
263263
264264
```shell
265265
# For Oxlint
266-
lingui compile --lint-directive "oxlint-disable"
266+
lingui compile --output-prefix "/*oxlint-disable*/"
267267
268268
# For Biome
269-
lingui compile --lint-directive "biome-ignore lint: auto-generated"
269+
lingui compile --output-prefix "/*biome-ignore lint: auto-generated*/"
270+
271+
# For no prefix at all
272+
lingui compile --output-prefix ""
270273
```
271274
272275
The generated file header will look like:
273276
274277
```js
275-
/*<your-directive>*/export const messages = JSON.parse(...);
278+
/*your-prefix-here*/ export const messages = JSON.parse("{}");
276279
```
277280
278281
## Configuring the Source Locale

0 commit comments

Comments
 (0)