From 41c3065aeb82d1249e1e723a8567ee3ef2f3a327 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Tue, 16 Jun 2026 10:17:59 +0800 Subject: [PATCH 1/2] fix(lint-md-action): unify basePath in getConfig() and add JSON parse error handling --- src/lint-md-action.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lint-md-action.ts b/src/lint-md-action.ts index 2e197ca..c1c1d69 100644 --- a/src/lint-md-action.ts +++ b/src/lint-md-action.ts @@ -32,19 +32,22 @@ export class LintMdAction { } getConfig() { - // 获取用户传入的配置文件目录 - const configPath = path.resolve(process.env.GITHUB_WORKSPACE || process.cwd(), core.getInput('configFile')) + const configPath = path.resolve(this.basePath, core.getInput('configFile')) if (!fs.existsSync(configPath)) { core.warning('The user does not have a configuration file to pass in, we will use the default configuration instead...') return {} } - // JavaScript 模块,直接 require if (configPath.endsWith('.js')) { return require(`${configPath}`) } const content = fs.readFileSync(configPath).toString() - return JSON.parse(content) + try { + return JSON.parse(content) + } catch (e) { + core.warning(`Failed to parse config file: ${(e as Error).message}`) + return {} + } } isPass() { From 45382888e88f10c6141fc8c57eb9c007acc5b2f8 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Tue, 16 Jun 2026 10:27:42 +0800 Subject: [PATCH 2/2] refactor(cli-types): add proper type definitions for CliConfig, CliLintResult, and LintMdError --- src/@lint-md/cli.d.ts | 28 ++++++++++++++++++++++++---- src/lint-md-action.ts | 6 +++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/@lint-md/cli.d.ts b/src/@lint-md/cli.d.ts index 473bcac..a19aa99 100644 --- a/src/@lint-md/cli.d.ts +++ b/src/@lint-md/cli.d.ts @@ -1,15 +1,35 @@ declare module '@lint-md/cli' { + export type RuleLevel = 0 | 1 | 2 | 'off' | 'warn' | 'error' + + export interface CliConfig { + excludeFiles?: string[] + rules?: Record + } + + export interface CliLintResult { + path: string + file: string + errors: LintMdError[] + } + + export interface LintMdError { + level: string + type: string + text: string + start: { line: number; column: number } + end: { line: number; column: number } + } + export class Lint { - constructor(files: string[], config: any) + constructor(files: string[], config: CliConfig) start(): Promise showResult(): void printOverview(): void countError(): { error: number; warning: number } - errorFiles: any[] + errorFiles: CliLintResult[] } - export type CliConfig = any } declare module '@lint-md/cli/lib/index' { - export { Lint, CliConfig } from '@lint-md/cli' + export { Lint, CliConfig, CliLintResult, LintMdError, RuleLevel } from '@lint-md/cli' } diff --git a/src/lint-md-action.ts b/src/lint-md-action.ts index c1c1d69..ee5e0d2 100644 --- a/src/lint-md-action.ts +++ b/src/lint-md-action.ts @@ -9,7 +9,7 @@ import * as fs from 'fs' import * as path from 'path' import * as core from '@actions/core' -import { Lint, CliConfig } from '@lint-md/cli/lib/index' +import { Lint, CliConfig, CliLintResult } from '@lint-md/cli/lib/index' export class LintMdAction { private readonly basePath!: string @@ -31,7 +31,7 @@ export class LintMdAction { .map(res => path.resolve(this.basePath, res)) } - getConfig() { + getConfig(): CliConfig { const configPath = path.resolve(this.basePath, core.getInput('configFile')) if (!fs.existsSync(configPath)) { core.warning('The user does not have a configuration file to pass in, we will use the default configuration instead...') @@ -94,7 +94,7 @@ export class LintMdAction { } } - getErrors() { + getErrors(): CliLintResult[] { return this.linter.errorFiles } }