Skip to content

Commit bb12dfd

Browse files
Merge pull request #14 from ChrisChinchilla/chrischinch/vale-ini
2 parents c6f8e37 + a106020 commit bb12dfd

File tree

8 files changed

+64
-27
lines changed

8 files changed

+64
-27
lines changed

build/index.js

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/vale-runner.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/vale-runner.js

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/vale-runner.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ function getInstallationInstructions(): {
9595
documentation: string;
9696
} {
9797
const platform = process.platform;
98-
const instructions: any = {
98+
const instructions: {
99+
platform: string;
100+
methods: Array<{ name: string; command: string; url?: string }>;
101+
documentation: string;
102+
} = {
99103
platform,
100104
documentation: "https://vale.sh/docs/vale-cli/installation/",
101105
methods: [],
@@ -234,6 +238,10 @@ const TOOLS: Tool[] = [
234238
type: "string",
235239
description: "Absolute or relative path to the file to check",
236240
},
241+
config_path: {
242+
type: "string",
243+
description: "Optional path to .vale.ini file. If not provided, Vale will search for .vale.ini starting from the file's directory and moving upward through parent directories.",
244+
},
237245
},
238246
required: ["path"],
239247
},
@@ -249,6 +257,10 @@ const TOOLS: Tool[] = [
249257
type: "string",
250258
description: "The text content to check with Vale",
251259
},
260+
config_path: {
261+
type: "string",
262+
description: "Optional path to .vale.ini file. If not provided, uses the server's configured path or searches in the current directory.",
263+
},
252264
},
253265
required: ["text"],
254266
},
@@ -353,9 +365,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
353365
}
354366

355367
case "check_file": {
356-
const { path: filePath } = args as { path: string };
368+
const { path: filePath, config_path } = args as { path: string; config_path?: string };
357369

358-
debug(`check_file called - path: ${filePath}`);
370+
debug(`check_file called - path: ${filePath}, config_path: ${config_path}`);
359371

360372
if (!filePath) {
361373
return {
@@ -376,7 +388,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
376388
return createValeNotInstalledResponse();
377389
}
378390

379-
const result = await checkFile(filePath, valeConfigPath);
391+
// Only pass config_path if explicitly provided by the user
392+
// This allows Vale to use its natural upward search from the file's directory
393+
const result = await checkFile(filePath, config_path);
380394

381395
debug(`check_file result - file: ${result.file}, issues found: ${result.issues.length}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}, suggestions: ${result.summary.suggestions}`);
382396

@@ -398,9 +412,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
398412
}
399413

400414
case "check_text": {
401-
const { text } = args as { text: string };
415+
const { text, config_path } = args as { text: string; config_path?: string };
402416

403-
debug(`check_text called - text length: ${text?.length}`);
417+
debug(`check_text called - text length: ${text?.length}, config_path: ${config_path}`);
404418

405419
if (!text) {
406420
return {
@@ -421,7 +435,11 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
421435
return createValeNotInstalledResponse();
422436
}
423437

424-
const result = await checkText(text, valeConfigPath);
438+
// For check_text, we should use the provided config_path if given,
439+
// otherwise fall back to the server's configured path since there's no file directory to search from
440+
const effectiveConfigPath = config_path !== undefined ? config_path : valeConfigPath;
441+
442+
const result = await checkText(text, effectiveConfigPath);
425443

426444
debug(`check_text result - issues found: ${result.issues.length}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}, suggestions: ${result.summary.suggestions}`);
427445

src/vale-runner.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export async function checkFile(
298298
command += ` "${absolutePath}"`;
299299

300300
// Run Vale from the file's directory so it searches upward from there
301-
const execOptions: any = {
301+
const execOptions: ExecOptions = {
302302
encoding: 'utf-8',
303303
cwd: path.dirname(absolutePath)
304304
};
@@ -308,13 +308,14 @@ export async function checkFile(
308308
try {
309309
const result = await execAsync(command, execOptions);
310310
stdout = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf-8');
311-
} catch (error: any) {
311+
} catch (error: unknown) {
312312
// Vale returns non-zero exit code when there are issues
313313
// But it still outputs JSON to stdout
314-
if (error.stdout) {
315-
stdout = error.stdout;
314+
const execError = error as { stdout?: string; stderr?: string; message?: string };
315+
if (execError.stdout) {
316+
stdout = execError.stdout;
316317
} else {
317-
const errorMessage = error.stderr || error.message || "Unknown error";
318+
const errorMessage = execError.stderr || execError.message || "Unknown error";
318319
throw new Error(
319320
`Vale execution failed: ${errorMessage}`
320321
);
@@ -379,8 +380,9 @@ export async function checkText(
379380
});
380381

381382
stdout = result.stdout;
382-
} catch (error: any) {
383-
const errorMessage = error.stderr || error.message || "Unknown error";
383+
} catch (error: unknown) {
384+
const execError = error as { stderr?: string; message?: string };
385+
const errorMessage = execError.stderr || execError.message || "Unknown error";
384386
throw new Error(
385387
`Vale execution failed: ${errorMessage}`
386388
);

0 commit comments

Comments
 (0)